已开启
【Documentation|文档反馈】06 自定义 matmul 算子章节 qmm_custom 编译必然失败:CMakeLists 采集 TORCH_NPU_PATH 被 stdout 噪声污染导致 flags.make 语法错误 + qmm_custom.asc 使用 CANN 8.5.0 已不存在的 aclprof Range API #690
Glenn创建于  11 天前
Glenn
Glenn
11 天前 创建

一、问题文档/代码位置
tutorials/llm_inference/qwen3_8b/06_custom_matmul_operator_development_and_integration_with_qwen3_8b.ipynb(第4章 编译自定义算子 code cell)
tutorials/llm_inference/qwen3_8b/src/op_custom/qmm_custom/CMakeLists.txt(第16-22行)
tutorials/llm_inference/qwen3_8b/src/op_custom/qmm_custom/qmm_custom.asc(第232/233/248/254行)
环境:Notebook Lab 官方镜像,CANN 8.5.0 aarch64,torch_npu,CMake 4.2。

二、存在的问题
问题1:CMakeLists.txt 用 execute_process 取 torch_npu 路径时未过滤子进程 stdout 噪声,生成的 flags.make 含换行,make 直接报语法错误。
CMakeLists.txt 第16-20行:
execute_process(COMMAND ${Python3_EXECUTABLE} -c "import os, torch_npu; print(os.path.dirname(torch_npu.file))" OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE TORCH_NPU_PATH)
实测该命令 stdout 为两行:第一行是真实路径,进程退出时又向 stdout 打印了 "path string is NULLpath string is NULL"(结无行,OUTPUT_STRIP_TRAILING_WHITESPACE 去不掉中间的换行)。于是 TORCH_NPU_PATH 变成行字符串,生成的 build/CMakeFiles/ascendc_ops.dir/flags.make 第7行 ASC_INCLUDES 被截断,第8行变成 path string is NULLpath string is NULL/include ...,make :
CMakeFiles/ascendc_ops.dir/flags.make:8: *** missing separator. Stop.
make[1]: *** [CMakeFiles/Makefile2:86: CMakeFiles/ascendc_ops.dir/all] Error 2
随后 notebook 加载算子报 OSError: libascendc_ops.so: cannot open shared object file。
这是教程 CMakeLists 的健壮性缺陷,与学员填写 kernel 代码关,在该镜像上必现。

问题2(更关键,且是问题1修复后才暴露的新缺陷):qmm_custom.asc 使用了 CANN 8.5.0 acl_prof.h 中已不存在的 3 个 profiling Range API,导致 5 个编译错误
qmm_custom.asc:232:23: error: use of undeclared identifier 'aclprofStr2Id'
qmm_custom.asc:233:23: error: use of undeclared identifier 'aclprofStr2Id'
qmm_custom.asc:248:3: error: use of undeclared identifier 'aclprofRangePushEx'
qmm_custom.asc:248:22: error: cannot initialize a parameter of type 'uint32_t'
qmm_custom.asc:254:3: error: use of undeclared identifier 'aclprofRangePop'
/usr/local/Ascend/cann-8.5.0/aarch64-linux/include/acl/acl_prof.h 中仅提供 aclprofPush/aclprofPop 等接口。教程源码与镜像内 CANN 版本文件不匹配,学员无法通过"填空"绕过。

三、复现步骤

  1. Notebook Lab 中按 06 notebook 依次执行到"编译自定义算子"cell;
    1. 观察 flags.make:8 missing separator 报错;
      1. 手动修复问题1(CMakeLists.txt 第20后加 string(REGEX REPLACE 取首行) )后重新 cmake && make;

        1. 此时出现问题2 的 5 个 aclprof 编译错误。
      2. 四、临时规避(仅本地验证用,不作为 PR)

      3. (a)CMakeLists.txt 在 execute_process 之后增加 string(REGEX REPLACE 只取首行) 清洗 TORCH_NPU_PATH;

      4. (b)在 qmm_custom.asc 中为 aclprofStr2Id / aclprofRangePushEx / aclprofRangePop 增加空实现 shim。

      5. 两步之后编译成生成 libascendc_ops.so(639KB),算子可加载,06 后续 profiling 推理可继续执行。

    2. 五、建议修复
    3. (a)CMakeLists.txt:execute_process 增加 ERROR_QUIET,并对输出做 string(REGEX REPLACE) 只取路径首行,或改由环境变量/find_package 传入 torch_npu 路径;
    4. (b)qmm_custom.asc:改用 CANN 8.5.0 现有的 aclprofPush/aclprofPop,或按 CANN 版本条件编译,并在文档中标注适配的 CANN 版本。
  2. 六、与 Issue 209 的区别
  3. Issue 209 只统记录了"06 编译报错 + requirements 依赖冲突",未定位到 flags.make 是由 TORCH_NPU_PATH 被子进程 stdout 噪声污染引起,也完全没有覆盖问题2(aclprof Range API 在 CANN 8.5.0 缺失)。问题2 是修复编译脚本后才暴露的独立源码缺陷,属于新的、可独立修复的缺陷。issue_06_flagsmake_aclprof.png
likedislike
Glenn
Glenn
11 天前 评论:

/assign @Glenn_118

likedislike
CANN-robotCANN-robot成员
11 天前 将 Glenn_118 设为负责人
ink_polymerink_polymer成员
11 天前 添加了label:good-first-issue