Closed
[Bug]: PR-40113 ACL_CALL_LOG 门控缓存导致 TORCH_NPU_LOGS=acl 不生效 #3614
wuyouqi1Add on Aug 1Closed at Aug 3
Aug 1 Added label: bug
Aug 1 Change title to "[Bug]: PR-40113 ACL_CALL_LOG 门控缓存导致 TORCH_NPU_LOGS=acl 不生效", originally titled "[Bug]: 1".
Aug 1 Change title to "[Bug]: PR-40113 ACL_CALL_LOG 门控缓存导致 TORCH_NPU_LOGS=acl 不生效", originally titled "[Bug]: 1".
Aug 1 Modify description of issue
Aug 3 Added label: bot-triaged
TorchNPU-Bot
Aug 3 Comments:
Aug 3 Comments:
检测到当前 issue 已关联 PR !43374,自动添加标签:bot-triaged


Aug 3 Close issue
Aug 3 Associated pull request
Aug 3 Associated pull request
Aug 3 Associated pull request
Aug 3 Associated pull request
Aug 3 Modify description of issue
Aug 3 Added label: resolved
Aug 24 Associated pull request
Aug 24 Associated pull request
Aug 24 Associated pull request
Aug 24 Associated pull request
Aug 24 Associated pull request
[Bug]: PR-40113 ACL_CALL_LOG 门控缓存导致 TORCH_NPU_LOGS=acl 不生效
环境信息
问题描述
PR-40113 合入后,
export TORCH_NPU_LOGS=acl无法打印 ACL 调用日志。必须额外设置ASCEND_GLOBAL_LOG_LEVEL=1才能打出。根因
PR-40113 将日志门控改为
call_once缓存g_log_enabled,但首次 ACL 调用发生在libtorch_npu.so被dlopen加载时的 C++ 全局变量初始化阶段——op-plugin 仓MlaPrologV3KernelNpuOpApi.cpp:34的全局bool is_cann_version_gte_required = IsGteCANNVersion(...)在.so加载时自动执行,触发AclsysGetCANNVersion→ACL_CALL_LOG宏,远早于 Python 侧LogContext::setLogs()处理TORCH_NPU_LOGS。此时LogContext未收到任何 log 配置,logger 默认级别为 WARNING(30) > INFO(20),g_log_enabled被永久锁为 false,之后setLogs()更新 logger level 也无法逆转。修复
g_log_enabled改为从环境变量直接判断——getenv("TORCH_NPU_LOGS") != nullptr,与TORCH_NPU_LOGS_FILTER一致。环境变量在dlopen之前已可用,C++ 全局变量初始化无论多早触发都能正确读取。热路径开销与 PR-40113 完全等价(~2 cycle)。仅改
AclCallDecorator.cpp。欢迎加入社区,感谢您对社区的贡献!