GetBlockNum

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 number of cores configured for the current task, which is used for multi-core logic control in the code.

Prototype

1
__aicore__ inline int64_t GetBlockNum()

Parameters

None

Returns

Number of cores configured for the current task

Constraints

None

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.