Skip to content

Commit 105418b

Browse files
committed
add single send/recv operation
1 parent de06640 commit 105418b

1 file changed

Lines changed: 34 additions & 12 deletions

File tree

flagcx/adaptor/ccl/hccl_adaptor.cc

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ struct HcclSendRecvItemEx {
6868
};
6969
HcclSendRecvItemEx item;
7070
std::vector<HcclSendRecvItem> sendRecvInfo;
71+
static int groupDepth = 0;
7172

7273
// TODO: unsupported
7374
flagcxResult_t hcclAdaptorGetVersion(int *version) {
@@ -307,34 +308,55 @@ flagcxResult_t hcclAdaptorSend(const void *sendbuff, size_t count,
307308
flagcxDataType_t datatype, int peer,
308309
flagcxInnerComm_t comm, flagcxStream_t stream) {
309310
void *sendbuffptr = (void *)sendbuff;
311+
HcclDataType hcclDatatype = (HcclDataType)f2h_datatype_map[datatype];
312+
if (groupDepth == 0) {
313+
return (flagcxResult_t)
314+
h2f_ret_map[HcclSend(sendbuffptr, count, hcclDatatype, (uint32_t)peer,
315+
comm->base, stream->base)];
316+
}
317+
310318
item.comm = comm;
311319
item.stream = stream;
312-
sendRecvInfo.emplace_back(HcclSendRecvItem{
313-
HcclSendRecvType::HCCL_SEND, sendbuffptr, count,
314-
(HcclDataType)f2h_datatype_map[datatype], (uint32_t)peer});
320+
sendRecvInfo.emplace_back(HcclSendRecvItem{HcclSendRecvType::HCCL_SEND,
321+
sendbuffptr, count, hcclDatatype,
322+
(uint32_t)peer});
315323
return flagcxSuccess;
316324
}
317325

318326
flagcxResult_t hcclAdaptorRecv(void *recvbuff, size_t count,
319327
flagcxDataType_t datatype, int peer,
320328
flagcxInnerComm_t comm, flagcxStream_t stream) {
321-
sendRecvInfo.emplace_back(HcclSendRecvItem{
322-
HcclSendRecvType::HCCL_RECV, recvbuff, count,
323-
(HcclDataType)f2h_datatype_map[datatype], (uint32_t)peer});
329+
HcclDataType hcclDatatype = (HcclDataType)f2h_datatype_map[datatype];
330+
if (groupDepth == 0) {
331+
return (flagcxResult_t)
332+
h2f_ret_map[HcclRecv(recvbuff, count, hcclDatatype, (uint32_t)peer,
333+
comm->base, stream->base)];
334+
}
335+
336+
item.comm = comm;
337+
item.stream = stream;
338+
sendRecvInfo.emplace_back(HcclSendRecvItem{HcclSendRecvType::HCCL_RECV,
339+
recvbuff, count, hcclDatatype,
340+
(uint32_t)peer});
324341
return flagcxSuccess;
325342
}
326343

327344
flagcxResult_t hcclAdaptorGroupStart() {
328-
sendRecvInfo.clear();
345+
if (groupDepth == 0) {
346+
sendRecvInfo.clear();
347+
}
348+
groupDepth++;
329349
return flagcxSuccess;
330350
}
331351

332352
flagcxResult_t hcclAdaptorGroupEnd() {
333-
uint32_t itemNum = 0;
334-
itemNum = sendRecvInfo.size();
335-
if (itemNum > 0) {
336-
return (flagcxResult_t)h2f_ret_map[HcclBatchSendRecv(
337-
sendRecvInfo.data(), itemNum, item.comm->base, item.stream->base)];
353+
groupDepth--;
354+
if (groupDepth == 0) {
355+
uint32_t itemNum = sendRecvInfo.size();
356+
if (itemNum > 0) {
357+
return (flagcxResult_t)h2f_ret_map[HcclBatchSendRecv(
358+
sendRecvInfo.data(), itemNum, item.comm->base, item.stream->base)];
359+
}
338360
}
339361
return flagcxSuccess;
340362
}

0 commit comments

Comments
 (0)