assert
Applicability
Product |
Supported |
|---|---|
Atlas 350 Accelerator Card |
√ |
√ |
|
√ |
|
x |
|
x |
|
x |
|
x |
Function Usage
Provides the assert function in SIMD and SIMT VF debugging scenarios (SIMT VF supported only on Atlas 350 Accelerator Card). In the operator kernel implementation code, if the internal assert condition evaluates to false, the condition is output, the input information is formatted and printed to the screen, and the operator execution fails.
Use assert at appropriate locations in the operator kernel code to perform condition checks and format the output of debugging information. The following is an example:
1 2 3 | int assertFlag = 10; assert(assertFlag == 10); |
1 | [ASSERT] /home/.../add_custom.cpp:44: : Assertion `assertFlag != 10' failed. |
Note that the printing function of the assert API affects the actual performance of the operator.
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 supports only the fusion compilation scenario.
- In the SIMD scenario, if you need to include the standard library header file <cassert>, include it before the utils/debug/asc_assert.h header file to avoid assert symbol conflicts.
Header Files to Be Included
To use this API, the utils/debug/asc_assert.h header file must be included.
1 | #include "utils/debug/asc_assert.h" |
SIMD Calling Example
1 2 3 4 5 6 | // SIMD __global__ __cube__ void simp_test_equal(int a) { // input a is 7 assert(a == 6); } |
Assert is triggered when the program is running. The print effect is as follows:
1 | [ASSERT] test_assert.asc:41: : Assertion `a == 6' failed. |
SIMT Calling Example
1 2 3 4 5 6 7 | //SIMT VF __simt_vf__ __launch_bounds__(1024) inline void AddCustom(__gm__ bool* dst, __gm__ float* x) { int idx = threadIdx.x + blockIdx.x * blockDim.x; assert(!isnan(x[idx])); dst[idx] = x[idx]; } |
Assert is triggered when the program is running. The print effect is as follows:
1 | [ASSERT] /home/.../add_custom.cpp:44: : Assertion `!isnan(x[idx])' failed. |