| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
fix(machine): Fix bisheng warning log Co-authored-by: anyangle<anyangle@huawei.com> # message auto-generated for no-merge-commit merge: !5391 merge bisheng into master fix(machine): Fix bisheng warning log Created-by: quadrate Commit-by: anyangle Merged-by: cann-robot Description: ## 1. 背景与问题 A5 场景下,动态 kernel 编译会调用 bisheng。成功时终端仍会刷大量 note:: text note: .../aicore_entry_dfx.h:117:33: Identify the scenario where the NOP instruction is inserted to prevent a running failure. note: .../aicore_entry_devtask.h:49:72: Identify the scenario where the NOP instruction is inserted to prevent a running failure. 来源是 bisheng 的 **Auto NOP Insert** pass(cce-aicore-auto-nop-insert),用于在特定指令序列中自动插入 NOP,避免上板运行失败。该诊断打在 **stdout**。 ## 2. 方案验证 当前涉及 bisheng 编译的有两个场景,分别在 codegen_npu.cpp 和 aicore_compiler.cpp 中。实验了以下几种方案: | 方案 | 能否消 note | 风险 / 代价 | 结论 | |------|-------------|-------------|------| | -mllvm -cce-aicore-auto-nop-insert=false | 能 | 关闭自动插 NOP,可能上板失败 | 否决 | | 编译命令加 -w | aicore 路径压不住 | 还会掩盖其它 warning | 否决 | | stdout/stderr 全量落盘 | 能 | 真实错误也进日志,终端即时性差 | 过重 | | **仅 stdout 落盘,失败回显** | 能 | 不改编译语义 | **采用** | 经确认,刷屏来自 CompileCoreMachine,leaf(codegen_npu.cpp)无贡献,因此只改 aicore 路径。 ## 3. 实现方案 ### 3.1 核心思路 Checkinject 禁止 std::system() 参数中出现 ; | < > \ 等 shell 元字符,因此 **不能在 C++ 里直接拼 bisheng ... > log**。 改为通过固定脚本 run_to_log.sh 在 shell 内部完成 stdout 重定向;C++ 仅执行不含 > 的 bash 调用。 ### 3.2 调用关系 text CompileAICoreKernel └─ CompileCoreMachine (AIC / AIV) └─ RunBishengQuiet ← 原先 std::system(ccecCmd) └─ bash run_to_log.sh <log_path> <compile_cmd> ### 3.3 RunBishengQuiet 流程 1. 在 objFile 所在目录用 mkstemp 创建临时日志文件 bisheng_log_<pid>_XXXXXX 2. GetRunToLogScriptPath() 查找固定脚本(优先级): - GetPyptoLibPath()/scripts/run_to_log.sh(安装包 / UT 软链) - 源码旁路:aicore_compiler.cpp 同目录下 compile/scripts/run_to_log.sh 3. 拼 runCmd 并 Checkinject 校验后执行: text bash '<script_path>' '<log_path>' '<bisheng ...>' 参数经 QuoteShellArg 单引号转义,避免路径/命令被 shell 拆开 4. run_to_log.sh 内部执行 eval "$2" >"$1":**仅 stdout 落盘**,stderr 仍打到终端 5. 成功:终端无 note,删除临时日志 6. 失败:LogBishengCompileFailure 读取日志全文,经 MACHINE_LOGE(COMPILE_CCEC_FAILED) 回显 > 链接路径(LinkObject)仍使用 RunLdViaSecureTempScript 临时脚本,与 bisheng 编译无关。 ### 3.4 脚本部署 | 场景 | 机制 | |------|------| | wheel / 正式安装 | 根 CMakeLists.txt install 到 lib/scripts/run_to_log.sh | | UT 构建 | framework/tests/cmake/func.cmake PRE_BUILD 软链到 output/lib/scripts/ | ## 4. 代码改动 **Commit 1** fix(machine): Fix bisheng warnning log - 新增 framework/src/machine/compile/scripts/run_to_log.sh - aicore_compiler.cpp:新增 RunBishengQuiet、GetRunToLogScriptPath、QuoteShellArg、LogBishengCompileFailure - CompileCoreMachine 末尾由 std::system(ccecCmd) 改为 RunBishengQuiet - 根 CMakeLists.txt:install run_to_log.sh - 新增 test_aicore_compiler.cpp UT **Commit 2** fix(machine): Add ut - 移除 RunBishengViaTempScript 临时脚本兜底,统一走固定 run_to_log.sh - func.cmake UT scripts 软链列表补充 run_to_log.sh,修复 UT 构建时 lib/scripts/ 被清空导致脚本缺失 - 补充 / 调整 RunBishengQuiet` 相关 UT 用例 See merge request: cann/pypto!5391 | 2 个月前 |