1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
|
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2020 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2015 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2023 Jeffrey M. Squyres. All rights reserved.
* Copyright (c) 2024 NVIDIA CORPORATION. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "ompi_config.h"
#include <stdlib.h>
#include <stdio.h>
#include "mpi.h"
#include "ompi/mca/mca.h"
#include "coll_tuned.h"
/* need to include our own topo prototypes so we can malloc data on the comm correctly */
#include "ompi/mca/coll/base/coll_base_topo.h"
/* need file reading function */
#include "ompi/mca/coll/base/coll_base_util.h"
/* also need the dynamic rule structures */
#include "coll_tuned_dynamic_rules.h"
/* and our own prototypes */
#include "coll_tuned_dynamic_file.h"
static int fileline=0; /* used for verbose error messages */
#define getnext(fptr, pval) ompi_coll_base_file_getnext_long(fptr, &fileline, pval)
#define isnext_digit(fptr) ompi_coll_base_file_peek_next_char_isdigit(fptr)
/*
* Reads a rule file called fname
* The rule file defines a set of sets of rules. The outer set is keyed on
* communicator size while the inner set is keyed on message size. When a
* communicator is constructed its size is used to look up the nested set of
* message size keyed rules. When a collective is called the message size
* determined from its call arguments are used to lookup a specific rule in the
* inner set.
*
* Rules for communicator and message sizes 0 and N (where N is the larger than
* largest key you provide) can be specified to fall back to the fixed decision
* framework above and below the communicator and message size ranges of
* interest.
*
* If an error occurs it removes rule table and then exits with a very verbose
* error message. this stops the user using a half baked rule table.
*
* Returns the number of actual collectives that a rule exists for
* (note 0 is NOT an error)
*
*/
int ompi_coll_tuned_read_rules_config_file (char *fname, ompi_coll_alg_rule_t** rules, int n_collectives)
{
long NCOL = 0, /* number of collectives for which rules are provided */
COLID = 0, /* identifies the collective type to associate the rules with */
NCOMSIZES = 0, /* number of sets of message size rules. the key is communicator size */
COMSIZE = 0, /* communicator size, the key identifying a specific set of message size rules. */
NMSGSIZES = 0, /* number of message size rules in the set. */
MSGSIZE = 0, /* message size, the key identifying a specific rule in the set. */
ALG = 0, /* the collective specific algorithm to use */
FANINOUT = 0, /* algorithm specific tuning parameter */
SEGSIZE = 0, /* algorithm specific tuning parameter */
MAXREQ = 0; /* algorithm specific tuning parameter */
FILE *fptr = (FILE*) NULL;
int x, ncs, nms, version;
ompi_coll_alg_rule_t *alg_rules = (ompi_coll_alg_rule_t*) NULL; /* complete table of rules */
/* individual pointers to sections of rules */
ompi_coll_alg_rule_t *alg_p = (ompi_coll_alg_rule_t*) NULL;
ompi_coll_com_rule_t *com_p = (ompi_coll_com_rule_t*) NULL;
ompi_coll_msg_rule_t *msg_p = (ompi_coll_msg_rule_t*) NULL;
/* stats info */
int total_alg_count = 0;
#if OPAL_ENABLE_DEBUG
int total_com_count = 0;
int total_msg_count = 0;
#endif
if (!fname) {
OPAL_OUTPUT((ompi_coll_tuned_stream,"Gave NULL as rule table configuration file for tuned collectives... ignoring!\n"));
return (-1);
}
if (!rules) {
OPAL_OUTPUT((ompi_coll_tuned_stream,"Gave NULL as rule table result ptr!... ignoring!\n"));
return (-2);
}
if (n_collectives<1) {
OPAL_OUTPUT((ompi_coll_tuned_stream,"Gave %d as max number of collectives in the rule table configuration file for tuned collectives!... ignoring!\n", n_collectives));
return (-3);
}
fptr = fopen (fname, "r");
if (!fptr) {
OPAL_OUTPUT((ompi_coll_tuned_stream,"Cannot read rules file [%s]\n", fname));
goto on_file_error;
}
/* make space and init the algorithm rules for each of the n_collectives MPI collectives */
alg_rules = ompi_coll_tuned_mk_alg_rules (n_collectives);
if (NULL == alg_rules) {
OPAL_OUTPUT((ompi_coll_tuned_stream,"Cannot allocate rules for file [%s]\n", fname));
goto on_file_error;
}
/* consume the optional version identifier */
if (0 == fscanf(fptr, "rule-file-version-%u", &version)) {
version = 1;
}
/* get the number of collectives for which rules are provided in the file */
if( (getnext(fptr, &NCOL) < 0) || (NCOL < 0) ) {
OPAL_OUTPUT((ompi_coll_tuned_stream,"Could not read number of collectives in configuration file around line %d\n", fileline));
goto on_file_error;
}
if (NCOL>n_collectives) {
OPAL_OUTPUT((ompi_coll_tuned_stream,"Number of collectives in configuration file %ld is greater than number of MPI collectives possible %d ??? error around line %d\n", NCOL, n_collectives, fileline));
goto on_file_error;
}
for (x=0;x<NCOL;x++) { /* for each collective */
/* get the collective for which rules are being provided */
if( (getnext(fptr, &COLID) < 0) || (COLID < 0) ) {
OPAL_OUTPUT((ompi_coll_tuned_stream,"Could not read next Collective id in configuration file around line %d\n", fileline));
goto on_file_error;
}
if (COLID>=n_collectives) {
OPAL_OUTPUT((ompi_coll_tuned_stream,"Collective id in configuration file %ld is greater than MPI collectives possible %d. Error around line %d\n", COLID, n_collectives, fileline));
goto on_file_error;
}
if (alg_rules[COLID].alg_rule_id != COLID) {
OPAL_OUTPUT((ompi_coll_tuned_stream, "Internal error in handling collective ID %ld\n", COLID));
goto on_file_error;
}
OPAL_OUTPUT((ompi_coll_tuned_stream, "Reading dynamic rule for collective ID %ld\n", COLID));
alg_p = &alg_rules[COLID];
alg_p->alg_rule_id = COLID;
alg_p->n_com_sizes = 0;
alg_p->com_rules = (ompi_coll_com_rule_t *) NULL;
/* get the number of communicator sizes for which a set of rules are to be provided */
if( (getnext (fptr, &NCOMSIZES) < 0) || (NCOMSIZES < 0) ) {
OPAL_OUTPUT((ompi_coll_tuned_stream,"Could not read count of communicators for collective ID %ld at around line %d\n", COLID, fileline));
goto on_file_error;
}
OPAL_OUTPUT((ompi_coll_tuned_stream, "Read communicator count %ld for dynamic rule for collective ID %ld\n", NCOMSIZES, COLID));
alg_p->n_com_sizes = NCOMSIZES;
alg_p->com_rules = ompi_coll_tuned_mk_com_rules (NCOMSIZES, COLID);
if (NULL == alg_p->com_rules) {
OPAL_OUTPUT((ompi_coll_tuned_stream,"Cannot allocate com rules for file [%s]\n", fname));
goto on_file_error;
}
for (ncs=0;ncs<NCOMSIZES;ncs++) { /* for each comm size */
com_p = &(alg_p->com_rules[ncs]);
/* get the communicator size to associate the set of rules with */
if( (getnext (fptr, &COMSIZE) < 0) || (COMSIZE < 0) ) {
OPAL_OUTPUT((ompi_coll_tuned_stream,"Could not read communicator size for collective ID %ld com rule %d at around line %d\n", COLID, ncs, fileline));
goto on_file_error;
}
com_p->mpi_comsize = COMSIZE;
/* get the number of message sizes to specify rules for. inner set size */
if( (getnext (fptr, &NMSGSIZES) < 0) || (NMSGSIZES < 0) ) {
OPAL_OUTPUT((ompi_coll_tuned_stream,"Could not read number of message sizes for collective ID %ld com rule %d at around line %d\n", COLID, ncs, fileline));
goto on_file_error;
}
OPAL_OUTPUT((ompi_coll_tuned_stream, "Read message count %ld for dynamic rule for collective ID %ld and comm size %ld\n",
NMSGSIZES, COLID, COMSIZE));
com_p->n_msg_sizes = NMSGSIZES;
com_p->msg_rules = ompi_coll_tuned_mk_msg_rules (NMSGSIZES, COLID, ncs, COMSIZE);
if (NULL == com_p->msg_rules) {
OPAL_OUTPUT((ompi_coll_tuned_stream,"Cannot allocate msg rules for file [%s]\n", fname));
goto on_file_error;
}
msg_p = com_p->msg_rules;
for (nms=0;nms<NMSGSIZES;nms++) { /* for each msg size */
msg_p = &(com_p->msg_rules[nms]);
/* read the message size to associate the rule with */
if( (getnext (fptr, &MSGSIZE) < 0) || (MSGSIZE < 0) ) {
OPAL_OUTPUT((ompi_coll_tuned_stream,"Could not read message size for collective ID %ld com rule %d msg rule %d at around line %d\n", COLID, ncs, nms, fileline));
goto on_file_error;
}
msg_p->msg_size = (size_t)MSGSIZE;
/* read the collective specific algorithm identifier */
if( (getnext (fptr, &ALG) < 0) || (ALG < 0) ) {
OPAL_OUTPUT((ompi_coll_tuned_stream,"Could not read target algorithm method for collective ID %ld com rule %d msg rule %d at around line %d\n", COLID, ncs, nms, fileline));
goto on_file_error;
}
msg_p->result_alg = ALG;
/* read faninout tuning parameter. required */
if( (getnext (fptr, &FANINOUT) < 0) || (FANINOUT < 0) ) {
OPAL_OUTPUT((ompi_coll_tuned_stream,"Could not read fan in/out topo for collective ID %ld com rule %d msg rule %d at around line %d\n", COLID, ncs, nms, fileline));
goto on_file_error;
}
msg_p->result_topo_faninout = FANINOUT;
/* read segsize tuning parameter. required */
if( (getnext (fptr, &SEGSIZE) < 0) || (SEGSIZE < 0) ) {
OPAL_OUTPUT((ompi_coll_tuned_stream,"Could not read target segment size for collective ID %ld com rule %d msg rule %d at around line %d\n", COLID, ncs, nms, fileline));
goto on_file_error;
}
msg_p->result_segsize = SEGSIZE;
/* read the max requests tuning parameter. optional */
msg_p->result_max_requests = ompi_coll_tuned_alltoall_max_requests;
if( (version > 1) && isnext_digit(fptr) ) {
if( (getnext (fptr, &MAXREQ) < 0) || (MAXREQ < 0) ) {
OPAL_OUTPUT((ompi_coll_tuned_stream,"Could not read max requests for collective ID %ld com rule %d msg rule %d at around line %d\n", COLID, ncs, nms, fileline));
goto on_file_error;
}
msg_p->result_max_requests = MAXREQ;
}
/* check the first rule is for 0 size. look-up depends on this */
if (!nms && MSGSIZE) {
OPAL_OUTPUT((ompi_coll_tuned_stream,"All algorithms must specify a rule for message size of zero upwards always first!\n"));
OPAL_OUTPUT((ompi_coll_tuned_stream,"Message size was %lu for collective ID %ld com rule %d msg rule %d at around line %d\n", MSGSIZE, COLID, ncs, nms, fileline));
goto on_file_error;
}
#if OPAL_ENABLE_DEBUG
total_msg_count++;
#endif
} /* msg size */
#if OPAL_ENABLE_DEBUG
total_com_count++;
#endif
} /* comm size */
total_alg_count++;
OPAL_OUTPUT((ompi_coll_tuned_stream, "Done reading dynamic rule for collective ID %ld\n", COLID));
} /* per collective */
fclose (fptr);
OPAL_OUTPUT((ompi_coll_tuned_stream,"\nConfigure file Stats\n"));
OPAL_OUTPUT((ompi_coll_tuned_stream,"Version\t\t\t\t\t: %5u\n", version));
OPAL_OUTPUT((ompi_coll_tuned_stream,"Collectives with rules\t\t\t: %5d\n", total_alg_count));
OPAL_OUTPUT((ompi_coll_tuned_stream,"Communicator sizes with rules\t\t: %5d\n", total_com_count));
OPAL_OUTPUT((ompi_coll_tuned_stream,"Message sizes with rules\t\t: %5d\n", total_msg_count));
OPAL_OUTPUT((ompi_coll_tuned_stream,"Lines in configuration file read\t\t: %5d\n", fileline));
/* return the rules to the caller */
*rules = alg_rules;
return (total_alg_count);
on_file_error:
/* here we close out the file and delete any memory allocated nicely */
/* we return back a verbose message and a count of -1 algorithms read */
/* draconian but its better than having a bad collective decision table */
OPAL_OUTPUT((ompi_coll_tuned_stream,"read_rules_config_file: bad configure file [%s]. Read afar as line %d\n", fname, fileline));
OPAL_OUTPUT((ompi_coll_tuned_stream,"Ignoring user supplied tuned collectives configuration decision file.\n"));
OPAL_OUTPUT((ompi_coll_tuned_stream,"Switching back to [compiled in] fixed decision table.\n"));
OPAL_OUTPUT((ompi_coll_tuned_stream,"Fix errors as listed above and try again.\n"));
/* deallocate memory if allocated */
if (alg_rules) ompi_coll_tuned_free_all_rules (alg_rules, n_collectives);
/* close file */
if (fptr) fclose (fptr);
*rules = (ompi_coll_alg_rule_t*) NULL;
return (-1);
}
|