昇腾社区首页
中文
注册
开发者
下载

HcclAllGather

产品支持情况

产品

是否支持

Atlas A3 训练系列产品/Atlas A3 推理系列产品

Atlas A2 训练系列产品

Atlas A2 推理系列产品

Atlas 200I/500 A2 推理产品

Atlas 推理系列产品

Atlas 训练系列产品

针对Atlas 推理系列产品,仅支持此系列产品中的Atlas 300I Duo 推理卡

功能说明

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

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

函数原型

1
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则等于count * rank size。

dataType

输入

allgather操作的数据类型,HcclDataType类型。

针对Atlas A3 训练系列产品/Atlas A3 推理系列产品,支持数据类型:int8、uint8、int16、uint16、int32、uint32、int64、uint64、float16、float32、float64、bfp16。

针对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。

comm

输入

集合通信操作所在的通信域。

stream

输入

本rank所使用的stream。

返回值

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

约束说明

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

调用示例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// 申请集合通信操作的 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_FIRST);
aclrtMalloc(&recvBuf, recvSize, ACL_MEM_MALLOC_HUGE_FIRST);

// 初始化通信域和流
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);   // 销毁通信域