AI CPU Device Debugging
printf
AI CPU supports formatted output of device runtime content through AscendC::printf. The debugging information can be directly printed to the host terminal.
foo.aicpu
// Simplified writing. These commands are used as a demo and cannot be run in meaningless scenarios.
// Include aicpu_api.h in the .aicpu file.
#include"aicpu_api.h"
__global__ __aicpu__ int test(void *arg) {
AscendC::printf("fmt string %d\n", 0x123);
return 0;
}
$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.
After the compile result is linked with the compile result of the host call file to form an executable file, the expected running result is as follows:
fmt string 0x123
assert
foo.aicpu
// Simplified writing. These commands are used as a demo and cannot be run in meaningless scenarios.
#include"aicpu_api.h"
__global__ __aicpu__ int test(void *arg) {
int assertFlag = 10;
// Assert condition
assert(assertFlag == 12);
return 0;
}
During compile, specify the path of the header file. 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. The compile command is as follows:
$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.
After the compile result is linked with the compile result of the host call file to form an executable file, the expected running result is as follows:
[ASSERT]` assertFlag == 12 ' at ...