ascendc_assert
Supported Products
Product |
Supported/Unsupported |
|---|---|
√ |
|
√ |
|
√ |
|
√ |
|
x |
|
x |
Functions
ascendc_assert provides an API for implementing the assertion function in the CPU or NPU domain. When the assertion condition is not met, the system outputs the assertion information and prints it in a formatted manner on the screen.
1 2 3 4 5 | int assertFlag = 10; ascendc_assert(assertFlag != 10); ascendc_assert(assertFlag != 10, "The assertFlag value is 10.\n"); ascendc_assert(assertFlag != 10, "The assertFlag value is %d.\n", assertFlag); |
The printing function of the ascendc_assert API affects the actual running performance of the operator. (For each ascendc_assert, the system adds an additional logical judgment. The specific performance impact depends on the number of ascendc_asserts used in the code.) Generally, this function is used in the debugging phase. You can disable the printing function by setting ASCENDC_DUMP to 0.
1 2 | DumpHead: AIV-0, CoreType=AIV, block dim=8, total_block_num=8, block_remain_len=696, block_initial_space=1024, rsv=0, magic=5aa5bccd [ASSERT] /home/.../add_custom.cpp:44: Assertion `assertFlag != 10' The assertFlag value is 10. |
1 2 | DumpHead: AIV-0, CoreType=AIV, block dim=8, total_block_num=8, block_remain_len=696, block_initial_space=1024, rsv=0, magic=5aa5bccd [ASSERT]/home/.../add_custom.cpp:44: Assertion `assertFlag != 10' |
Prototype
1 2 | ascendc_assert(expr) ascendc_assert(expr, __gm__ const char *fmt, Args&&... args) |
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. |
fmt |
Input |
Format control string, which contains two types of objects: common characters and conversion descriptions.
Note:
|
args |
Input |
Additional arguments (an output list with variable quantities and types). Depending on the fmt string, the function may require a series of additional arguments. Each argument contains a value to be inserted and replaces each % tag specified in the fmt parameter. The number of arguments must be the same as the number of % tags. |
Returns
None
Restrictions
- This API does not support the operator graph input scenario.
- This API does not support the simulator mode.
- This API does not need to use the AscendC namespace.
- This API does not support the printing of escape characters except newline characters.
- The total size of data printed by a single call to this API cannot exceed 1 MB (including the header and trailer information required by the framework, which can be ignored). If the limit is exceeded, the data will not be printed.
- When the custom operator project is used, the following restrictions exist:
- This API uses the dump function. The total size of dump data of all APIs that use the dump function for an operator 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.
- The space used by this API on each core cannot exceed 1 KB. You need to control the amount of data to be printed. If the limit is exceeded, no content will be printed.
Examples
- API Calling Example
1 2 3 4 5 6 7 8 9 10 11
int assertFlag = 10; // Assert condition ascendc_assert(assertFlag == 10); // Print messages. ascendc_assert(assertFlag == 10, "The assertFlag value is 10.\n"); // Format the print. ascendc_assert(assertFlag == 10, "The assertFlag value is %d.\n", assertFlag); ascendc_assert(assertFlag != 10, "The assertFlag value is %d.\n", assertFlag);
Assert is triggered when the program is running. The print is as follows:
1[ASSERT] /home/.../add_custom.cpp:44: Assertion `assertFlag != 10' The assertFlag value is 10.
- The following is an example of disabling the ASCENDC_DUMP function in the custom operator project and kernel direct debugging project.
- Custom operator projectModify the CMakeLists.txt file in the op_kernel directory of the operator project. Add the compilation option -DASCENDC_DUMP=0 to the first line to disable ASCENDC_DUMP. The following is an example.
1 2
// Disable the printing function of all operators. add_ops_compile_options(ALL OPTIONS -DASCENDC_DUMP=0)
- Kernel launch project
- Modify the npu_lib.cmake file in the cmake directory and add the macro definition ASCENDC_DUMP=0 to the ascendc_compile_definitions command to disable the ASCENDC_DUMP function on the NPU. The following is an example:
1 2 3 4
// Disable the printing function of all operators. ascendc_compile_definitions(ascendc_kernels_${RUN_MODE} PRIVATE ASCENDC_DUMP=0 )
- In the cpu_lib.cmake file in the CMake directory, add the macro definition ASCENDC_DUMP=0 to the target_compile_definitions command to disable the ASCENDC_DUMP function on the CPU. The following is an example:
1 2 3
target_compile_definitions(ascendc_kernels_${RUN_MODE} PRIVATE ASCENDC_DUMP=0 )
- Modify the npu_lib.cmake file in the cmake directory and add the macro definition ASCENDC_DUMP=0 to the ascendc_compile_definitions command to disable the ASCENDC_DUMP function on the NPU. The following is an example:
- Custom operator project