@@ -1122,7 +1122,8 @@ flagcxResult_t flagcxC2cPlanner::findStrategy() {
11221122 -1 , 0 , homoMyRank_ * buffer.count_ , buffer.count_ , 0 ,
11231123 preHomoFuncCommOp);
11241124 } else if (preHomoFuncCommOp == flagcxCommOpAllGather) {
1125- preHomoFuncPipeline_[0 ].emplace_back (
1125+ preHomoFuncPipeline_.emplace_back ();
1126+ preHomoFuncPipeline_[1 ].emplace_back (
11261127 -1 , 0 , clusterOffset_ * sendCount_, sendCount_, 0 ,
11271128 preHomoFuncCommOp);
11281129 } else if (preHomoFuncCommOp == flagcxCommOpBroadcast) {
@@ -1250,6 +1251,11 @@ flagcxResult_t flagcxC2cPlanner::findStrategy() {
12501251 interRankBufferInfoManager_.getBufferInfoList (j, rank_);
12511252 for (auto it = rankList.begin (); it != rankList.end (); ++it) {
12521253 if (it->isScheduled_ && it->loopId_ == i) {
1254+ int offset =
1255+ ((!it->isRecv_ && commOp_ == flagcxCommOpAllGather &&
1256+ eachNicPerRank_)
1257+ ? 0
1258+ : it->offset_ );
12531259 if (nSteps_ > 1 ) {
12541260 int sendClusterId = it->isRecv_
12551261 ? comm_->cluster_ids [it->peerRank_ ]
@@ -1261,11 +1267,11 @@ flagcxResult_t flagcxC2cPlanner::findStrategy() {
12611267 (sendClusterId + comm_->nclusters - 1 - recvClusterId) %
12621268 comm_->nclusters ;
12631269 heteroFuncStep[step].addP2pOp (rank_, it->peerRank_ ,
1264- it-> offset_ , it->count_ ,
1270+ offset , it->count_ ,
12651271 it->isRecv_ );
12661272 } else {
12671273 heteroFuncStep[0 ].addP2pOp (rank_, it->peerRank_ ,
1268- it-> offset_ , it->count_ ,
1274+ offset , it->count_ ,
12691275 it->isRecv_ );
12701276 }
12711277 }
@@ -1578,13 +1584,14 @@ flagcxResult_t flagcxC2cPlanner::execute(const void *sendbuff, void *recvbuff,
15781584 void *recvTmpBuff = (scratchBuffer_ == nullptr ) ? recvbuff : scratchBuffer_;
15791585 void *sendTmpBuff =
15801586 (commOp_ == flagcxCommOpAlltoAll || commOp_ == flagcxCommOpAlltoAllv ||
1581- (commOp_ == flagcxCommOpScatter && rank_ == rootRank_))
1587+ (commOp_ == flagcxCommOpScatter && rank_ == rootRank_) ||
1588+ (commOp_ == flagcxCommOpAllGather && eachNicPerRank_))
15821589 ? const_cast <void *>(sendbuff)
15831590 : recvTmpBuff;
15841591
15851592 // execute preHomoFuncs
15861593 cclAdaptors[flagcxCCLAdaptorDevice]->groupStart ();
1587- for (int i = 0 ; i < preHomoFuncLoops_ ; ++i) {
1594+ for (int i = 0 ; i < preHomoFuncPipeline_[ 0 ]. size () ; ++i) {
15881595 preHomoFuncPipeline_[0 ][i].run (sendbuff, recvTmpBuff, datatype, redOp_,
15891596 comm_->globalrank2homorank [root], comm_,
15901597 stream, sendCounts_, sDispls_ , recvCounts_,
@@ -1593,16 +1600,33 @@ flagcxResult_t flagcxC2cPlanner::execute(const void *sendbuff, void *recvbuff,
15931600 cclAdaptors[flagcxCCLAdaptorDevice]->groupEnd ();
15941601
15951602 if (commOp_ == flagcxCommOpAllGather) {
1596- flagcxHeteroGroupStart ();
1597- for (int i = 0 ; i < heteroFuncPipeline_[0 ].size (); ++i) {
1598- heteroFuncPipeline_[0 ][i].run (sendTmpBuff, recvTmpBuff, datatype, comm_,
1599- stream);
1600- }
1601- flagcxHeteroGroupEnd ();
1602- deviceAdaptor->streamSynchronize (stream);
1603-
16041603 flagcxStream_t het_stream;
16051604 deviceAdaptor->streamCreate (&het_stream);
1605+ if (preHomoFuncPipeline_.size () > 1 ) {
1606+ cclAdaptors[flagcxCCLAdaptorDevice]->groupStart ();
1607+ for (int i = 0 ; i < preHomoFuncPipeline_[1 ].size (); ++i) {
1608+ preHomoFuncPipeline_[1 ][i].run (sendbuff, recvTmpBuff, datatype, redOp_,
1609+ comm_->globalrank2homorank [root], comm_,
1610+ stream, sendCounts_, sDispls_ ,
1611+ recvCounts_, rDispls_);
1612+ }
1613+ cclAdaptors[flagcxCCLAdaptorDevice]->groupEnd ();
1614+ flagcxHeteroGroupStart ();
1615+ for (int i = 0 ; i < heteroFuncPipeline_[0 ].size (); ++i) {
1616+ heteroFuncPipeline_[0 ][i].run (sendTmpBuff, recvTmpBuff,
1617+ datatype, comm_, het_stream);
1618+ }
1619+ flagcxHeteroGroupEnd ();
1620+ deviceAdaptor->streamSynchronize (stream);
1621+ deviceAdaptor->streamSynchronize (het_stream);
1622+ } else {
1623+ flagcxHeteroGroupStart ();
1624+ for (int i = 0 ; i < heteroFuncPipeline_[0 ].size (); ++i) {
1625+ heteroFuncPipeline_[0 ][i].run (sendTmpBuff, recvTmpBuff, datatype, comm_,
1626+ stream);
1627+ }
1628+ flagcxHeteroGroupEnd ();
1629+ }
16061630
16071631 for (int s = 1 ; s < nSteps_ - 1 ; ++s) {
16081632 cclAdaptors[flagcxCCLAdaptorDevice]->groupStart ();
@@ -1626,8 +1650,8 @@ flagcxResult_t flagcxC2cPlanner::execute(const void *sendbuff, void *recvbuff,
16261650 }
16271651
16281652 // last pipeline
1629- cclAdaptors[flagcxCCLAdaptorDevice]->groupStart ();
16301653 // execute postHomoFunc
1654+ cclAdaptors[flagcxCCLAdaptorDevice]->groupStart ();
16311655 for (int i = 0 ; i < postHomoFuncPipeline_[nSteps_ - 1 ].size (); ++i) {
16321656 postHomoFuncPipeline_[nSteps_ - 1 ][i].run (
16331657 recvTmpBuff, recvbuff, datatype, redOp_,
0 commit comments