SetFlag/WaitFlag

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

Synchronizes different pipelines in the same core. This synchronization needs to be inserted between different pipeline instructions with data dependencies.
  • SetFlag: The current instruction starts to be executed after all read and write operations of the current instruction are completed and the corresponding flag bit in hardware is set to 1.
  • WaitFlag: When this instruction is executed, if the corresponding flag bit is 0, the subsequent instructions in the queue are blocked; if the corresponding flag bit is 1, the subsequent instructions are executed after this bit is changed to 0.

Prototype

1
2
__aicore__ inline void SetFlag(TEventID id)
__aicore__ inline void WaitFlag(TEventID id)

Parameters

Table 1 Parameters

Parameter

Input/Output

Description

id

Input

Event ID, which is user-defined. You are advised to obtain the value through AllocEventID or FetchEventID. The definition is as follows:

1
using TEventID = int8_t;

Atlas training product: The value ranges from 0 to 3.

Atlas inference product AI Core: The value ranges from 0 to 7.

Atlas A2 training product/Atlas A2 inference product: The value ranges from 0 to 7.

Atlas A3 training product/Atlas A3 inference product: The value ranges from 0 to 7.

Atlas 200I/500 A2 inference product: The value ranges from 0 to 7.

Returns

None

Constraints

SetFlag and WaitFlag must be used in pairs.

Example

DataCopy can be executed only after SetValue is executed. In this case, you need to insert the synchronization operation between PIPE_S and PIPE_MTE3.

1
2
3
4
5
6
7
AscendC::GlobalTensor<half> dstGlobal;
AscendC::LocalTensor<half> dstLocal;
dstLocal.SetValue(0, 0);
AscendC::TQueSync<PIPE_S, PIPE_MTE3> sync;
sync.SetFlag(0);
sync.WaitFlag(0);
AscendC::DataCopy(dstGlobal, dstLocal, dataSize);