已合并
fix(qbmm): 迁移公共校验安全整改到 9.1.0 #7027
fix(qbmm): 迁移公共校验安全整改到 9.1.0 #7027
已合并
zhaoyingchao2创建于 7月4日
7月4日

描述

参考已合入 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 命名空间,移除文件内重复定义,降低维护成本。
  • isA8W4FloatisA8W4IntisMxisA8W4MsdIsMicroScalingIsFormatNZ 等公共判断函数补充 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 "<<<<<<<|=======|>>>>>>>",未发现残留冲突标记。
  • 已检查新公共头文件与 PR #6889 中最终版本的 Git blob 一致:1eeffc4d1112e371c8d4efed327dd0e91bbe0fb7
  • 未执行完整编译/LLT:当前本地环境未配置 CANN 编译链路和对应运行环境。

文档更新

不涉及文档更新。

类型标签

AI/Agent生成声明

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 zhaoyingchao2 的贡献)
Zzhaoyingchao2
7月4日 创建了 pull request,commit 07ea7818
Zzhaoyingchao2
7月4日 关联了issue:[Bug-Report|缺陷反馈]: 9.1.0 分支 QBMM 公共校验逻辑缺少 nullptr 防护
CANN-robotCANN-robot成员
7月4日 添加了label:stat/needs-squash
CANN-robotCANN-robot成员
7月4日 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
7月4日 评论:

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 /approve or /lgtm
  • Commenting /approve implies 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. 👍

likedislike
atomgit-bot
atomgit-bot
7月4日 评论:

变更摘要

此 PR 将已合入 master 分支的 PR #6889 中关于 QBMM V4 公共校验逻辑拆分与安全性增强的改动迁移到 9.1.0 分支。核心变更是新增 quant_matmul_v4_common.h 公共头文件,将 aclnn_quant_matmul_v4.cpp 中的常量、tuple 类型别名以及 isA8W4FloatisA8W4IntisMxisA8W4MsdIsMicroScalingIsTCGSelectNzK0ValueIsAlignedIsFormatNZ 等公共判断函数提取到独立的 quant_matmul_v4 命名空间中,消除文件内重复定义,降低维护成本,并对各判断函数补充了 nullptr 防护。同时修复了 AdaptiveSlidingWindowMXBasicAPITiling::GetApiLevel 的参数命名问题。由于 9.1.0 分支缺少 master 的宏头文件路径,部分 kernel 宏前移逻辑未被同步。

主要改动

  • 新增 quant_matmul_v4_common.h 公共头文件:将 V4 参数校验中的公共常量(如 MX_SCALE_LAST_DIM_INDEXINDEX_X1_IN_MANDTORY_TUPLE 等)、tuple 类型别名(TupleTensorTupleOptionalTupleInputTupleQuantTupleAttr)以及场景判断与校验函数统一收敛到 quant_matmul_v4 命名空间中,并对 isA8W4FloatisA8W4IntisMxisA8W4MsdIsMicroScalingIsFormatNZ 等函数增加了入参 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,消除无副作用的参数命名不规范问题。

likedislike
不准确?
atomgit-bot
atomgit-bot
7月4日 评论:

代码审查

经过对全部 3 个变更文件的逐行审查(包括公共头文件中每个新增常量/函数/类型别名的逐项核实、cpp 文件中每一处删除/修改跨文件的引用链追踪、tiling 文件的参数命名变更),此 PR 中没有发现任何正确性、安全性、可靠性或回归性缺陷

变更总结:

  • aclnn_quant_matmul_v4.cpp:移除文件内重复的 ~170 行常量/类型别名/工具函数定义,改为引入 quant_matmul_v4_common.husing 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 无问题

⚠️ 已识别出整体风险,但无法提取行内评论,请参考整体评估。

likedislike
不准确?
Zzhaoyingchao2
7月4日 update merge request[project id: 7665709, iid: 7027, commit_id: 801d567f1712ee1efcd652a9005c51b5dadf49c6] virtual merging success
Zzhaoyingchao2
7月4日 强制推送  1 个提交:f18a2f88-add nullptr check
Zzhaoyingchao2
7月4日 update merge request[project id: 7665709, iid: 7027, commit_id: a0b3629c317b8db0212f80765ba402c5e6f592a5] virtual merging success
zhaoyingchao2
7月4日 评论:

compile

likedislike
Zzhaoyingchao2
7月4日 update merge request[project id: 7665709, iid: 7027, commit_id: 5fa68c20cfb11a3b50a90f45894c8c2e6669cb1a] virtual merging success
zhaoyingchao2
7月4日 评论:

/ai review

likedislike
CANN-robotCANN-robot成员
7月4日 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
7月4日 评论:

流水线任务触发成功
任务链接 [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 >>>>>
likedislike
CANN-robot
CANN-robot成员
7月4日 评论:

流水线任务触发成功
任务链接 [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执行结束

likedislike
CANN-robotCANN-robot成员
7月4日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
7月4日 添加了label:ci-pipeline-failed
atomgit-bot
atomgit-bot
7月4日 评论:

代码审查

审查总结

文件 审查结果
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

⛔ 需要修改

likedislike
不准确?
atomgit-bot
atomgit-bot7月4日进行代码检视2
matmul/quant_batch_matmul_v3/op_kernel/arch35/quant_batch_matmul_v3_apt_tiling_key.h
已过期
@@ -50,3 +58,3 @@
5058 
5159#if defined(__CCE_AICORE__) && defined(ORIG_DTYPE_X1) && defined(ORIG_DTYPE_X2) && defined(ORIG_DTYPE_SCALE) && \
52- defined(FORMAT_X2) && \
60+ defined(DT_FLOAT8_E4M3FN) && defined(DT_FLOAT8_E5M2) && defined(DT_FLOAT4_E2M1) && defined(DT_FLOAT8_E8M0) \
atomgit-bot
atomgit-bot7月4日评论:

🔴 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_X1ORIG_DTYPE_X2ORIG_DTYPE_SCALE 以及 DT_FLOAT8_E4M3FNDT_FLOAT8_E5M2DT_FLOAT4_E2M1DT_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) && \
应用建议
likedislike
不准确?
System
系统消息系统
7月6日 评论:

changed this line on 35256957 view diff detail

Zzhaoyingchao2
7月6日 update merge request[project id: 7665709, iid: 7027, commit_id: 7d7a36b705f1d1a2f07e9b34bf6ae0575d61d6c0] virtual merging success
Zzhaoyingchao2
7月6日 强制推送  1 个提交:35256957-add nullptr check
Zzhaoyingchao2
7月6日 update merge request[project id: 7665709, iid: 7027, commit_id: 0f0d769ba3fdbfdd65ec4a646ea3dbb60b7c8998] virtual merging success
zhaoyingchao2
7月6日 评论:

compile

likedislike
Zzhaoyingchao2
7月6日 update merge request[project id: 7665709, iid: 7027, commit_id: 9a30d90d4330327e70ae6c768603ee82fdf204a9] virtual merging success
CANN-robotCANN-robot成员
7月6日 删除了label:ci-pipeline-failed
CANN-robotCANN-robot成员
7月6日 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
7月6日 评论:

流水线任务触发成功
任务链接 [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执行结束

likedislike
CANN-robot
CANN-robot成员
7月6日 评论:

流水线任务触发成功
任务链接 [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执行结束

likedislike
CANN-robotCANN-robot成员
7月6日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
7月6日 添加了label:ci-pipeline-passed
liulun0308成员
7月6日 评论:

/approve

likedislike
yangyang016成员
7月6日 评论:

/lgtm

likedislike
wangyongguang成员
7月6日 评论:

/approve

likedislike
CANN-robotCANN-robot成员
7月6日 添加了label:lgtmapproved
CANN-robotCANN-robot成员
7月6日 解决了最后一个问题
CANN-robotCANN-robot成员
7月6日 关闭了关联的issue
CANN-robotCANN-robot成员
7月6日 合入了pull request
CANN-robot
CANN-robot成员
7月6日 评论:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike
CANN-robot
CANN-robot成员
7月6日 评论:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike
CANN-robot
CANN-robot成员
7月6日 评论:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike