根据变量类型和用法,变量可以存储在寄存器中或存储在Local Memory、Global Memory内存中,用户可以打印变量的地址以找出它的存储位置并进一步打印关联的内存。
GlobalTensor一般用来存放Global Memory(外部存储)的全局数据。
输入以下命令,进行GlobalTensor变量打印。以zGm为例,如下所示,zGm所在地址为“0x00001240c0016000”。
(msdebug) p zGm (AscendC::GlobalTensor<__fp16>) $0 = { bufferSize_ = 2048 shapeInfo_ = { shapeDim = '\0' originalShapeDim = '\0' shape = ([0] = 0, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 0, [6] = 0, [7] = 0) originalShape = ([0] = 0, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 0, [6] = 0, [7] = 0) dataFormat = ND } address_ = 0x00001240c0016000 }
因GlobalTensor类型变量实际的值保存在GM内存中,输入以下命令,打印GM内存中位于地址“0x00001240c0016000”上的值,打印格式设置为:打印1行,每行256字节,按照float16格式打印。
(msdebug) x -m GM -f float16[] 0x00001240c0016000 -s 256 -c 1 0x1240c0016000: {0 4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96 100 104 108 112 116 120 124 128 132 136 140 144 148 152 156 160 164 168 172 176 180 184 188 192 196 200 204 208 212 216 220 224 228 232 236 240 244 248 252 256 260 264 268 272 276 280 284 288 292 296 300 304 308 312 316 320 324 328 332 336 340 344 348 352 356 360 364 368 372 376 380 384 388 392 396 400 404 408 412 416 420 424 428 432 436 440 444 448 452 456 460 464 468 472 476 480 484 488 492 496 500 504 508} (msdebug) 打印GlobalTensor GlobalTensor一般用来存放Global Memory(外部存储)的全局数据。 输入以下命令,进行GlobalTensor变量打印。以zGm为例,如下所示,zGm所在地址为“0x00001240c0016000”。 (msdebug) p zGm (AscendC::GlobalTensor<__fp16>) $0 = { bufferSize_ = 2048 shapeInfo_ = { shapeDim = '\0' originalShapeDim = '\0' shape = ([0] = 0, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 0, [6] = 0, [7] = 0) originalShape = ([0] = 0, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 0, [6] = 0, [7] = 0) dataFormat = ND } address_ = 0x00001240c0016000 } 因GlobalTensor类型变量实际的值保存在GM内存中,输入以下命令,打印GM内存中位于地址“0x00001240c0016000”上的值,打印格式设置为:打印1行,每行256字节,按照float16格式打印。 (msdebug) x -m GM -f float16[] 0x00001240c0016000 -s 256 -c 1 0x1240c0016000: {0 4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96 100 104 108 112 116 120 124 128 132 136 140 144 148 152 156 160 164 168 172 176 180 184 188 192 196 200 204 208 212 216 220 224 228 232 236 240 244 248 252 256 260 264 268 272 276 280 284 288 292 296 300 304 308 312 316 320 324 328 332 336 340 344 348 352 356 360 364 368 372 376 380 384 388 392 396 400 404 408 412 416 420 424 428 432 436 440 444 448 452 456 460 464 468 472 476 480 484 488 492 496 500 504 508} (msdebug)
LocalTensor一般用于存放AI Core中Local Memory(内部存储)的数据。
输入以下命令,进行LocalTensor变量打印,以zLocal为例,如下图所示,zLocal地址位于1024上,长度为256。
(msdebug) p zLocal (AscendC::LocalTensor<__fp16>) $0 = { address_ = (logicPos = '\n', bufferHandle = "", dataLen = 256, bufferAddr = 1024) shapeInfo_ = { shapeDim = '\0' originalShapeDim = '\0' shape = ([0] = 0, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 0, [6] = 0, [7] = 0) originalShape = ([0] = 0, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 0, [6] = 0, [7] = 0) dataFormat = ND } } (msdebug)
该tensor变量实际的内容保存在UB内存中,输入以下命令,打印UB内存中位于地址1024上的值,打印格式设置为:打印1行,每行256字节,按照float16格式打印。
本用例中,tensor变量的实际内容保存在UB上,但LocalTensor不一定都保存在UB中,也可能在L1/L0A/L0B上,需要用户根据代码自行判断,然后在打印命令的-m选项中选择正确的内存类型。
(msdebug) x -m UB -f float16[] 1024 -s 256 -c 1 0x00000400: {0 4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96 100 104 108 112 116 120 124 128 132 136 140 144 148 152 156 160 164 168 172 176 180 184 188 192 196 200 204 208 212 216 220 224 228 232 236 240 244 248 252 256 260 264 268 272 276 280 284 288 292 296 300 304 308 312 316 320 324 328 332 336 340 344 348 352 356 360 364 368 372 376 380 384 388 392 396 400 404 408 412 416 420 424 428 432 436 440 444 448 452 456 460 464 468 472 476 480 484 488 492 496 500 504 508} (msdebug)
输入以下命令,打印当前作用域所有局部变量。
(msdebug) var (KernelAdd *) this = 0x000000000016a9b8 (int32_t) progress = 0 (AscendC::LocalTensor<__fp16>) zLocal = { address_ = (logicPos = '\n', bufferHandle = "", dataLen = 256, bufferAddr = 1024) shapeInfo_ = { shapeDim = '\0' originalShapeDim = '\0' shape = ([0] = 0, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 0, [6] = 0, [7] = 0) originalShape = ([0] = 0, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 0, [6] = 0, [7] = 0) dataFormat = ND } }