SetAtomicType

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

x

Function Usage

Sets different atomic operation data types using template parameters.

Prototype

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

Parameters

Table 1 Template parameters

Parameter

Description

T

Sets different data types.

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.

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.

For the Atlas inference product AI Core, the supported data types are int16_t, half, and float.

For the Atlas 350 Accelerator Card, the supported data types are int8_t, int16_t, half, bfloat16_t, int32_t, and float.

For the Atlas 200I/500 A2 inference product, the supported data types are int16_t, half, int32_t, and float.

Returns

None

Constraints

It must be used together with SetAtomicAdd, SetAtomicMax, and SetAtomicMin.

After using the API, you are advised to clear the atomic operating status (for details, see DisableDmaAtomic) to avoid affecting subsequent command functions.

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
// In this example, atomic minimization is performed when DataCopy is used to move data from VECOUT to external dstGlobal, and SetAtomicType is used to modify the data type of atomic minimization.
#include "kernel_operator.h"
// Initialize dst0Local and dst1Local.
AscendC::LocalTensor<T> dst0Local = queueDst0.DeQue<T>();
AscendC::LocalTensor<T> dst1Local = queueDst1.DeQue<T>();
// VECOUT: Move data from dst1Local to external dstGlobal.
AscendC::DataCopy(dstGlobal, dst1Local, size);
AscendC::PipeBarrier<PIPE_MTE3>();

// Set atomic comparison for subsequent transfers, which compares the content to be copied with the existing content in global memory and writes the minimum value to the global memory.
        AscendC::SetAtomicMin<int8_t>();  // The value can be set to any type. In this example, int8_t is used.
        AscendC::SetAtomicType<T>(); // Set this parameter to the actual data type.
// VECOUT: After dst0Local atomic comparison, move data to external dstGlobal.
AscendC::DataCopy(dstGlobal, dst0Local, size);
queueDst0.FreeTensor(dst0Local);
queueDst1.FreeTensor(dst1Local);
// Clear the status of the atomic operation.
AscendC::DisableDmaAtomic();
The input data of each core is as follows:
Src0: [1,1,1,1,1, ...,1] // 1 × 256
Src1: [2,2,2,2,2, ...,2] // 2 × 256
Final output data: [1,1,1,1,1,...,1] // 1 × 256