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 code and host code, while isolating code for different architectures on the device side.

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 1 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 must be obtained by calling the "SIMD APIs > Basic APIs > TPosition > GetBlockIdx" API in Ascend C Operator Development.

block_num

Number of used cores, which is a logical value in the core and remains imperceptible to developers. The number of cores used during programming must be obtained by calling the "SIMD APIs > Basic APIs > TPosition > GetBlockNum" API in Ascend C Operator Development.