GetBlockIdx

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

Obtains the index of the current core, which is used for multi-core logic control and multi-core offset computation in the code.

Prototype

1
__aicore__ inline int64_t GetBlockIdx()

Parameters

None

Returns

GetBlockIdx returns the index of the current core. The value range is [0, NumBlocks).

In the scenario where both the AIC and AIV are started:

When the AIC-to-AIV ratio is 1:2, the value range on the AIC is [0, NumBlocks), and the value range on the AIV is [0, 2 × NumBlocks).

When the AIC-to-AIV ratio is 1:1, the value range on the AIC is [0, NumBlocks), and the value range on the AIV is [0, NumBlocks).

Constraints

GetBlockIdx is a built-in function of the system. It returns the index of the current core.

Example

1
2
3
4
5
6
7
8
// srcGm and dstGm are the external global memory space.
AscendC::GlobalTensor<float> srcGlobal;
AscendC::GlobalTensor<float> dstGlobal;
blockNum = AscendC::GetBlockNum(); // Obtain the total number of cores.
perBlockSize = srcDataSize / blockNum; // Each core evenly processes the same number of pieces of data.
blockIdx = AscendC::GetBlockIdx(); // Obtain the ID of the current working core.
srcGlobal.SetGlobalBuffer(reinterpret_cast<__gm__ float*>(srcGm + blockIdx * perBlockSize * sizeof(float)), perBlockSize);    // Allocate the memory address of srcGlobal on each core.
dstGlobal.SetGlobalBuffer(reinterpret_cast<__gm__ float*>(dstGm + blockIdx * perBlockSize * sizeof(float)), perBlockSize);    // Allocate the memory address of dstGlobal on each core.