assert
Product Support
|
Product |
Supported |
|---|---|
|
|
√ |
|
|
√ |
|
|
x |
|
|
x |
|
|
x |
|
|
x |
Function
This API implements 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 assert condition is not true, information such as the assert condition, trigger file name, and line number is 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 through <<<...>>> and is 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 using this API, if you use the bisheng command line for compilation, you need to manually link the related static library. However, if you use CMake for compilation, the framework automatically handles the linkage, 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
Use assert to check the code where assertions need to be added to the implementation code on the kernel of the operator. 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 |