SetFlag/WaitFlag

Product Support

Product

Supported

Atlas A3 training products/Atlas A3 inference products

Atlas A2 training products/Atlas A2 inference products

Atlas 200I/500 A2 inference products

Atlas inference product's AI Core

Atlas inference product's Vector Core

x

Atlas training products

Function

Synchronizes different pipelines in the same core. This synchronization needs to be inserted between different pipeline instructions with data dependency.
  • 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 specified by the user. You are advised to obtain the value by using AllocEventID or FetchEventID. The definition is as follows:

1
using TEventID = int8_t;

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

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

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

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

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

Returns

None

Restrictions

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);