Predefined Macros and Built-in Variables

Predefined Macros

Like other language compilers, the BiSheng Compiler has some predefined macros for developers to write programs.

Predefined Macros

Default Value

Description

__CCE_IS_AICORE__

1

The value is 1 on the device, which can be used to distinguish device code from host code.

__DAV_CUBE__

-

Isolates Cube-side code.

__DAV_VEC__

-

Isolates Vector-side code.

__NPU_ARCH__

-

Distinguishes between device-side and host-side code, while isolating code for different architectures on the device side.

Table 1 Mapping between AI processor models and __NPU_ARCH__

AI processor Model

__NPU_ARCH__

Atlas 350 Accelerator Card

3510

Atlas A3 training product / Atlas A3 inference product

2201

Atlas A2 training product / Atlas A2 inference product

2201

Atlas 200I/500 A2 inference product

3002

Atlas inference product

2002

Atlas training product

1001

Note:

  • Tightly coupled cores (CUBE and VEC not separated): The compiler defines both __DAV_CUBE__ and __DAV_VEC__.
  • Loosely coupled cores (CUBE and VEC separated): The compiler defines __DAV_CUBE__ when compiling CUBE and __DAV_VEC__ when compiling VEC.
  • CUBE-only cores: Only __DAV_CUBE__ is defined.
  • VECTOR-only cores: Only __DAV_VEC__ is defined.

Built-in Variables

The following variables are built-in variables of the BiSheng Compiler. The variable names defined by developers in programs cannot be the same as the built-in variable names. Additionally, built-in variables are usually used by the framework and remain imperceptible to developers. To obtain the core ID or number of cores, use the corresponding Ascend C API.

Table 2 Built-in variable list

Built-in Variable

Description

block_idx

Current core ID, which is a logical value in the core and remains imperceptible to developers. The core ID used during programming can be obtained by calling GetBlockIdx.

block_num

Number of used cores, which is a logical value in the core and remains imperceptible to developers. The number of cores used for programming can be obtained by calling GetBlockNum.