GetBlockIdx

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

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, BlockDim quantity set by the user).

In the scenario where both AICs and AIVs are started:

When the ratio of AICs to AIVs is 1:2, the value range on the AIC is [0, BlockDim quantity set by the user), and the value range on the AIV is [0, 2 × BlockDim quantity set by the user).

When the ratio of AICs to AIVs is 1:1, the value range on the AIC is [0, BlockDim quantity set by the user), and the value range on the AIV is [0, BlockDim quantity set by the user).

Restrictions

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
 9
10
11
12
13
14
15
16
17
18
#include "kernel_operator.h"
constexpr int32_t SINGLE_CORE_OFFSET = 256;
class KernelGetBlockIdx {
public:
    __aicore__ inline KernelGetBlockIdx () {}
    __aicore__ inline void Init(__gm__ uint8_t* src0Gm, __gm__ uint8_t* src1Gm, __gm__ uint8_t* dstGm)
    {
        // Offset the address of each core based on the index.
        src0Global.SetGlobalBuffer((__gm__ float*)src0Gm + AscendC::GetBlockIdx() * SINGLE_CORE_OFFSET);
        src1Global.SetGlobalBuffer((__gm__ float*)src1Gm + AscendC::GetBlockIdx() * SINGLE_CORE_OFFSET);
        dstGlobal.SetGlobalBuffer((__gm__ float*)dstGm + AscendC::GetBlockIdx() * SINGLE_CORE_OFFSET);
        pipe.InitBuffer(inQueueSrc0, 1, 256 * sizeof(float));
        pipe.InitBuffer(inQueueSrc1, 1, 256 * sizeof(float));
        pipe.InitBuffer(selMask, 1, 256);
        pipe.InitBuffer(outQueueDst, 1, 256 * sizeof(float));
    }
    ......
};