AI CPU Device调测
printf
AI CPU支持通过AscendC::printf实现Device运行时内容的格式化输出,调试信息可直接打印至Host终端。
调用示例如下:
foo.aicpu // 简化写法,无意义场景不可运行,仅演示编程编译使用方法 // 使用时需在.aicpu文件中包含aicpu_api.h #include"aicpu_api.h" __global__ __aicpu__ int test(void *arg) { AscendC::printf("fmt string %d\n", 0x123); return 0; }
编译时编译时需要指定头文件对应路径;通过--cce-aicpu-laicpu_api为Device链接libaicpu_api.a,通过--cce-aicpu-L指定libaicpu_api.a的库路径。编译命令如下:
$bisheng -O2 foo.aicpu --cce-aicpu-L${INSTALL_DIR}/toolkit/lib64/device/lib64 --cce-aicpu-laicpu_api -I${INSTALL_DIR}/include/ascendc/aicpu_api -c -o foo.aicpu.o
${INSTALL_DIR}请替换为CANN软件安装后文件存储路径。若安装的Ascend-cann-toolkit软件包,以root安装举例,则安装后文件存储路径为:/usr/local/Ascend/ascend-toolkit/latest。
该编译结果与Host调用文件的编译结果链接成可执行文件后,期望运行结果如下:
fmt string 0x123
assert
AI CPU支持算子调试过程中的断言功能。该功能通过在Device函数中调用assert实现,如果assert内部条件判断不为真,则在Host屏幕上输出assert条件、触发文件名、行号等信息。assert使用时需要包含头文件aicpu_api.h,且不可包含系统的assert.h,避免宏定义冲突。调用示例如下:
foo.aicpu
// 简化写法,无意义场景不可运行,仅演示编程编译使用方法
#include"aicpu_api.h"
__global__ __aicpu__ int test(void *arg) {
int assertFlag = 10;
// 断言条件
assert(assertFlag == 12);
return 0;
}
编译时需要指定头文件对应路径;通过--cce-aicpu-laicpu_api为Device链接libaicpu_api.a,通过--cce-aicpu-L指定libaicpu_api.a的库路径。编译命令如下:
$bisheng -O2 foo.aicpu --cce-aicpu-L${INSTALL_DIR}/toolkit/lib64/device/lib64 --cce-aicpu-laicpu_api -I${INSTALL_DIR}/include/ascendc/aicpu_api -c -o foo.aicpu.o
${INSTALL_DIR}请替换为CANN软件安装后文件存储路径。若安装的Ascend-cann-toolkit软件包,以root安装举例,则安装后文件存储路径为:/usr/local/Ascend/ascend-toolkit/latest。
该编译结果与Host调用文件的编译结果链接成可执行文件后,期望运行结果如下:
[ASSERT]` assertFlag == 12 ' at ...
父主题: AI CPU编程指导