Skip to content

Commit 0f68484

Browse files
authored
Merge pull request #12827 from burlen/dynamic_decision_alltoall_max_requests
coll tuned dynamic rules file alltoall_algorithm_max_requests
2 parents 25feb3b + f6387a4 commit 0f68484

File tree

3 files changed

+114
-42
lines changed

3 files changed

+114
-42
lines changed

ompi/mca/coll/base/coll_base_util.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
* Copyright (c) 2014-2020 Research Organization for Information Science
1313
* and Technology (RIST). All rights reserved.
1414
* Copyright (c) 2023 Jeffrey M. Squyres. All rights reserved.
15+
*
16+
* Copyright (c) 2024 NVIDIA CORPORATION. All rights reserved.
17+
*
1518
* $COPYRIGHT$
1619
*
1720
* Additional copyrights may follow
@@ -482,6 +485,26 @@ int ompi_coll_base_file_peek_next_char_is(FILE *fptr, int *fileline, int expecte
482485
} while (1);
483486
}
484487

488+
/**
489+
* return non-zero if the next non-space to read on the current line is a digit.
490+
* otherwise return 0.
491+
*/
492+
int ompi_coll_base_file_peek_next_char_isdigit(FILE *fptr)
493+
{
494+
do {
495+
int next = fgetc(fptr);
496+
497+
if ((' ' == next) || ('\t' == next)) {
498+
continue; /* discard space and tab. keep everything else */
499+
}
500+
501+
ungetc(next, fptr); /* put the char back into the stream */
502+
503+
return isdigit(next); /* report back whether or not next is a digit */
504+
505+
} while (1);
506+
}
507+
485508
/**
486509
* There are certainly simpler implementation for this function when performance
487510
* is not a critical point. But, as this function is used during the collective

ompi/mca/coll/base/coll_base_util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* All rights reserved.
1212
* Copyright (c) 2014-2020 Research Organization for Information Science
1313
* and Technology (RIST). All rights reserved.
14+
* Copyright (c) 2024 NVIDIA CORPORATION. All rights reserved.
1415
* $COPYRIGHT$
1516
*
1617
* Additional copyrights may follow
@@ -195,6 +196,7 @@ int ompi_coll_base_file_getnext_string(FILE *fptr, int *fileline, char** val);
195196
* eat the value, otherwise put it back into the file.
196197
*/
197198
int ompi_coll_base_file_peek_next_char_is(FILE *fptr, int *fileline, int expected);
199+
int ompi_coll_base_file_peek_next_char_isdigit(FILE *fptr);
198200

199201
/* Miscellaneous function */
200202
const char* mca_coll_base_colltype_to_str(int collid);

ompi/mca/coll/tuned/coll_tuned_dynamic_file.c

Lines changed: 89 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* Copyright (c) 2015 Research Organization for Information Science
1313
* and Technology (RIST). All rights reserved.
1414
* Copyright (c) 2023 Jeffrey M. Squyres. All rights reserved.
15+
* Copyright (c) 2024 NVIDIA CORPORATION. All rights reserved.
1516
* $COPYRIGHT$
1617
*
1718
* Additional copyrights may follow
@@ -42,13 +43,24 @@
4243
static int fileline=0; /* used for verbose error messages */
4344

4445
#define getnext(fptr, pval) ompi_coll_base_file_getnext_long(fptr, &fileline, pval)
46+
#define isnext_digit(fptr) ompi_coll_base_file_peek_next_char_isdigit(fptr)
4547

4648
/*
4749
* Reads a rule file called fname
48-
* Builds the algorithm rule table for a max of n_collectives
50+
* The rule file defines a set of sets of rules. The outer set is keyed on
51+
* communicator size while the inner set is keyed on message size. When a
52+
* communicator is constructed its size is used to look up the nested set of
53+
* message size keyed rules. When a collective is called the message size
54+
* determined from its call arguments are used to lookup a specific rule in the
55+
* inner set.
56+
*
57+
* Rules for communicator and message sizes 0 and N (where N is the larger than
58+
* largest key you provide) can be specified to fall back to the fixed decision
59+
* framework above and below the communicator and message size ranges of
60+
* interest.
4961
*
5062
* If an error occurs it removes rule table and then exits with a very verbose
51-
* error message (this stops the user using a half baked rule table
63+
* error message. this stops the user using a half baked rule table.
5264
*
5365
* Returns the number of actual collectives that a rule exists for
5466
* (note 0 is NOT an error)
@@ -57,9 +69,18 @@ static int fileline=0; /* used for verbose error messages */
5769

5870
int ompi_coll_tuned_read_rules_config_file (char *fname, ompi_coll_alg_rule_t** rules, int n_collectives)
5971
{
60-
long CI, NCS, CS, ALG, NMS, FANINOUT, X, MS, SS;
72+
long NCOL = 0, /* number of collectives for which rules are provided */
73+
COLID = 0, /* identifies the collective type to associate the rules with */
74+
NCOMSIZES = 0, /* number of sets of message size rules. the key is communicator size */
75+
COMSIZE = 0, /* communicator size, the key identifying a specific set of message size rules. */
76+
NMSGSIZES = 0, /* number of message size rules in the set. */
77+
MSGSIZE = 0, /* message size, the key identifying a specific rule in the set. */
78+
ALG = 0, /* the collective specific algorithm to use */
79+
FANINOUT = 0, /* algorithm specific tuning parameter */
80+
SEGSIZE = 0, /* algorithm specific tuning parameter */
81+
MAXREQ = 0; /* algorithm specific tuning parameter */
6182
FILE *fptr = (FILE*) NULL;
62-
int x, ncs, nms;
83+
int x, ncs, nms, version;
6384

6485
ompi_coll_alg_rule_t *alg_rules = (ompi_coll_alg_rule_t*) NULL; /* complete table of rules */
6586

@@ -103,106 +124,131 @@ int ompi_coll_tuned_read_rules_config_file (char *fname, ompi_coll_alg_rule_t**
103124
goto on_file_error;
104125
}
105126

106-
if( (getnext(fptr, &X) < 0) || (X < 0) ) {
127+
/* consume the optional version identifier */
128+
if (0 == fscanf(fptr, "rule-file-version-%u", &version)) {
129+
version = 1;
130+
}
131+
132+
/* get the number of collectives for which rules are provided in the file */
133+
if( (getnext(fptr, &NCOL) < 0) || (NCOL < 0) ) {
107134
OPAL_OUTPUT((ompi_coll_tuned_stream,"Could not read number of collectives in configuration file around line %d\n", fileline));
108135
goto on_file_error;
109136
}
110-
if (X>n_collectives) {
111-
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", X, n_collectives, fileline));
137+
if (NCOL>n_collectives) {
138+
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));
112139
goto on_file_error;
113140
}
114141

115-
for (x=0;x<X;x++) { /* for each collective */
142+
for (x=0;x<NCOL;x++) { /* for each collective */
116143

117-
if( (getnext(fptr, &CI) < 0) || (CI < 0) ) {
144+
/* get the collective for which rules are being provided */
145+
if( (getnext(fptr, &COLID) < 0) || (COLID < 0) ) {
118146
OPAL_OUTPUT((ompi_coll_tuned_stream,"Could not read next Collective id in configuration file around line %d\n", fileline));
119147
goto on_file_error;
120148
}
121-
if (CI>=n_collectives) {
122-
OPAL_OUTPUT((ompi_coll_tuned_stream,"Collective id in configuration file %ld is greater than MPI collectives possible %d. Error around line %d\n", CI, n_collectives, fileline));
149+
if (COLID>=n_collectives) {
150+
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));
123151
goto on_file_error;
124152
}
125153

126-
if (alg_rules[CI].alg_rule_id != CI) {
127-
OPAL_OUTPUT((ompi_coll_tuned_stream, "Internal error in handling collective ID %ld\n", CI));
154+
if (alg_rules[COLID].alg_rule_id != COLID) {
155+
OPAL_OUTPUT((ompi_coll_tuned_stream, "Internal error in handling collective ID %ld\n", COLID));
128156
goto on_file_error;
129157
}
130-
OPAL_OUTPUT((ompi_coll_tuned_stream, "Reading dynamic rule for collective ID %ld\n", CI));
131-
alg_p = &alg_rules[CI];
158+
OPAL_OUTPUT((ompi_coll_tuned_stream, "Reading dynamic rule for collective ID %ld\n", COLID));
159+
alg_p = &alg_rules[COLID];
132160

133-
alg_p->alg_rule_id = CI;
161+
alg_p->alg_rule_id = COLID;
134162
alg_p->n_com_sizes = 0;
135163
alg_p->com_rules = (ompi_coll_com_rule_t *) NULL;
136164

137-
if( (getnext (fptr, &NCS) < 0) || (NCS < 0) ) {
138-
OPAL_OUTPUT((ompi_coll_tuned_stream,"Could not read count of communicators for collective ID %ld at around line %d\n", CI, fileline));
165+
/* get the number of communicator sizes for which a set of rules are to be provided */
166+
if( (getnext (fptr, &NCOMSIZES) < 0) || (NCOMSIZES < 0) ) {
167+
OPAL_OUTPUT((ompi_coll_tuned_stream,"Could not read count of communicators for collective ID %ld at around line %d\n", COLID, fileline));
139168
goto on_file_error;
140169
}
141-
OPAL_OUTPUT((ompi_coll_tuned_stream, "Read communicator count %ld for dynamic rule for collective ID %ld\n", NCS, CI));
142-
alg_p->n_com_sizes = NCS;
143-
alg_p->com_rules = ompi_coll_tuned_mk_com_rules (NCS, CI);
170+
OPAL_OUTPUT((ompi_coll_tuned_stream, "Read communicator count %ld for dynamic rule for collective ID %ld\n", NCOMSIZES, COLID));
171+
alg_p->n_com_sizes = NCOMSIZES;
172+
alg_p->com_rules = ompi_coll_tuned_mk_com_rules (NCOMSIZES, COLID);
144173
if (NULL == alg_p->com_rules) {
145174
OPAL_OUTPUT((ompi_coll_tuned_stream,"Cannot allocate com rules for file [%s]\n", fname));
146175
goto on_file_error;
147176
}
148177

149-
for (ncs=0;ncs<NCS;ncs++) { /* for each comm size */
178+
for (ncs=0;ncs<NCOMSIZES;ncs++) { /* for each comm size */
150179

151180
com_p = &(alg_p->com_rules[ncs]);
152181

153-
if( (getnext (fptr, &CS) < 0) || (CS < 0) ) {
154-
OPAL_OUTPUT((ompi_coll_tuned_stream,"Could not read communicator size for collective ID %ld com rule %d at around line %d\n", CI, ncs, fileline));
182+
/* get the communicator size to associate the set of rules with */
183+
if( (getnext (fptr, &COMSIZE) < 0) || (COMSIZE < 0) ) {
184+
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));
155185
goto on_file_error;
156186
}
157187

158-
com_p->mpi_comsize = CS;
188+
com_p->mpi_comsize = COMSIZE;
159189

160-
if( (getnext (fptr, &NMS) < 0) || (NMS < 0) ) {
161-
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", CI, ncs, fileline));
190+
/* get the number of message sizes to specify rules for. inner set size */
191+
if( (getnext (fptr, &NMSGSIZES) < 0) || (NMSGSIZES < 0) ) {
192+
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));
162193
goto on_file_error;
163194
}
164195
OPAL_OUTPUT((ompi_coll_tuned_stream, "Read message count %ld for dynamic rule for collective ID %ld and comm size %ld\n",
165-
NMS, CI, CS));
166-
com_p->n_msg_sizes = NMS;
167-
com_p->msg_rules = ompi_coll_tuned_mk_msg_rules (NMS, CI, ncs, CS);
196+
NMSGSIZES, COLID, COMSIZE));
197+
com_p->n_msg_sizes = NMSGSIZES;
198+
com_p->msg_rules = ompi_coll_tuned_mk_msg_rules (NMSGSIZES, COLID, ncs, COMSIZE);
168199
if (NULL == com_p->msg_rules) {
169200
OPAL_OUTPUT((ompi_coll_tuned_stream,"Cannot allocate msg rules for file [%s]\n", fname));
170201
goto on_file_error;
171202
}
172203

173204
msg_p = com_p->msg_rules;
174205

175-
for (nms=0;nms<NMS;nms++) { /* for each msg size */
206+
for (nms=0;nms<NMSGSIZES;nms++) { /* for each msg size */
176207

177208
msg_p = &(com_p->msg_rules[nms]);
178209

179-
if( (getnext (fptr, &MS) < 0) || (MS < 0) ) {
180-
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", CI, ncs, nms, fileline));
210+
/* read the message size to associate the rule with */
211+
if( (getnext (fptr, &MSGSIZE) < 0) || (MSGSIZE < 0) ) {
212+
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));
181213
goto on_file_error;
182214
}
183-
msg_p->msg_size = (size_t)MS;
215+
msg_p->msg_size = (size_t)MSGSIZE;
184216

217+
/* read the collective specific algorithm identifier */
185218
if( (getnext (fptr, &ALG) < 0) || (ALG < 0) ) {
186-
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", CI, ncs, nms, fileline));
219+
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));
187220
goto on_file_error;
188221
}
189222
msg_p->result_alg = ALG;
190223

224+
/* read faninout tuning parameter. required */
191225
if( (getnext (fptr, &FANINOUT) < 0) || (FANINOUT < 0) ) {
192-
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", CI, ncs, nms, fileline));
226+
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));
193227
goto on_file_error;
194228
}
195229
msg_p->result_topo_faninout = FANINOUT;
196230

197-
if( (getnext (fptr, &SS) < 0) || (SS < 0) ) {
198-
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", CI, ncs, nms, fileline));
231+
/* read segsize tuning parameter. required */
232+
if( (getnext (fptr, &SEGSIZE) < 0) || (SEGSIZE < 0) ) {
233+
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));
199234
goto on_file_error;
200235
}
201-
msg_p->result_segsize = SS;
236+
msg_p->result_segsize = SEGSIZE;
237+
238+
/* read the max requests tuning parameter. optional */
239+
msg_p->result_max_requests = ompi_coll_tuned_alltoall_max_requests;
240+
if( (version > 1) && isnext_digit(fptr) ) {
241+
if( (getnext (fptr, &MAXREQ) < 0) || (MAXREQ < 0) ) {
242+
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));
243+
goto on_file_error;
244+
}
245+
msg_p->result_max_requests = MAXREQ;
246+
}
202247

203-
if (!nms && MS) {
248+
/* check the first rule is for 0 size. look-up depends on this */
249+
if (!nms && MSGSIZE) {
204250
OPAL_OUTPUT((ompi_coll_tuned_stream,"All algorithms must specify a rule for message size of zero upwards always first!\n"));
205-
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", MS, CI, ncs, nms, fileline));
251+
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));
206252
goto on_file_error;
207253
}
208254

@@ -219,13 +265,14 @@ int ompi_coll_tuned_read_rules_config_file (char *fname, ompi_coll_alg_rule_t**
219265
} /* comm size */
220266

221267
total_alg_count++;
222-
OPAL_OUTPUT((ompi_coll_tuned_stream, "Done reading dynamic rule for collective ID %ld\n", CI));
268+
OPAL_OUTPUT((ompi_coll_tuned_stream, "Done reading dynamic rule for collective ID %ld\n", COLID));
223269

224270
} /* per collective */
225271

226272
fclose (fptr);
227273

228274
OPAL_OUTPUT((ompi_coll_tuned_stream,"\nConfigure file Stats\n"));
275+
OPAL_OUTPUT((ompi_coll_tuned_stream,"Version\t\t\t\t\t: %5u\n", version));
229276
OPAL_OUTPUT((ompi_coll_tuned_stream,"Collectives with rules\t\t\t: %5d\n", total_alg_count));
230277
OPAL_OUTPUT((ompi_coll_tuned_stream,"Communicator sizes with rules\t\t: %5d\n", total_com_count));
231278
OPAL_OUTPUT((ompi_coll_tuned_stream,"Message sizes with rules\t\t: %5d\n", total_msg_count));

0 commit comments

Comments
 (0)