assert
Supported Products
|
Product |
Supported |
|---|---|
|
|
√ |
|
|
√ |
|
|
x |
|
|
x |
|
|
x |
|
|
x |
Function
This API is used to implement the assert function in the AI CPU operator kernel debugging scenario. The header file aicpu_api.h must be included.
During operator execution, if the internal condition of assert is not true, the assert condition, trigger file name, and line number are output.
Prototype
1
|
assert(expr) |
Parameters
|
Parameter |
Input/Output |
Description |
|---|---|---|
|
expr |
Input |
Condition for asserting whether to terminate a program. If the value is true, the program continues to be executed. If the value is false, the program is terminated. |
Returns
None
Restrictions
- This API can be called only by using <<<...>>> and used in the heterogeneous compilation scenario.
- Do not include assert.h of the system during kernel development. Otherwise, macro definition conflicts may occur.
- The assert API is called in the same way as the C language, and the AscendC namespace is not required.
- This API uses the dump function. The total amount of dump data of all APIs using the dump function on each core cannot exceed 1 MB. You need to control the amount of data to be printed. If the limit is exceeded, no content will be printed.
- When this API is used, if the Bisheng compiler is used for compilation, you need to manually link related static libraries. When CMake is used for compilation, the framework automatically processes the link, and you do not need to pay attention to it. The specific compilation commands are as follows: Use --cce-aicpu-laicpu_api to link libaicpu_api.a to the device, and use --cce-aicpu-L to specify the library path of libaicpu_api.a.
$bisheng -O2 foo.aicpu --cce-aicpu-L${INSTALL_DIR}/lib64/device/lib64 --cce-aicpu-laicpu_api -I${INSTALL_DIR}/include/ascendc/aicpu_api -c -o foo.aicpu.o
Replace ${INSTALL_DIR} with the CANN component directory. For example, if the installation is performed by the root user, the default file storage path is /usr/local/Ascend/cann.
Example
In the operator kernel implementation code, assert can be used to check the code where assert is required. The following is an example:
1 2 3 |
int assertFlag = 10; // Assert condition assert(assertFlag == 12); |
Assert is triggered when the program is running. The print is as follows:
1
|
[ASSERT]` assertFlag == 12 ' at /home/.../test.cpp:36 |