printf
产品支持情况
功能说明
本接口提供SIMT VF调试场景下的格式化输出功能。在算子Kernel侧的SIMT VF实现代码中,需要输出日志信息时,调用printf接口打印相关内容。
函数原型
template <class... Args>
__attribute__((always_inline)) inline __simt_callee__ void printf(const __gm__ char* fmt, Args&&... args)
参数说明
返回值说明
无
约束说明
- printf在SIMT VF中调用,会占用SIMT栈空间,请合理控制调用printf次数,防止SIMT栈溢出。
- printf功能需要占用额外的Global Memory空间用于数据缓存,缓存空间大小默认为2MB。您可以通过acl.json中的"simt_printf_fifo_size"字段进行配置,配置范围最小为1MB,最大为64MB。当打印数据量较大时,建议增加缓存空间。
- 在仿真环境下,使用printf接口会增加算子运行时间,通过在VF代码中判断线程ID,可以仅在部分线程中打印调试信息,减少重复内容的打印,更有利于调试。
需要包含的头文件
使用该接口需要包含"utils/debug/asc_printf.h"头文件。
#include "utils/debug/asc_printf.h"
调用示例
#include "kernel_operator.h"
#include "simt_api/asc_simt.h"
#include "utils/debug/asc_printf.h"
// asc_vf_call调用时dim3参数:dim3(8, 2, 8)
__simt_vf__ __launch_bounds__(128) inline void SimtCompute()
{
int x = threadIdx.x;
int y = threadIdx.y;
int z = threadIdx.z;
printf("simt vf: d: (%d, %d, %d), f: %f, s: %s\n", x, y, z, 3.14f, "pass");
}
NPU模式下,程序运行时打印效果如下:
simt vf: d: (0, 0, 0), f: 3.140000, s: pass
simt vf: d: (0, 0, 1), f: 3.140000, s: pass
simt vf: d: (0, 0, 2), f: 3.140000, s: pass
simt vf: d: (0, 0, 3), f: 3.140000, s: pass
simt vf: d: (0, 0, 4), f: 3.140000, s: pass
simt vf: d: (0, 0, 5), f: 3.140000, s: pass
simt vf: d: (0, 0, 6), f: 3.140000, s: pass
simt vf: d: (0, 0, 7), f: 3.140000, s: pass
simt vf: d: (0, 1, 0), f: 3.140000, s: pass
simt vf: d: (0, 1, 1), f: 3.140000, s: pass
......