HcommReadReduceOnThread
Applicability
Product |
Supported |
|---|---|
Atlas 350 Accelerator Card |
√ |
√ |
|
√ |
|
x |
|
x |
|
x |
For
Function
Reads data from the specified memory on a channel. It performs a reduceOp operation on the memory data of length count × sizeof(dataType) pointed to by src and the memory data of the same length pointed to by dst, and outputs the result to dst. The API caller is the node where dst resides.
Prototype
1 | int32_t HcommReadReduceOnThread(ThreadHandle thread, ChannelHandle channel, void *dst, const void *src, uint64_t count, HcommDataType dataType, HcommReduceOp reduceOp) |
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
thread |
Input |
Communication thread handle, which is threads returned by the HcclThreadAcquire call. For details, see ThreadHandle. |
channel |
Input |
Communication channel handle, which is channels returned by the HcclChannelAcquire call. For details, see ChannelHandle. |
dst |
Output |
Destination memory address, which is obtained using HcclGetHcclBuffer or HcclChannelGetHcclBuffer. |
src |
Input |
Source memory address, which is obtained using HcclGetHcclBuffer or HcclChannelGetHcclBuffer. |
count |
Input |
Number of elements. |
dataType |
Input |
Data type. For details, see HcommDataType. Atlas 350 Accelerator Card: The supported data types are int8, int16, int32, uint8, uint16, uint32, fp16, fp32, and bfp16. |
reduceOp |
Input |
Reduction operation type. For details, see HcommReduceOp. Atlas 350 Accelerator Card: The supported reduction types are sum, max, and min. |
Returns
int32_t: 0 on success; else, failure.
Restrictions
None
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 | // Allocate communication threads. CommEngine engine = CommEngine::COMM_ENGINE_CPU_TS; // Used by the Atlas A3 training product/Atlas A3 inference product CommEngine engine = CommEngine::COMM_ENGINE_AICPU_TS; // Used by the Atlas 350 Accelerator Card uint32_t threadNum = 1; uint32_t notifyNumPerThread = 1; ThreadHandle thread; HcclThreadAcquire(engine, threadNum, notifyNumPerThread, &thread); // Allocate communication channels. uint32_t channelNum = 1; HcclChannelDesc channelDesc; HcclChannelDescInit(&channelDesc, channelNum); HcclComm comm; ChannelHandle channel; HcclChannelAcquire(comm, engine, &channelDesc, channelNum, &channel); // Obtain the local communication memory information. void * localBuffer; uint64_t localBufferSize; HcclGetHcclBuffer(comm, &localBuffer, &localBufferSize); // Obtain the remote communication memory information. void * remoteBuffer; uint64_t remoteBufferSize; HcclChannelGetHcclBuffer(comm, channel, &remoteBuffer, &remoteBufferSize); uint64_t count = std::min(localBufferSize/sizeof(uint64_t), remoteBufferSize/sizeof(uint64_t)); // Perform the reduction operation on the local and remote memory data and output the result to the local memory. HcommReadReduceOnThread(thread, channel, localBuffer, remoteBuffer, count, HCOMM_DATA_TYPE_INT32, HCOMM_REDUCE_SUM); |