文档
注册

DumpTensor功能

功能介绍

使用工具进行算子调测时,支持DumpTensor功能,默认从Tensor的第0位元素开始打印指定长度的元素值。

固定为每个核分配的打印数据的最大可使用空间为1M,目前该大小不支持修改,若打印超过1M,打印内容不再显示,请开发者控制待打印的数据量。

使用方法(命令行)

  1. 在核函数代码中按需在目标位置调用DumpTensor接口,接口说明参见DumpTensor接口说明,样例如下:
    DumpTensor(srcLocal, 5, dataNum); 
  2. NPU调测场景执行如下命令,使能Dump开关。
    ascendebug kernel --backend npu --dump-mode normal ... {其他NPU调测参数}

    --dump-mode取normal,开启通用打印Tensor模式,其他参数说明请参考NPU调测参数,用户按需配置即可。

  3. 查看打印结果。

    Dump的Tensor数据存放到${work_dir}/${op_type}/npu路径下,目录结构示例如下:

    • ${work_dir}是调测工作空间,缺省时为当前路径下的debug_workspace文件夹(若无会自动新建)。
    • ${op_type}是调测算子名,本章以AddCustom为例。
    ├ AddCustom(算子名)
    ├── npu
    │   ├── dump
    │       ├── dump_data
    │           ├──0(core number)
    │               ├──index_5 (index是dump接口的desc唯一标识值)
    │                   ├──core_0_index_5_loop_0.bin
    │                   ├──core_0_index_5_loop_0.txt   
    │                   ├──core_0_index_5_loop_1.bin
    │                   ├──core_0_index_5_loop_1.txt
    │           ├──index_dtype.json(存放每个dump Tensor的数据类型)

    其中core_${core_id}_index_${index}_loop_${loop}.txt是工具根据bin文件自动解析的Dump结果,其命名规则为:

    • ${core_id}:计算核id。
    • ${index}:是Dump接口的desc唯一标识值。
    • ${loop}:若DumpTensor接口在for循环中被调用,其表示循环的索引值,否则默认为0。

使用方法(API)

  1. 在核函数代码中按需在目标位置调用DumpTensor接口,接口说明参见DumpTensor接口说明,样例如下:
    DumpTensor(srcLocal, 5, dataNum); 
  2. 设置dump_mode='normal',调用算子编译、运行API接口。这里以标准自定义场景下实现NPU上板打印Tensor数据为例:
    compile_npu_options = ascendebug.CompileNpuOptions(dump_mode='normal')
    name, kernel_file, extern = op_executor.compile_custom_npu(customize_path, tiling_info.tiling_key, compile_npu_options)
    npu_compile_info = ascendebug.NpuCompileInfo(syncall=extern['cross_core_sync'], task_ration=extern['task_ration'], dump_mode='normal')
    run_npu_options = ascendebug.RunNpuOptions()
    op_executor.run_npu(kernel_file, run_npu_options, npu_compile_info=npu_compile_info, tiling_info=tiling_info)
  3. 查看打印结果。

    Dump的Tensor数据存放到${work_dir}/${op_type}/npu路径下,目录结构示例如下:

    • ${work_dir}是调测工作空间,缺省时为当前路径下的debug_workspace文件夹(若无会自动新建)。
    • ${op_type}是调测算子名,本章以AddCustom为例。
    ├ AddCustom(算子名)
    ├── npu
    │   ├── dump
    │       ├── dump_data
    │           ├──0(core number)
    │               ├──index_5 (index是dump接口的desc唯一标识值)
    │                   ├──core_0_index_5_loop_0.bin
    │                   ├──core_0_index_5_loop_0.txt   
    │                   ├──core_0_index_5_loop_1.bin
    │                   ├──core_0_index_5_loop_1.txt
    │           ├──index_dtype.json(存放每个dump Tensor的数据类型)

    其中core_${core_id}_index_${index}_loop_${loop}.txt是工具根据bin文件自动解析的Dump结果,其命名规则为:

    • ${core_id}:计算核id。
    • ${index}:是Dump接口的desc唯一标识值。
    • ${loop}:若DumpTensor接口在for循环中被调用,其表示循环的索引值,否则默认为0。

DumpTensor接口说明

表1 DumpTensor接口说明表

函数原型

  • void DumpTensor(LocalTensor<T> &tensor, uint32_t desc, uint32_t dumpNum)
  • void DumpTensor(GlobalTensor<T> &tensor, uint32_t desc, uint32_t dumpNum)
  • void DumpTensor(LocalTensor<T> &tensor, uint32_t desc, uint32_t dumpNum, const ShapeInfo& shapeInfo)
  • void DumpTensor(GlobalTensor<T> &tensor, uint32_t desc, uint32_t dumpNum, const ShapeInfo& shapeInfo)

函数功能

从Tensor的第0位元素开始打印指定长度的元素值。

参数(IN)

tensor

用户需要Dump的Tensor。多个DumpTensor调用时,不可重复。

desc

用户自定义附加信息(行号或其他自定义数字)。

dumpNum

需要Dump的元素个数。

shapeInfo

如果有Tensor的shape信息,工具可解析shapeInfo并进行打印。

参数(OUT)

NA

-

返回值

NA

-

使用约束

  • 当前接口仅支持位于Unified Buffer/L1 Buffer/L0C Buffer/Global Memory的数据Dump。
  • 每次Dump的大小(dataNum * sizeof(T))需要32B对齐。

调用示例

DumpTensor(srcLocal,5, dataNum);   // Dump LM
DumpTensor(this->gm_, 0, dataNum); // Dump GM
搜索结果
找到“0”个结果

当前产品无相关内容

未找到相关内容,请尝试其他搜索词