TorchAir C++层日志
功能简介
TorchAir C++层日志开启主要通过环境变量TNG_LOG_LEVEL实现,方便进行C++层功能调试和问题定位。
支持的日志级别如下:
- TNG_LOG_LEVEL:0,日志级别DEBUG,开启后输出DEBUG、INFO、WARNING、ERROR日志。
- TNG_LOG_LEVEL:1,日志级别INFO,开启后输出INFO、WARNING、ERROR日志。
- TNG_LOG_LEVEL:2,日志级别WARNING,开启后输出WARNING、ERROR日志。
- TNG_LOG_LEVEL:3,日志级别ERROR,开启后输出ERROR日志。
环境变量TNG_LOG_LEVEL的默认值为“3”。
使用方法
在shell或python脚本中,提前配置环境变量TNG_LOG_LEVEL。
- 在shell环境或者shell脚本
export TNG_LOG_LEVEL=0
- python脚本
该方式设置环境变量时,需早于import torchair,否则影响日志显示。
import os os.environ['TNG_LOG_LEVEL'] = '0'
C++侧debug日志样例如下
[DEBUG] TORCHAIR [static_npu_graph_executor.cpp:37] Assemble aten device input 0 at::Tensor(shape=[4, 1], dtype='float', device=npu:1, addr=0x124180000000) to ge::Tensor(shape=[4, 1], format=ND, dtype=DT_FLOAT, device=NPU, addr=0x124180000000) [DEBUG] TORCHAIR [static_npu_graph_executor.cpp:37] Assemble aten device input 1 at::Tensor(shape=[4, 4], dtype='float', device=npu:1, addr=0x124180000200) to ge::Tensor(shape=[4, 4], format=ND, dtype=DT_FLOAT, device=NPU, addr=0x124180000200) [DEBUG] TORCHAIR [static_npu_graph_executor.cpp:37] Assemble aten device input 2 at::Tensor(shape=[4, 4], dtype='int', device=npu:1, addr=0x124180000400) to ge::Tensor(shape=[4, 4], format=ND, dtype=DT_INT32, device=NPU, addr=0x124180000400) [DEBUG] TORCHAIR [static_npu_graph_executor.cpp:96] Create empty output 0 at::Tensor(shape=[4, 4], dtype='float', device=npu:1, addr=0x124180000800) [DEBUG] TORCHAIR [static_npu_graph_executor.cpp:104] Assemble torch output 0 at::Tensor(shape=[4, 4], dtype='float', device=npu:1, addr=0x124180000800) to ge::Tensor(shape=[4, 4], format=ND, dtype=DT_FLOAT, device=NPU, addr=0x124180000800) [INFO] TORCHAIR [AllocatorManager.cpp:11] Start to EnsureAllocatorRegistered according to stream = 0x228dd940 [INFO] TORCHAIR [AllocatorManager.cpp:19] External allocator did not registered, register allocator = 0x251a6ec0 while stream = 0x228dd940 [DEBUG] TORCHAIR [memory/Allocator.cpp:15] [MemoryTrace] Malloc memory from NPUCachingAllocator success, block = 0x234855e0 [DEBUG] TORCHAIR [memory/Allocator.cpp:25] [MemoryTrace] Malloc the mem_block success, mem_block = 0x23282c80, device_ptr = 0x124180000a00, size = 1536 [INFO] TORCHAIR [AllocatorManager.cpp:11] Start to EnsureAllocatorRegistered according to stream = 0x228dd940 [INFO] TORCHAIR [AllocatorManager.cpp:15] External allocator has registered, stream = 0x228dd940 , allocator = 0x251a6ec0 [INFO] TORCHAIR [static_npu_graph_executor.cpp:145] Try to alloc and update feature map memory, graph id = 0 , size = 512 [INFO] TORCHAIR [memory/Allocator.cpp:80] [MemoryTrace] MallocFeatureMemory: Try Malloc size = 512 [INFO] TORCHAIR [memory/Allocator.cpp:65] [MemoryTrace] MallocPoolMemory: Try Malloc size = 512 [DEBUG] TORCHAIR [memory/Allocator.cpp:15] [MemoryTrace] Malloc memory from NPUCachingAllocator success, block = 0x234856f0 [DEBUG] TORCHAIR [memory/Allocator.cpp:25] [MemoryTrace] Malloc the mem_block success, mem_block = 0x23283a80, device_ptr = 0x124180001000, size = 1024 [INFO] TORCHAIR [memory/Allocator.cpp:71] [MemoryTrace] MallocPoolMemory: Malloc memory success, size = 1024, and addr = 0x124180001000, use count = 1 [INFO] TORCHAIR [static_npu_graph_executor.cpp:160] AllocAndUpdateFeatureMemory success, feature map addr = 0x124180001000 , size = 1024 [INFO] TORCHAIR [static_npu_graph_executor.cpp:212] StaticNpuGraphExecutor::Run graph 0 on stream 0x228dd940 successfully
父主题: 日志功能