---
title: AI CPU Device调测
description: "AI CPU支持通过AscendC::printf(https://www.hiascend.comdocument/detail/zh/canncommercial/900/API/ascendcopapi/atlasascendc_api_07_00166.html)实现Device运行时内容的格式化输出，调试信息可直接打印至Host终端。"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/compiler/BishengCompiler/atlas_bisheng_10_0020.html
sourcePath: /source/zh/canncommercial/900/compiler/BishengCompiler/atlas_bisheng_10_0020.html
indexId: 4a9114258390b7c1d677c530076c05d8af37e7efaf18c234ada594c9f19cdded81
---
# AI CPU Device调测

#### printf

AI CPU支持通过AscendC::printf(https://www.hiascend.comdocument/detail/zh/canncommercial/900/API/ascendcopapi/atlasascendc_api_07_00166.html)实现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}/lib64/device/lib64 --cce-aicpu-laicpu_api -I${INSTALL_DIR}/include/ascendc/aicpu_api -c -o foo.aicpu.o
```


${INSTALL_DIR}请替换为CANN软件安装后文件存储路径。以root用户安装为例，安装后文件默认存储路径为：/usr/local/Ascend/cann。

该编译结果与Host调用文件的编译结果链接成可执行文件后，期望运行结果如下：

```
fmt string 0x123
```


#### assert

AI CPU支持算子调试过程中的断言功能。该功能通过在Device函数中调用assert(https://www.hiascend.comdocument/detail/zh/canncommercial/900/API/ascendcopapi/atlasascendc_api_07_00167.html)实现，如果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}/lib64/device/lib64 --cce-aicpu-laicpu_api -I${INSTALL_DIR}/include/ascendc/aicpu_api -c -o foo.aicpu.o
```

${INSTALL_DIR}请替换为CANN软件安装后文件存储路径。以root用户安装为例，安装后文件默认存储路径为：/usr/local/Ascend/cann。

该编译结果与Host调用文件的编译结果链接成可执行文件后，期望运行结果如下：

```
[ASSERT]` assertFlag == 12 ' at ...
```
