基于算子工程开发的算子,可以使用该接口实现CPU侧/NPU侧调试场景下的格式化输出功能。
1 2 3 | #include "kernel_operator.h" AscendC::printf("fmt string %d\n", 0x123); AscendC::PRINTF("fmt string %d\n", 0x123); |
1 2 3 4 | // 关闭所有算子的printf打印功能 ascendc_compile_definitions(ascendc_kernels_${RUN_MODE} PRIVATE -DASCENDC_DUMP=0 ) |
1 2 3 | target_compile_definitions(ascendc_kernels_${RUN_MODE} PRIVATE -DASCENDC_DUMP=0 ) |
需要注意的是,关闭CPU侧的打印开关时,只对PRINTF接口生效,对printf不生效。
CANN Version: XXX.XX, TimeStamp: 20240807140556417 fmt string 291 fmt string 291
1 2 | void printf(__gm__ const char* fmt, Args&&... args) void PRINTF(__gm__ const char* fmt, Args&&... args) |
参数名 |
输入/输出 |
描述 |
---|---|---|
fmt |
输入 |
格式控制字符串,包含两种类型的对象:普通字符和转换说明。
|
args |
输入 |
附加参数,个数和类型可变的输出列表:根据不同的fmt字符串,函数可能需要一系列的附加参数,每个参数包含了一个要被插入的值,替换了fmt参数中指定的每个%标签。参数的个数应与%标签的个数相同。 |
无
Atlas A2训练系列产品/Atlas 800I A2推理产品
Atlas推理系列产品AI Core
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #include "kernel_operator.h" // 整型打印: AscendC::printf("fmt string %d\n", 0x123); AscendC::PRINTF("fmt string %d\n", 0x123); // 浮点型打印: float a = 3.14; AscendC::printf("fmt string %f\n", a); AscendC::PRINTF("fmt string %f\n", a); // 指针打印: int *a; AscendC::printf("TEST %p\n", a); AscendC::PRINTF("TEST %p\n", a); |
程序运行时打印效果如下:
fmt string 291 fmt string 291 TEST 0x12c08001a000 TEST 0x12c08001a000