Pull Request已成功合入, 合并人@CANN-robot
(感谢 zhaoyingchao2 的贡献)Thanks for your pull-request.
The full list of commands accepted by me can be found at here。
You can get sig-info at here
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| */*/op_api/*.h | ✅ 王永光, 杨阳 (2/2) | ✅ 王永光 (1/1) |
| ** | ✅ gcw_kUomxQ2l, 杨阳 (2/2) | ✅ gcw_kUomxQ2l (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
zhaoyingchao2, thanks for your pull request. All authors of the commits have signed the CLA. 👍


变更摘要
此 PR 将已合入 master 分支的 PR #6889 中关于 QBMM V4 公共校验逻辑拆分与安全性增强的改动迁移到 9.1.0 分支。核心变更是新增 quant_matmul_v4_common.h 公共头文件,将 aclnn_quant_matmul_v4.cpp 中的常量、tuple 类型别名以及 isA8W4Float、isA8W4Int、isMx、isA8W4Msd、IsMicroScaling、IsTCG、SelectNzK0Value、IsAligned、IsFormatNZ 等公共判断函数提取到独立的 quant_matmul_v4 命名空间中,消除文件内重复定义,降低维护成本,并对各判断函数补充了 nullptr 防护。同时修复了 AdaptiveSlidingWindowMXBasicAPITiling::GetApiLevel 的参数命名问题。由于 9.1.0 分支缺少 master 的宏头文件路径,部分 kernel 宏前移逻辑未被同步。
主要改动
-
新增
quant_matmul_v4_common.h公共头文件:将 V4 参数校验中的公共常量(如MX_SCALE_LAST_DIM_INDEX、INDEX_X1_IN_MANDTORY_TUPLE等)、tuple 类型别名(TupleTensor、TupleOptional、TupleInput、TupleQuant、TupleAttr)以及场景判断与校验函数统一收敛到quant_matmul_v4命名空间中,并对isA8W4Float、isA8W4Int、isMx、isA8W4Msd、IsMicroScaling、IsFormatNZ等函数增加了入参 nullptr 防护,避免可选 tensor 被直接解引用。 -
aclnn_quant_matmul_v4.cpp引入公共头文件并移除重复定义:删除了约 170 行已被迁移到公共头文件的常量、类型别名和内联函数定义,改为#include "quant_matmul_v4_common.h"并添加using namespace quant_matmul_v4;,复用统一命名空间下的公共逻辑。 -
修复
GetApiLevel参数命名:AdaptiveSlidingWindowMXBasicAPITiling::GetApiLevel的参数从匿名的NpuArch改为命名的NpuArch npuArch,消除无副作用的参数命名不规范问题。


代码审查
经过对全部 3 个变更文件的逐行审查(包括公共头文件中每个新增常量/函数/类型别名的逐项核实、cpp 文件中每一处删除/修改跨文件的引用链追踪、tiling 文件的参数命名变更),此 PR 中没有发现任何正确性、安全性、可靠性或回归性缺陷。
变更总结:
aclnn_quant_matmul_v4.cpp:移除文件内重复的 ~170 行常量/类型别名/工具函数定义,改为引入quant_matmul_v4_common.h并using namespace quant_matmul_v4;,所有调用方通过命名空间解析到公共头文件中的同一份定义,无遗漏、无冲突。quant_matmul_v4_common.h(新增 214 行):沉淀公共常量、tuple 类型、isA8W4Float/isA8W4Int/isMx/isA8W4Msd/IsMicroScaling/IsTCG/SelectNzK0Value/IsAligned/IsFormatNZ等函数,并对其中 6 个原本缺乏 nullptr 防护的函数增加了前置空指针检查——不会改变任何有效输入下的行为,属纯安全性增强。adaptive_sliding_window_mx_basic_api_tiling.cpp:仅将GetApiLevel(NpuArch)的匿名参数改为GetApiLevel(NpuArch npuArch),与函数声明保持一致,无行为变化。
审查结论:无问题可报告。
| 文件 | 审查结果 |
|---|---|
matmul/quant_batch_matmul_v3/op_api/aclnn_quant_matmul_v4.cpp |
无问题 |
matmul/quant_batch_matmul_v3/op_api/quant_matmul_v4_common.h |
无问题 |
matmul/quant_batch_matmul_v3/op_host/op_tiling/arch35/adaptive_sliding_window_mx_basic_api_tiling.cpp |
无问题 |
⚠️ 已识别出整体风险,但无法提取行内评论,请参考整体评估。


compile


/ai review


流水线任务触发成功
任务链接 [8efaf529ed004711a7c21e69c7857878][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| Compile_Ascend_X86_mobile_station | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM | ❌ FAILED | >>>>> | |
| Compile_Ascend_single | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_experimental | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Pre | ✅ SUCCESS | >>>>> | |
| pre_comment | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86 | ❌ FAILED | >>>>> | |
| Compile_X86_monitor_910b | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910c | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_harmony-infer-chs-nn | ✅ SUCCESS | >>>>> |


流水线任务触发成功
任务链接 [9b8f663f34154295b8cadf5447994fdf][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| codecheck | ✅ SUCCESS | >>>>> | |
| antipoison | ✅ SUCCESS | >>>>> | |
| codecheck_checkpr | ✅ SUCCESS | ||
| StaticCheck_codespell_check | ✅ SUCCESS | ||
| StaticCheck_link_validity_check | ✅ SUCCESS | ||
| StaticCheck_resource_existence_check | ✅ SUCCESS | ||
| StaticCheck_tag_closed_check | ✅ SUCCESS | ||
| StaticCheck_markdownlint | ✅ SUCCESS | ||
| codecheck_style | ✅ SUCCESS | >>>>> | |
| codecheck_precommit | ⚠️ WARNING | >>>>> | >>>>> |
| SCA | ✅ SUCCESS | >>>>> |
[2026-07-04 16:00:15] CI执行结束


代码审查
审查总结
| 文件 | 审查结果 |
|---|---|
matmul/quant_batch_matmul_v3/op_api/quant_matmul_v4_common.h |
无问题(新增公共头文件,nullptr 防护正确,逻辑迁移完整) |
matmul/quant_batch_matmul_v3/op_api/aclnn_quant_matmul_v4.cpp |
无问题(删除重复定义、引入公共头文件、仅尾随空格清理,语义无变化) |
matmul/quant_batch_matmul_v3/op_host/op_tiling/arch35/adaptive_sliding_window_mx_basic_api_tiling.cpp |
无问题(参数命名与声明一致,无副作用) |
matmul/quant_batch_matmul_v3/op_kernel/arch35/quant_batch_matmul_v3_apt_tiling_key.h |
1 个 P0 问题:预处理器 #if 条件缺少 && 运算符 |
发现统计:P0 × 1,P1 × 0,P2 × 0,P3 × 0。
总体风险判断:此次变更存在一个编译阻断级缺陷——tiling key 头文件中 defined(FORMAT_X2) && 替换为多个 defined(DT_*) 检查时遗漏末尾 &&,导致 MX 模板场景下预处理器语法错误、编译失败。其余迁移工作(公共头文件拆分、nullptr 防护补充、参数命名对齐、尾随空格清理)均正确无误。建议在合入前修复该 && 缺失问题。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 1 |
| 🟡 建议 | 0 |
⛔ 需要修改


🔴 Critical
在 quant_batch_matmul_v3_apt_tiling_key.h 第 60 行,diff 将原来的 defined(FORMAT_X2) && \ 替换为四个 defined(DT_*) 检查,但遗漏了末尾的 && 运算符。
经过行续接(backslash-newline 移除)后,第 59–61 行合并为一条逻辑行:
defined(DT_FLOAT8_E8M0) 求值为 0 或 1 后,紧接着 (ORIG_DTYPE_X1 == ... 表达式,两者之间缺少运算符,这在 C 预处理器 #if 表达式中是语法错误。
触发条件:当 __CCE_AICORE__、ORIG_DTYPE_X1、ORIG_DTYPE_X2、ORIG_DTYPE_SCALE 以及 DT_FLOAT8_E4M3FN、DT_FLOAT8_E5M2、DT_FLOAT4_E2M1、DT_FLOAT8_E8M0 等宏全部被定义时,编译器处理此 #if 条件将直接报预处理器语法错误,导致编译失败。
建议:在第 60 行末尾 DT_FLOAT8_E8M0) 之后、\ 之前补上 &&,使其与下一行的 (ORIG_DTYPE_X1 == ...) 表达式正确连接。
| 60
| - defined(DT_FLOAT8_E4M3FN) && defined(DT_FLOAT8_E5M2) && defined(DT_FLOAT4_E2M1) && defined(DT_FLOAT8_E8M0) \ |
|
60 | + defined(DT_FLOAT8_E4M3FN) && defined(DT_FLOAT8_E5M2) && defined(DT_FLOAT4_E2M1) && defined(DT_FLOAT8_E8M0) && \ |


compile


流水线任务触发成功
任务链接 [f1a71bddbbb04e9c8dc4c3e946ce45b3][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| Compile_Ascend_X86_mobile_station | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_single | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_experimental | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Pre | ✅ SUCCESS | >>>>> | |
| pre_comment | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910b | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910c | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_harmony-infer-chs-nn | ✅ SUCCESS | >>>>> | |
| UT_Test_ophost | ✅ SUCCESS | ||
| UT_Test_opapi | ✅ SUCCESS | ||
| UT_Test_kernel | ✅ SUCCESS | ||
| UT_Test_opgraph | ✅ SUCCESS | ||
| PreSmoke_A900 | ✅ SUCCESS | >>>>> | |
| PreSmoke_ATK_Test_A2 | ✅ SUCCESS | >>>>> |
[2026-07-06 09:35:46] CI执行结束


流水线任务触发成功
任务链接 [318cb37752674111b0f4cccdb86b96b6][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| codecheck | ✅ SUCCESS | >>>>> | |
| antipoison | ✅ SUCCESS | >>>>> | |
| codecheck_checkpr | ✅ SUCCESS | ||
| StaticCheck_codespell_check | ✅ SUCCESS | ||
| StaticCheck_link_validity_check | ✅ SUCCESS | ||
| StaticCheck_resource_existence_check | ✅ SUCCESS | ||
| StaticCheck_tag_closed_check | ✅ SUCCESS | ||
| StaticCheck_markdownlint | ✅ SUCCESS | ||
| codecheck_style | ✅ SUCCESS | >>>>> | |
| codecheck_precommit | ⚠️ WARNING | >>>>> | >>>>> |
| SCA | ✅ SUCCESS | >>>>> |
[2026-07-06 09:36:21] CI执行结束


/approve


/lgtm


/approve


Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


描述
参考已合入 master 的 PR #6889(【qbmm】公共校验逻辑拆分与安全性增强),将 QBMM V4 公共校验与安全防护相关改动迁移到
9.1.0分支:matmul/quant_batch_matmul_v3/op_api/quant_matmul_v4_common.h,沉淀 V4 参数校验中的公共常量、tuple 类型、A8W4/MX/TCG 场景判断、NZ K0 选择、对齐检查和 format 判断等公共逻辑。aclnn_quant_matmul_v4.cpp引入公共头文件并复用quant_matmul_v4命名空间,移除文件内重复定义,降低维护成本。isA8W4Float、isA8W4Int、isMx、isA8W4Msd、IsMicroScaling、IsFormatNZ等公共判断函数补充 nullptr 防护,避免可选 tensor 在场景识别中被直接解引用。AdaptiveSlidingWindowMXBasicAPITiling::GetApiLevel的参数命名整改。迁移说明:PR #6889 中部分 kernel 宏前移逻辑依赖 master 分支已有的宏头文件路径,
9.1.0分支当前不存在该头文件。因此本次迁移保留9.1.0现有平台宏路径,仅同步公共校验拆分、nullptr 防护和无副作用的参数命名整改。关联的Issue
关联Issue #3839:https://gitcode.com/cann/ops-nn/issues/3839
测试
git diff --check upstream/9.1.0..HEAD,无空白错误。rg -n "<<<<<<<|=======|>>>>>>>",未发现残留冲突标记。1eeffc4d1112e371c8d4efed327dd0e91bbe0fb7。文档更新
不涉及文档更新。
类型标签
AI/Agent生成声明