集体通信函数¶
以下 NCCL API 提供了一些常用的集体操作。
ncclAllReduce¶
-
ncclResult_t
ncclAllReduce
(const void* sendbuff, void* recvbuff, size_t count, ncclDataType_t datatype, ncclRedOp_t op, ncclComm_t comm, cudaStream_t stream)¶ 使用
op
操作归约sendbuff
中长度为count
的数据数组,并在每个recvbuff
中留下结果的相同副本。如果
sendbuff == recvbuff
,将发生就地操作。
相关链接: AllReduce。
ncclBroadcast¶
-
ncclResult_t
ncclBroadcast
(const void* sendbuff, void* recvbuff, size_t count, ncclDataType_t datatype, int root, ncclComm_t comm, cudaStream_t stream)¶ 将
root
秩上sendbuff
中的count
个元素复制到所有秩的recvbuff
。sendbuff
仅在秩root
上使用,对于其他秩则忽略。如果
sendbuff == recvbuff
,将发生就地操作。
-
ncclResult_t
ncclBcast
(void* buff, size_t count, ncclDataType_t datatype, int root, ncclComm_t comm, cudaStream_t stream)¶ ncclBroadcast
的旧版就地版本,类似于 MPI_Bcast。 调用ncclBcast(buff, count, datatype, root, comm, stream)
等效于
ncclBroadcast(buff, buff, count, datatype, root, comm, stream)
相关链接: Broadcast
ncclReduce¶
-
ncclResult_t
ncclReduce
(const void* sendbuff, void* recvbuff, size_t count, ncclDataType_t datatype, ncclRedOp_t op, int root, ncclComm_t comm, cudaStream_t stream)¶ 使用
op
操作将sendbuff
中长度为count
的数据数组归约到root
秩上的recvbuff
中。recvbuff
仅在秩root
上使用,对于其他秩则忽略。如果
sendbuff == recvbuff
,将发生就地操作。
相关链接: Reduce。
ncclAllGather¶
-
ncclResult_t
ncclAllGather
(const void* sendbuff, void* recvbuff, size_t sendcount, ncclDataType_t datatype, ncclComm_t comm, cudaStream_t stream)¶ 从所有 GPU 收集
sendcount
个值,并在每个recvbuff
中留下结果的相同副本,从秩i
接收数据,偏移量为i*sendcount
。注意: 这假设接收计数等于
nranks*sendcount
,这意味着recvbuff
的大小应至少为nranks*sendcount
个元素。如果
sendbuff == recvbuff + rank * sendcount
,将发生就地操作。
ncclReduceScatter¶
-
ncclResult_t
ncclReduceScatter
(const void* sendbuff, void* recvbuff, size_t recvcount, ncclDataType_t datatype, ncclRedOp_t op, ncclComm_t comm, cudaStream_t stream)¶ 使用
op
操作归约来自所有 GPU 的sendbuff
中的数据,并将归约结果分散在设备上,以便秩i
上的recvbuff
将包含结果的第 i 个块。注意: 这假设发送计数等于
nranks*recvcount
,这意味着sendbuff
的大小应至少为nranks*recvcount
个元素。如果
recvbuff == sendbuff + rank * recvcount
,将发生就地操作。
相关链接: ReduceScatter, 就地操作。