Pull Request has been successfully merged by CANN-robot.
(Thank you for renshuojian's contribution.)变更摘要
该 PR 以「质量加固」为目标,围绕 quant/ascend_requant 的 AscendRequant 算子补齐 Host 侧 tiling/infershape 的输入校验与整型溢出防护,并调整 Kernel 侧的搬运与尾块处理逻辑。核心是新增 ValidateBroadcastShape 与 ValidateTotalElements 两个校验函数(声明于 ascend_requant_tiling_arch35.h),在 ascend_requant_infershape.cpp 与 tiling 流程中拒绝广播放大、输出 shape 不等于 x、rank 越界以及元素总数/步长溢出等非法输入,同时把分块与步长计算改用 __int128 累计并透传错误码。
主要改动
- 广播规则强制校验:新增
ValidateBroadcastShape,要求req_scale每维为 1 或等于x对应维(广播结果须等于x的 shape),且每个输出 shape 逐维等于x,违反时返回kErrShapeMismatch;InferShape4AscendRequant中同步加了xrank 需在[1,8]、req_scalerank 需在[0,8]的检查及逐维广播检查(UNKNOWN_DIM时跳过、留待 tiling 复查)。 - 整型溢出受控拒绝:新增错误码
kErrShapeOverflow与ValidateTotalElements,用__int128计算全部维度乘积并在超出INT64_MAX时拒绝;FindSplitAxis、MultiCoreSplit、ComputeBranchTiling、PrecomputeStrides的累乘改为__int128,PrecomputeStrides由void改为返回bool,调用处检查返回值并返回ge::GRAPH_FAILED。 - UB 缓冲区尾块余量预留:引入常量
TAIL_LOAD_MARGIN_BYTES = 512,在FindSplitAxis与ComputeBranchTiling计算单缓冲可容纳元素数时先扣除该余量,以适配 VF 整向量寄存器宽度加载的越界读范围。 - Kernel 搬运与存出掩码调整:
ascend_requant_kernel.h中说明 GM→UB 搬运走 NDDMA 元素粒度以支持 stride-0 广播;RequantVF新增storeMask与kCopyOutAlignElems,将最后一个 repeat 的存储元素数按 32 字节拷出对齐粒度向上取整,保证DataCopyPad读到的尾部字节均已写入。 - 回归用例补充:
test_ascend_requant_tiling.cpp新增三个 tiling 失败用例,分别覆盖广播放大(x=[1,4]、req_scale=[3,1])、输出 shape 与x不一致、以及总元素数超过int64范围的 shape 被拒绝。
🧩 本次 Review 已使用自定义 Skill:


代码审查
审查结论
逐文件审查确认
| 变更文件 | 结论 |
|---|---|
op_host/arch35/ascend_requant_tiling_arch35.cpp |
有 2 项 P3(ComputeBranchTiling 的 computeStrides 越界检查缺失、512B 余量魔法数字与 kernel 侧隐式契约)。其余加固(ValidateBroadcastShape、ValidateTotalElements、FindSplitAxis/MultiCoreSplit 的 __int128 与返回值校验、PrecomputeStrides 失败上抛)逐条核算过:ValidateTotalElements 先把总元素限制在 int64 内,使得 kernel 侧 innerCount/CalcInputOffset 的 int64 累加不会溢出,检查位置与边界判断正确,无问题 |
op_host/arch35/ascend_requant_tiling_arch35.h |
无问题(kErrShapeOverflow = -6 与两个新声明一致,无历史错误码顺序改动) |
op_host/ascend_requant_infershape.cpp |
有 1 项 P3(新增拒绝逻辑无 UT)。秩上限与 tiling 侧 ValidateDimensions 一致,“未知秩/未知维延后到 tiling”分支逻辑正确,无功能缺陷 |
op_kernel/arch35/ascend_requant_kernel.h |
无问题。已逐项验算:count ≤ perBufElems、scale 尾块整宽读量 = 63×8 = 504B ≤ 512B 余量、storeElems 尾块按 32B 对齐后 i*VL + aligned ≥ ceil(count/32)*32(VL=64 为 32 的整数倍,cap 到 oneRepeatSize 后仍覆盖),中间 repeat 的 storeMask 与原 mask 等价,扩展车道越界写落在外层 512B 余量内且被 DataCopyPad 丢弃 |
tests/ut/op_host/arch35/test_ascend_requant_tiling.cpp |
有 1 项 P2(tiling_output_shape_mismatch_rejected 被 CheckBroadcastShape 提前拒绝,未覆盖新增的输出 shape 校验分支)。另外两项新用例判定链路核对无误 |
问题统计
- P0:0
- P1:0
- P2:1
- P3:3
总体风险判断
本次改动方向正确且实现质量较高:三处 int64 累乘均已改用 __int128,越界/溢出分支的返回值都在调用方被检查,kernel 尾块读写与新预留余量在 256B 向量宽度下自洽验算通过,未发现新增的越界、溢出或功能回归。风险集中在验证充分性:真正阻断“输出 shape ≠ x 越界写”这一安全修复的用例实际未生效,以及新增的 Host 端拒绝路径没有测试保护;另有一处跨端魔法数字与重复实现漂移的维护性隐患。建议合入前优先补齐 P2 的用例修正。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 0 |
| 🟡 建议 | 1 |
💬 仅评论
🧩 本次 Review 已使用自定义 Skill:


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.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| quant | ✅ 陈展熹, 上官秦南 (2/2) | ✅ 陈展熹 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
rsj007, thanks for your pull request. All authors of the commits have signed the CLA. 👍


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


您好,pr合入已准备就绪,请尽快联系committer进行检视,谢谢!
@u010470851 @sxb154714 @wangzitao_leo @liujie12345678 @yourealize @chaotang233 @chenfeng61 @LinPX @liuyang_806


描述
新增 ValidateBroadcastShape 与 ValidateTotalElements 两个校验函数,在 infershape 与 tiling 流程中拒绝广播放大、输出 shape 不等于 x、rank 越界以及元素总数/步长溢出等非法输入,同时把分块与步长计算改用 __int128 累计并透传错误码。
关联的Issue
https://gitcode.com/cann/ops-nn/issues/8164
测试
obp、david冒烟
文档更新
不涉及
类型标签
AI/Agent生成声明