IBSet

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

x

Atlas inference product AI Core

Atlas inference product Vector Core

x

Atlas training product

Function Usage

When different AI Cores operate the same global memory block, this function can be called to synchronize the AI Cores to avoid data dependency problems such as write-after-read, read-after-write, and write-after-write. IBSet is called to set the flag bit of a core. IBSet and IBWait are used in pairs to indicate the synchronization waiting instruction between cores, waiting for the completion of a core operation.

Prototype

1
2
template <bool isAIVOnly = true>
__aicore__ inline void IBSet(const GlobalTensor<int32_t>& gmWorkspace, const LocalTensor<int32_t>& ubWorkspace, int32_t blockIdx, int32_t eventID)

Parameters

Table 1 Template parameters

Parameter

Description

isAIVOnly

Indicates whether the AIVOnly mode is used. The default value is true.

Table 2 API parameters

Parameter

Input/Output

Description

gmWorkspace

Output

Public buffer for storing the external core status. The type is GlobalTensor. For details about the definition of the GlobalTensor data structure, see GlobalTensor.

ubWorkspace

Input

Public buffer that stores the current core status.

The type is LocalTensor, and TPosition can be VECIN, VECCALC, or VECOUT.

blockIdx

Input

IDX number of the waiting core. The value range is [0, Number of cores – 1].

eventID

Input

Controls the set and wait events of the current core.

Returns

None

Constraints

  • The minimum space allocated for gmWorkspace is as follows: Number of cores × 32 bytes × eventID_max + blockIdx_max × 32 bytes + 32 bytes. (eventID_max and blockIdx_max indicate the maximum values of eventID and blockIdx, respectively.)
  • In AIVOnly mode, the number of cores is GetBlockNum(). In MIX mode, the number of cores is GetBlockNum() × 2.
  • The minimum size of ubWorkspace is 32 bytes.
  • The value of the gmWorkspace cache needs to be initialized to 0.
  • When this API is used for multi-core control, the logical numBlocks specified during operator calling must be less than or equal to the number of cores for running the operator. Otherwise, the framework inserts abnormal synchronization during multi-round scheduling, causing the kernel to stop responding.

Example

In this example, two cores are used for data processing, and each core processes 256 pieces of half-type data. Core 0 implements the x+y operation and stores the result in the first half of z. Core 1 stores the computation result of core 0 in x, adds the computation result to y, and stores the result in the second half of z. Therefore, data synchronization needs to be performed between multiple cores.

// sync_gm is the public buffer for storing the external core status, and its type is GlobalTensor. sync_buf is the public buffer for storing the current core status, and its type is LocalTensor.
int32_t blockIdx = AscendC::GetBlockIdx(); // Obtain the current core.
if (blockIdx == 1) { // Set IBWait on core 1 to block instruction execution until the operation on core 0 is complete.
    AscendC::IBWait(sync_gm, sync_buf, 0, 0);
}
...
if (blockIdx == 0) { // Set IBSet on core 0. After the operation of core 0 is complete, execute the instruction of core 1.
    AscendC::IBSet(sync_gm, sync_buf, 0, 0);
}