产品 |
是否支持 |
|---|---|
Ascend 950PR/Ascend 950DT |
√ |
√ |
|
√ |
|
x |
|
x |
|
x |
|
x |
本接口提供SIMD和SIMT编程调试场景下的格式化输出功能。
在算子Kernel侧的实现代码中,需要输出日志信息时,调用printf接口打印相关内容。
printf(PRINTF)接口打印功能会对算子实际运行的性能带来一定影响,通常在调测阶段使用。开发者可以按需通过设置ASCENDC_DUMP=0的方式关闭打印功能
1 2 | template <class... Args> __aicore__ inline void printf( const __gm__ char* fmt, Args&&... args) |
以下接口为simd_vf中所使用的printf接口,仅支持Ascend 950PR/Ascend 950DT。
1 2 | template <class... Args> __simd_callee__ inline void printf( const __ubuf__ char* fmt, Args&&... args) |
无
__ubuf__ const char* fmt = "simd vf: int=%d, uint=%u, float=%f, string=%s\n";
使用该接口需要包含"utils/debug/asc_printf.h"头文件。
1 | #include "utils/debug/asc_printf.h" |
1 2 3 4 5 6 7 8 9 10 11 12 13 | #include "utils/debug/asc_printf.h" // SIMD printf __global__ __mix__(1, 2) void hello_world() { // print string printf("hello world device\n"); // print int printf("fmt string int: %d\n", 0x123); // print float float b = 3.14; printf("fmt string float: %f\n", b); } |
NPU模式下,程序运行时打印效果如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 | hello world device fmt string int: 291 fmt string float: 3.140000 hello world device fmt string int: 291 fmt string float: 3.140000 hello world device fmt string int: 291 fmt string float: 3.140000 hello world device fmt string int: 291 fmt string float: 3.140000 ...... |
1 2 3 4 5 6 7 8 | #include "kernel_operator.h" #include "utils/debug/asc_printf.h" __simd_vf__ inline void SimdVfPrint() { __ubuf__ const char* fmt = "simd vf: int=%d, uint=%u, float=%f, string=%s\n"; printf(fmt, 1, 2U, 5.0f, "AscendC"); } |
NPU模式下,程序运行时打印效果如下:
1 2 3 4 | simd vf: int=1, uint=2, float=5.000000, string=AscendC simd vf: int=1, uint=2, float=5.000000, string=AscendC simd vf: int=1, uint=2, float=5.000000, string=AscendC ...... |
1 2 3 4 5 6 7 8 9 10 11 12 | #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模式下,程序运行时打印效果如下:
1 2 3 4 5 6 7 8 9 10 11 | 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 ...... |