HcclScatter
Applicability
Product |
Supported |
|---|---|
Atlas 350 Accelerator Card |
√ |
√ |
|
√ |
|
☓ |
|
☓ |
|
√ |
For
Function
Scatters data of the root rank to other ranks.
Prototype
1 | HcclResult HcclScatter(void *sendBuf, void *recvBuf, uint64_t recvCount, HcclDataType dataType, uint32_t root, HcclComm comm, aclrtStream stream) |
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
sendBuf |
Input |
Address of the source data buffer. |
recvBuf |
Output |
Address of the buffer to receive collective communication result. |
recvCount |
Input |
Number of recvBuf data elements to perform the Scatter operation. For example, if only one int32 data element is involved, then recvCount = 1. |
dataType |
Input |
Data type of the Scatter operation, which is of the HcclDataType type. Atlas 350 Accelerator Card: The supported data types are int8, uint8, int16, uint16, int32, uint32, int64, uint64, float8-e5m2, float8-e4m3, float8-e8m0, hifloat8, float16, float32, float64, and bfp16. |
root |
Input |
ID of the root rank used for the Scatter operation. |
comm |
Input |
Communicator where the operation is performed. |
stream |
Input |
Stream of the rank. |
Returns
HcclResult: HCCL_SUCCESS on success, or else failure.
Constraints
- The ranks must have the same recvCount, dataType, and root.
- There can be only one root rank globally.
- sendBuf of a non-root rank can be empty. sendBuf of the root rank cannot be empty.
Call Example
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 28 29 30 31 32 33 | void *sendBuf = nullptr; void *recvBuf = nullptr; uint64_t sendCount = 8; uint64_t recvCount = 1; size_t sendSize = sendCount * sizeof(float); size_t recvSize = recvCount * sizeof(float); // Allocate the device memory for receiving the Scatter result. ACLCHECK(aclrtMalloc(&recvBuf, recvSize, ACL_MEM_MALLOC_HUGE_ONLY)); // On the root rank, allocate the device memory for storing the sent data. if (device == rootRank) { ACLCHECK(aclrtMalloc(&sendBuf, sendSize, ACL_MEM_MALLOC_HUGE_ONLY)); } // Initialize the communicator. uint32_t rankSize = 8; HcclComm hcclComm; HcclCommInitRootInfo(rankSize, &rootInfo, device, &hcclComm); // Create a task flow. aclrtStream stream; aclrtCreateStream(&stream); // Execute Scatter to evenly distribute data of the root rank in the communicator to other ranks. HcclScatter(sendBuf, recvBuf, recvCount, HCCL_DATA_TYPE_FP32, rootRank, hcclComm, stream); // Wait until the collective communication task in the task flow is complete. aclrtSynchronizeStream(stream); // Free resources. aclrtFree(sendBuf); // Free the device memory. aclrtFree(recvBuf); // Free the device memory. aclrtDestroyStream(stream); // Destroy the task flow. HcclCommDestroy(hcclComm); // Destroy the communicator. |