SetAtomicAdd

Applicability

Product

Supported

Atlas 350 Accelerator Card

Atlas A3 training product/Atlas A3 inference product

Atlas A2 training product/Atlas A2 inference product

Atlas 200I/500 A2 inference product

Atlas inference product AI Core

Atlas inference product Vector Core

x

Atlas training product

Function Usage

Adds atomic accumulation for subsequent data transmission from VECOUT/L0C/L1 to the GM. Different accumulation data types can be set by using template parameters.

Prototype

1
2
template <typename T>
__aicore__ inline void SetAtomicAdd()

Parameters

Table 1 Template parameters

Parameter

Description

T

Set different addition data types.

For the Atlas training product, the supported data type is float, and the supported data path is VECOUT->GM.

For the Atlas inference product AI Core, the supported data types are int16_t, half, and float, and the supported data path is VECOUT->GM.

For the Atlas A2 training product/Atlas A2 inference product, the supported data types are int8_t, int16_t, half, bfloat16_t, int32_t, and float, and the supported data path is VECOUT/L0C/L1->GM.

For the Atlas A3 training product/Atlas A3 inference product, the supported data types are int8_t, int16_t, half, bfloat16_t, int32_t, and float, and the supported data path is VECOUT/L0C/L1->GM.

For the Atlas 350 Accelerator Card, the supported data types are int8_t, int16_t, half, bfloat16_t, int32_t, and float, and the supported data path is VECOUT/L0C Buffer->GM.

For the Atlas 200I/500 A2 inference product, the supported data types are int16_t, half, int32_t, and float, and the supported data path is VECOUT/L0C/L1->GM.

Returns

None

Constraints

  • You are advised to disable atomic accumulation using DisableDmaAtomic to avoid affecting subsequent instruction functions.
  • Before the instruction is executed, the GM data is not cleared. Developers can determine whether to clear the GM data based on the actual operator logic and clear the GM data as required.

Examples

In this example, atomic accumulation is performed when DataCopy is used to move data from VECOUT to external dstGlobal. To ensure the correctness of atomic accumulation, you need to clear dstGm before calling the kernel function.

Calling example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
// Initialize LocalTensor.
AscendC::LocalTensor<float> src0Local = inQueueSrc0.AllocTensor<float>();
// Clear the status of the atomic operation.
AscendC::DisableDmaAtomic();
AscendC::DataCopy(src0Local, src0Global, 256);
// Manually insert the MTE3 wait for the synchronization of data movement from src0Global to src0Local.
AscendC::SetFlag<AscendC::HardEvent::MTE2_MTE3>(0);
AscendC::WaitFlag<AscendC::HardEvent::MTE2_MTE3>(0);
// Enable atomic accumulation.
AscendC::SetAtomicAdd<float>();
AscendC::DataCopy(dstGlobal, src0Local, 256);
// Clear the status of the atomic operation.
AscendC::DisableDmaAtomic();
inQueueSrc0.FreeTensor(src0Local);

Result example:

Input data Src0 of each core: [1,1,1,1,1,...,1] // 1 × 256
Final output data dstGm: [3,3,3,3,3,...,3] // 3 × 256