Skip to content

Commit 2d06372

Browse files
committed
pre-allocate buffer for allgather
1 parent 49b87cf commit 2d06372

2 files changed

Lines changed: 17 additions & 11 deletions

File tree

flagcx/core/flagcx_tuner.cc

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ flagcxResult_t flagcxTunerInit(size_t nRanks, size_t nNodes,
187187
}
188188
}
189189

190+
// initialize profilingResults pointer
191+
FLAGCXCHECK(
192+
flagcxCalloc(&internalTuner.profilingResults, internalTuner.nranks));
190193
// start timer
191194
ctx->timer.start();
192195
return flagcxSuccess;
@@ -281,20 +284,19 @@ static flagcxResult_t findBestComm(struct flagcxTunerContext *ctx,
281284

282285
INFO(FLAGCX_TUNING, "before allgather, duration for rank %d is %.3fms",
283286
internalTuner.rank, duration);
284-
float *durationResults = NULL;
285-
FLAGCXCHECK(flagcxCalloc(&durationResults, internalTuner.nranks));
286-
memcpy(durationResults + internalTuner.rank, &duration, sizeof(float));
287+
memcpy(internalTuner.profilingResults + internalTuner.rank, &duration,
288+
sizeof(float));
287289
// get average duration across all ranks
288-
FLAGCXCHECK(bootstrapAllGather(internalTuner.commState,
289-
(void *)durationResults, sizeof(float)));
290-
FLAGCXCHECK(bootstrapBarrier(internalTuner.commState, internalTuner.rank,
290+
FLAGCXCHECK(bootstrapAllGather(internalTuner.bootstrap,
291+
(void *)internalTuner.profilingResults,
292+
sizeof(float)));
293+
FLAGCXCHECK(bootstrapBarrier(internalTuner.bootstrap, internalTuner.rank,
291294
internalTuner.nranks, 0));
292295
duration = 0.0f;
293296
for (int i = 0; i < internalTuner.nranks; ++i) {
294-
duration += durationResults[i];
297+
duration += internalTuner.profilingResults[i];
295298
}
296299
duration /= internalTuner.nranks;
297-
free(durationResults);
298300
INFO(FLAGCX_TUNING, "after allgather, duration for rank %d is %.3fms",
299301
internalTuner.rank, duration);
300302

@@ -468,14 +470,16 @@ flagcxResult_t flagcxTunerDestroy(void *context) {
468470

469471
// stop timer
470472
ctx->timer.stop();
473+
free(internalTuner.profilingResults);
471474
delete ctx;
472475
return flagcxSuccess;
473476
}
474477

475478
flagcxTuner_t internalTuner = {"internal tuner",
476479
NULL, // assigned during flagcxCommInit
477-
0,
478-
0,
480+
0, // assigned during flagcxCommInit
481+
0, // assigned during flagcxCommInit
482+
NULL, // initialized during tunerInit
479483
flagcxTunerInit,
480484
flagcxTunerGetCandidateNumber,
481485
flagcxTunerSetCandidate,

flagcx/core/flagcx_tuner.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ struct flagcxTuner {
77
// Name of the tuner
88
const char *name;
99

10-
void *commState;
10+
void *bootstrap;
1111

1212
int rank;
1313
int nranks;
14+
15+
float *profilingResults;
1416
// Initializes tuner states.
1517
// Inputs:
1618
// - nRanks: number of ranks in current communicator. Each communicator

0 commit comments

Comments
 (0)