When the tool is used for operator debugging, the DumpTensor function is supported. By default, the element value of a specified length is printed starting from element 0 of the tensor.
DumpTensor in the simulator debugging scenario is controlled by the dump mode parameter.
The maximum available space allocated to each core for printing data is fixed at 1 MB. If the printing size exceeds 1 MB, the printed content will not be displayed. Therefore, the amount of data to be printed needs to be controlled.
Call the DumpTensor API at the target position in the kernel code as required. For details about the API description, see Table 1. The following is an example:
DumpTensor(srcLocal, 5, dataNum);
In the simulator debugging scenario, run the following command to enable the dump function:
ascendebug kernel --backend simulator --dump-mode normal ... {other simulator debugging parameters} --Set dump-mode to normal to enable the general printing Tensor mode. Set other parameters by referring to NPU Debugging Parameters.
View the dump result. For details, see Artifact Description.
The DumpTensor API is described as follows:
Function prototype:
Function usage: Prints the element value of a specified length starting from element 0 of a tensor.
Parameter (IN):
Parameter (OUT): N/A
Return value: N/A
Restrictions:
Calling example:
Example 1: Printing without tensor shape
DumpTensor(srcLocal,5, dataNum); # Dump LM DumpTensor(this->gm_, 0, dataNum); # Dump GM
Example 2: Printing with tensor shape
uint32_t array[] = {static_cast<uint32_t>(8),static_cast<uint32_t>(8)};
ShapeInfo shapeInfo(2, array); # Set dim to 2 and shape to (8,8).
DumpTensor(x, 2, 64, shapeInfo); # Dump 64 elements of **x**, which are parsed and arranged based on (8,8) of **shapeInfo**. The command output is as follows:
[[150.000000,83.000000,109.000000,166.000000,129.000000,50.000000,150.000000,74.000000], [135.000000,79.000000,98.000000,134.000000,146.000000,166.000000,112.000000,70.000000], [122.000000,51.000000,116.000000,68.000000,172.000000,72.000000,102.000000,69.000000], [136.000000,83.000000,88.000000,88.000000,112.000000,148.000000,79.000000,136.000000], [133.000000,104.000000,83.000000,71.000000,83.000000,99.000000,103.000000,151.000000], [98.000000,118.000000,128.000000,83.000000,25.000000,105.000000,179.000000,34.000000], [104.000000,169.000000,115.000000,113.000000,134.000000,121.000000,88.000000,96.000000], [29.000000,139.000000,70.000000,40.000000,158.000000,138.000000,72.000000,171.000000]]
The dumped tensor data is stored in the ${root}/${work_dir}/simulator directory. ${root} indicates the current operation path, ${work_dir} indicates the debugging workspace, and the default directory is /debug_workspace/${op_type}. ${op_type} indicates the operator name. The directory structure is as follows:
├ ${op_type} // Operator name
├── simulator
│ ├── dump
│ ├── PARSER_${timestamp}
│ ├── dump_data
│ ├──0 // Core ID
│ ├──index_5 // **index** is the unique identifier of the dump API description.
│ ├──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 // Storing the data type of each dump tensor core_${core_id}_index_${index}_loop_${loop}.txt is the dump result automatically parsed by the tool based on the .bin file. The naming rules are as follows:
${core_id}: compute core ID.
${index}: unique identifier of the dump API.
${loop}: If the DumpTensor API is called in the for loop, this parameter indicates the loop index. Otherwise, the default value is 0.