基于算子工程开发的算子,可以使用该接口Dump指定Tensor的内容。同时支持打印自定义的附加信息(仅支持uint32_t数据类型的信息),比如打印当前行号等。
1
|
AscendC::DumpTensor(srcLocal,5, dataLen); |
Dump时,每个block核的dump信息前会增加对应信息头DumpHead(32字节大小),用于记录核号和资源使用信息;每次Dump的Tensor数据前也会添加信息头DumpTensorHead(32字节大小),用于记录Tensor的相关信息。如下图所示,展示了多核打印场景下的打印信息结构。
DumpHead的具体信息如下:
DumpTensorHead的具体信息如下:
DumpTensor打印结果的最前面会自动打印CANN_VERSION_STR值与CANN_TIMESTAMP值。其中,CANN_VERSION_STR与CANN_TIMESTAMP为宏定义,CANN_VERSION_STR代表CANN软件包的版本号信息,形式为字符串,CANN_TIMESTAMP为CANN软件包发布时的时间戳,形式为数值(uint64_t)。开发者也可在代码中直接使用这两个宏。
打印示例如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
CANN Version: XXX.XX, TimeStamp: 20240807XXXXXXXXX DumpHead: block_id=0, total_block_num=16, block_remain_len=1048448, block_initial_space=1048576, magic=5aa5bccd DumpTensor: desc=5, addr=0, data_type=DT_FLOAT16, position=UB [40, 82, 60, 11, 24, 55, 52, 60, 31, 86, 53, 61, 47, 54, 34, 62, 84, 29, 48, 95, 16, 0, 20, 77, 3, 55, 69, 73, 75, 40, 35, 13] CANN Version: XXX.XX, TimeStamp: 20240807XXXXXXXXX DumpHead: block_id=1, total_block_num=16, block_remain_len=1048448, block_initial_space=1048576, magic=5aa5bccd DumpTensor: desc=5, addr=0, data_type=DT_FLOAT16, position=UB [58, 84, 22, 54, 41, 93, 1, 45, 50, 9, 72, 81, 23, 96, 86, 45, 36, 9, 36, 34, 78, 7, 2, 29, 47, 26, 13, 24, 27, 55, 90, 5] ... CANN Version: XXX.XX, TimeStamp: 20240807XXXXXXXXX DumpHead: block_id=7, total_block_num=16, block_remain_len=1048448, block_initial_space=1048576, magic=5aa5bccd DumpTensor: desc=5, addr=0, data_type=DT_FLOAT16, position=UB [28, 27, 79, 39, 86, 5, 23, 97, 89, 5, 65, 69, 59, 13, 49, 2, 34, 6, 52, 38, 4, 90, 11, 11, 61, 50, 71, 98, 19, 54, 54, 99] |
1 2 3 4 |
template <typename T> __aicore__ inline void DumpTensor(const LocalTensor<T> &tensor, uint32_t desc, uint32_t dumpSize) template <typename T> __aicore__ inline void DumpTensor(const GlobalTensor<T>& tensor, uint32_t desc, uint32_t dumpSize) |
1 2 3 4 |
template <typename T> __aicore__ inline void DumpTensor(const LocalTensor<T>& tensor, uint32_t desc, uint32_t dumpSize, const ShapeInfo& shapeInfo) template <typename T> __aicore__ inline void DumpTensor(const GlobalTensor<T>& tensor, uint32_t desc, uint32_t dumpSize, const ShapeInfo& shapeInfo) |
参数名 |
描述 |
---|---|
T |
需要dump的Tensor的数据类型。支持的数据类型为uint8_t/int8_t/int16_t/uint16_t/int32_t/uint32_t/int64_t/uint64_t/float/half/bfloat16_t。 |
参数名 |
输入/输出 |
描述 |
---|---|---|
tensor |
输入 |
需要dump的Tensor。
|
desc |
输入 |
用户自定义附加信息(行号或其他自定义数字)。 在使用DumpTensor功能时,用户可通过desc参数附加自定义信息,以便在不同调用场景下区分Dump内容的来源。此功能有助于精准定位具体DumpTensor的输出,提升调试与分析效率。 |
dumpSize |
输入 |
需要dump的元素个数。dump的元素总长度需要32字节对齐。 |
shapeInfo |
输入 |
传入Tensor的shape信息,可按照shape信息进行打印。 |
无
1
|
AscendC::DumpTensor(srcLocal,5, dataLen); |
1 2 3 |
uint32_t array[] = {static_cast<uint32_t>(8),static_cast<uint32_t>(8)}; AscendC::ShapeInfo shapeInfo(2, array); // dim为2, shape为(8,8) AscendC::DumpTensor(x, 2, 64, shapeInfo); // dump x的64个元素,且解析按照shapeInfo的(8,8)排列 |
打印结果如下:
1 2 3 4 5 6 7 8 |
[[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]] |