AtomicMin
Applicability
Product |
Supported |
|---|---|
Atlas 350 Accelerator Card |
√ |
x |
|
x |
|
x |
|
x |
|
x |
|
x |
Function Usage
Performs atomic minimization on the specified global memory address.
Prototype
1 2 | template <typename T> __aicore__ inline T AtomicMin(__gm__ T *address, T value) |
Parameters
Parameter |
Description |
|---|---|
T |
Operand data type. For the Atlas 350 Accelerator Card, the supported data types are int32_t, uint32_t, float, int64_t, and uint64_t. |
Parameter |
Input/Output |
Description |
|---|---|---|
address |
Input |
Global memory address. |
value |
Input |
Scalar value. Its data type can be the same as that specified by the address. |
Returns
Data before the atomic operation is performed on the global memory address.
Constraints
The atomic operation involves scalar computation. If the Scalar Unit and DMA unit (MTE2/MTE3) have data dependencies during global memory read and write, you need to insert synchronization as needed.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 | // Pass the address of the global data to initialize dstGlobal and dstLocal. dstGlobal.SetGlobalBuffer(reinterpret_cast<__gm__ T *>(dstGm), dataSize); LocalTensor<T> dstLocal = inQueueX.AllocTensor<T>(); int32_t value = 0; int32_t a = AscendC::AtomicMin(reinterpret_cast<__gm__ int32_t *>(dstGm), value); // The movement operation can be performed only after the atomic operation is complete. There are data dependencies. event_t eventIdSToMte2 = static_cast<event_t>(GetTPipePtr()->AllocEventID<HardEvent::S_MTE2>()); // Manually insert the MTE2 wait for Scalar Unit synchronization. SetFlag<HardEvent::S_MTE2>(eventIdSToMte2); WaitFlag<HardEvent::S_MTE2>(eventIdSToMte2); DataCopy(dstLocal, dstGlobal, dataSize); // ... |
Assume that the preceding function is executed on three cores, and core 1, core 2, and core 3 are scheduled in sequence. The result example is as follows:
Original global memory data dst: [1,1,1,1,1,...,1] Core 1: Global memory data dst after atomic computation: [0,1,1,1,1,...,1] Return value a: 1 Core 2: Global memory data dst after atomic computation: [0,1,1,1,1,...,1] Return value a: 0 Core 3: Global memory data dst after atomic computation: [0,1,1,1,1,...,1] Return value a: 0