HcclAllGather

产品支持情况

  • Ascend 950PR/Ascend 950DT:支持
  • Atlas A3 训练系列产品/Atlas A3 推理系列产品:支持
  • Atlas A2 训练系列产品/Atlas A2 推理系列产品:支持
  • Atlas 推理系列产品:支持
  • Atlas 训练系列产品:支持

功能说明

集合通信算子AllGather的操作接口,将通信域内所有节点的输入按照rank id重新排序,然后拼接起来,再将结果发送到所有节点的输出。

allgather

说明

针对AllGather操作,每个节点都接收按照rank id重新排序后的数据集合,即每个节点的AllGather输出都是一样的。

函数原型

HcclResult HcclAllGather(void *sendBuf, void *recvBuf, uint64_t sendCount, HcclDataType dataType, HcclComm comm, aclrtStream stream)

参数说明

参数名 输入/输出 描述
sendBuf 输入 源数据buffer地址。
recvBuf 输出 目的数据buffer地址,集合通信结果输出至此buffer中。
sendCount 输入 参与allgather操作的sendBuf的数据size,recvBuf的数据size则等于sendCount * rank size。
dataType 输入 allgather操作的数据类型,HcclDataType类型。
不同的型号支持的数据类型不同,详细请参见数据类型说明
comm 输入 集合通信操作所在的通信域。
stream 输入 本rank所使用的stream。

数据类型说明

  • 针对Ascend 950PR/Ascend 950DT,支持数据类型:int8、uint8、int16、uint16、int32、uint32、int64、uint64、float8-e5m2、float8-e4m3、float8-e8m0、hifloat8、float16、float32、float64、bfp16。
  • 针对Atlas A3 训练系列产品/Atlas A3 推理系列产品,支持数据类型:int8、uint8、int16、uint16、int32、uint32、int64、uint64、float16、float32、float64、bfp16。
  • 针对Atlas A2 训练系列产品/Atlas A2 推理系列产品,支持数据类型:int8、uint8、int16、uint16、int32、uint32、int64、uint64、float16、float32、float64、bfp16。
  • 针对Atlas 训练系列产品,支持数据类型:int8、uint8、int16、uint16、int32、uint32、int64、uint64、float16、float32、float64。
  • 针对Atlas 300I Duo 推理卡,支持数据类型:int8、uint8、int16、uint16、int32、uint32、int64、uint64、float16、float32、float64。

返回值

HcclResult:接口成功返回HCCL_SUCCESS,其他失败。

约束说明

  • 所有rank的sendCount、dataType均应相同。
  • 针对Atlas 300I Duo 推理卡,仅支持单Server场景,单Server中最大支持部署16张Atlas 300I Duo 推理卡(即32个NPU)。

调用示例

// 申请集合通信操作的Device内存
void *sendBuf = nullptr, *recvBuf = nullptr;
uint32_t rankSize = 8;
uint64_t sendCount = 1;  // 每个节点发送的数据个数
size_t sendSize = sendCount * sizeof(float);
size_t recvSize = rankSize * sendCount * sizeof(float);
aclrtMalloc(&sendBuf, sendSize, ACL_MEM_MALLOC_HUGE_ONLY);
aclrtMalloc(&recvBuf, recvSize, ACL_MEM_MALLOC_HUGE_ONLY);

// 初始化通信域和流
HcclComm hcclComm;
HcclCommInitRootInfo(rankSize, &rootInfo, devId, &hcclComm);

// 创建任务流
aclrtStream stream;
aclrtCreateStream(&stream);

// 执行AllGather,将通信域内所有rank的sendBuf 按照rank_id顺序拼接起来,再将结果发送到所有rank的recvBuf
HcclAllGather(sendBuf, recvBuf, sendCount, HCCL_DATA_TYPE_FP32, hcclComm, stream);
// 阻塞等待任务流中的集合通信任务执行完成
aclrtSynchronizeStream(stream);

// 释放资源
aclrtFree(sendBuf);          // 释放Device侧内存
aclrtFree(recvBuf);          // 释放Device侧内存
aclrtDestroyStream(stream);  // 销毁任务流
HcclCommDestroy(hcclComm);   // 销毁通信域