已合并
resize类算子tiling侧增加单轴是否超INT32_MAX的判断 #1133
wkx12138创建于 7月16日
resize类算子tiling侧增加单轴是否超INT32_MAX的判断 #1133
已合并
wkx12138创建于 7月16日
wkx12138成员
7月16日

描述

resize类算子tiling侧新增输入输出H、W轴是否超过INT32_MAX的判断,解决shape在(INT32_MAX, UINT32_MAX]范围内,输入输出H、W轴中有大于INT32_MAX的用例在tiling判断时被误判可走int32分支导致kernel中int32溢出为负。
resize_bicubic_v2算子的README.MD补充align_corners,scales属性说明

关联的Issue

https://gitcode.com/cann/ops-cv/issues/618

测试

david冒烟、obp冒烟、线上st均已跑

文档更新

更新了resize_bicubic_v2算子的README.md文件。

类型标签

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 wkx12138 的贡献)
Wwkx12138成员
7月16日 创建了 pull request,commit a427f8d9
atomgit-bot
atomgit-bot
7月16日 评论:

变更摘要

此 PR 针对 resize 类算子(包括 bicubic、bilinear、linear、nearest_neighbor、upsample_nearest3d 及其梯度算子)在 tiling 侧增加了对单个空间维度是否超过 INT32_MAX 的判断。此前 isInt32/useIdx32 等索引类型标志仅依据输入输出的总元素数是否小于 UINT32_MAX 来决定,忽略了 [INT32_MAX, UINT32_MAX] 区间内单轴维度可能超出有符号 int32 上限导致溢出为负、静默数据错误的隐患。修复后,当任意 HW 维度超过 INT32_MAX 时强制使用 int64 索引核。同时修复了 ResizeBicubicV2 NHWC 格式下仅当 H 和 W 同时变化才走 NHWC 布局核的缺陷(&& 改为 ||),并在 kernel 入口函数中补齐了 return 语句防止调度模式间的 fall-through。

主要改动

  • 单轴 INT32_MAX 溢出判断: 在所有 resize 算子的 tiling 逻辑(DoTilingKeyPostProcess、IsUseIdx32、MatchTilingStrategyAndSetTilingKey、SetSimtTilingKey、LinearCompute、LinearComputeGrad、SetIndexType、GetAndCheckShapes 等)中新增对 lenSrcH_、lenSrcW_、lenDesH_、lenDesW_(或对应的 L/D 维)是否超过 INT32_MAX 的检查,超限则将 isInt32_/useIdx32/isUint32 置为 0 以使用 int64 索引核,消除有符号 int32 溢出隐患。
  • BicubicV2 NHWC 布局核匹配修复: resize_bicubic_v2_tiling_arch35.cpp 中 CheckParams 的 NHWC 条件由 (lenDesH_ != lenSrcH_ && lenDesW_ != lenSrcW_) 改为 (lenDesH_ != lenSrcH_ || lenDesW_ != lenSrcW_),确保 NHWC 格式下任一空间维变化即走 NHWC 布局核,而非错误地使用 NCHW 布局核处理 channel-last 数据。
  • BicubicV2 kernel 入口 fall-through 修复: resize_bicubic_v2_apt.cpp 中 schId == 5/6 的分支以及 NCHW/NHWC 分支均补齐 return,防止不同调度模式或布局分支之间的意外 fall-through。
  • 新增单测用例: test_resize_bicubic_v2_tiling.cpp 新增三个测试用例,分别验证 NHWC 单维 H 变化、单维 W 变化时 isNchw=0,以及 lenSrcH 超过 INT32_MAX 时 isInt32=0。
  • 伴随格式化清理: 多个文件的代码格式统一调整(花括号换行、长错误消息换行、多余分号去除等),无业务逻辑影响。
likedislike
不准确?
atomgit-bot
atomgit-bot
7月16日 评论:

代码审查

I've completed the thorough review of all 12 changed files. Let me summarize my findings.


审查总结

审查结果

优先级 数量
P0 1
P1 0
P2 0
P3 0

各文件审查确认

  1. image/resize_bicubic_v2/README.md — 文档变更,仅新增 align_corners 和 scales 属性说明,无问题。

  2. image/resize_bicubic_v2/op_host/arch35/resize_bicubic_v2_tiling_arch35.cpp — 核心修复:&& → || 修复 NHWC 单维变化 bug;在 DoTilingKeyPostProcess() 中新增各轴 INT32_MAX 判断。逻辑正确,无问题。

  3. image/resize_bicubic_v2/op_kernel/resize_bicubic_v2_apt.cpp — 在 schId == MODE_5/MODE_6 分支和 NCHW/NHWC 分支末尾补充 return 语句,防止 fall-through 到错误模板实例化。修复正确,无问题。

  4. image/resize_bicubic_v2/tests/ut/op_host/arch35/test_resize_bicubic_v2_tiling.cpp — 新增 3 个回归测试用例(Test 07/08/09),覆盖 NHWC 单维变化和 INT32_MAX 溢出场景。测试设计合理,无问题。

  5. image/resize_bicubic_v2_grad/op_host/arch35/resize_bicubic_v2_grad_base_tiling_arch35.cpp — ⚠️ P0:IsUseIdx32() 缺失闭合花括号 } 导致编译失败。新增 lenDstH/lenDstW 到 INT32_MAX 检查的改动本身正确,但格式化重构过程中误删了闭合花括号。

  6. image/resize_bilinear_v2/op_host/arch35/resize_bilinear_v2_tiling_arch35.cpp — MatchTilingStrategyAndSetTilingKey() 中 useIdx32 新增各轴 INT32_MAX 判断。逻辑正确,无问题。

  7. image/resize_bilinear_v2_grad/op_host/arch35/resize_bilinear_v2_grad_tiling_arch35.cpp — SetSimtTilingKey() 中原内联乘法改为先赋值 int64_t 局部变量再比较,新增各轴 INT32_MAX 判断。所有操作数为 int64_t,乘法安全,无问题。

  8. image/resize_linear/op_host/arch35/resize_linear_tiling_arch35.cpp — LinearCompute() 中新增 lenSrcL_、lenDesL_ 超 INT32_MAX 判断。无问题。

  9. image/resize_linear_grad/op_host/arch35/resize_linear_grad_tiling_arch35.cpp — LinearComputeGrad() 中新增 lenSrcLOrUb_、lenDesL_ 超 INT32_MAX 判断。变量均为 int64_t,无问题。

  10. image/resize_nearest_neighbor_v2/op_host/arch35/resize_nearest_neighbor_v2_tiling_base.cpp — MatchTilingStrategyAndSetTilingKey() 中 idxUseInt32_ 新增各轴 INT32_MAX 判断。大量缩进/格式化调整均为纯风格变更,无逻辑问题。

  11. image/resize_nearest_neighbor_v2_grad/op_host/arch35/resize_nearest_neighbor_v2_grad_tiling_base.cpp — SetIndexType() 中 isIdx32 新增各轴 INT32_MAX 判断。缩进/格式化调整均为纯风格变更,无问题。

  12. image/upsample_nearest3d/op_host/upsample_nearest3d_tiling_arch35.cpp — GetAndCheckShapes() 中 isUint32 计算新增各轴 INT32_MAX 判断。所有维度均为 int64_t,无问题。

整体风险评估

高风险:由于 resize_bicubic_v2_grad_base_tiling_arch35.cpp 存在 P0 编译阻断缺陷(IsUseIdx32() 缺失闭合花括号),该 PR 当前无法通过编译,必须修复后才能合入。其余 11 个文件的改动均正确,逻辑修复(&& → ||、新增 INT32_MAX 轴判断、kernel 中 return 防 fall-through)均为必要且正确的改进。

类型 数量
🔴 阻塞 1
🟡 建议 0

⛔ 需要修改

likedislike
不准确?
CANN-robotCANN-robot成员
7月16日 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
7月16日 评论:

CLA Signature Pass

wkx12138, thanks for your pull request. All authors of the commits have signed the CLA. 👍

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

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
*/*/README.md ✅ 陈娇, 刘伟 (2/2) ✅ 陈娇 (1/1)
** ✅ 刘伟, gcw_kUomxQ2l, 陈娇 (3/2) ✅ gcw_kUomxQ2l, 陈娇 (2/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

wkx12138, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
CANN-robotCANN-robot成员
7月16日 将zhou-qilong,gitee-duhuiping,rxtfeng,loov1,zhangzijie,zl_hw,liu-wei,jiangtao_rts,gitcode-chenjiao,hanxiaolong,llimwang,zhouwenfang,gubaocheng,wuyao51511,gcw_kUomxQ2l,Andy-lb,caiwenwen设为评审人
CANN-robotCANN-robot成员
7月16日 将gitee-duhuiping,jiangtao_rts,gitcode-chenjiao,hanxiaolong,zhouwenfang,wuyao51511,gcw_kUomxQ2l,Andy-lb,caiwenwen设为审查人
atomgit-bot
atomgit-bot7月16日进行代码检视1
image/resize_bicubic_v2_grad/op_host/arch35/resize_bicubic_v2_grad_base_tiling_arch35.cpp
@@ -374,2 +389,2 @@
374- inputInfo_.lenSrcH <= INT32_MAX && inputInfo_.lenSrcW <= INT32_MAX;
375-}
389+ inputInfo_.lenSrcH <= INT32_MAX && inputInfo_.lenSrcW <= INT32_MAX && inputInfo_.lenDstH <= INT32_MAX &&
390+ inputInfo_.lenDstW <= INT32_MAX;
atomgit-bot
atomgit-bot7月16日评论:

🔴 Critical

diff 中 IsUseIdx32() 函数原有的闭合花括号 }(旧行375)被删除,新代码行390 return ... <= INT32_MAX; 之后没有恢复 }。导致后续的 Tiling4ResizeBicubicV2Grad、TilingPrepare4ResizeBicubicV2Grad 两个函数和 IMPL_OP_OPTILING 宏被错误地嵌入到 IsUseIdx32() 成员函数体内。

后果:

  1. 这些代码出现在 return 语句之后,形成不可达死代码;
  2. IMPL_OP_OPTILING 宏展开需要命名空间级别的上下文,在函数体内会编译失败;
  3. 两个原本应是命名空间自由函数的 Tiling4ResizeBicubicV2Grad 和 TilingPrepare4ResizeBicubicV2Grad 被解析为类成员函数定义,但无法匹配任何声明。

这是 diff 格式化重构过程中的误删。在行390 inputInfo_.lenDstW <= INT32_MAX; 之后、行392 ge::graphStatus Tiling4ResizeBicubicV2Grad(...) 之前,必须补回 }。

建议:在行390 inputInfo_.lenDstW <= INT32_MAX; 之后、行391空行之后、行392之前,插入 } 闭合 IsUseIdx32() 函数。

改动建议
375
- inputInfo_.lenDstW <= INT32_MAX;
375
+ inputInfo_.lenDstW <= INT32_MAX;
376
+ }
377
+
378
+ ge::graphStatus Tiling4ResizeBicubicV2Grad(gert::TilingContext * context)
应用建议
likedislike
不准确?
Wwkx12138成员
7月16日 预合并成功(commit_id: 8e1b6d280b8c4ff2503f4367c5d5effbe3fe300f)
此处折叠了5条事件消息 查看更多
Wwkx12138成员
7月16日 解决了最后一个问题
wkx12138成员
7月16日 评论:

compile

likedislike
Wwkx12138成员
7月16日 预合并成功(commit_id: 51879ab51dae2cef9c55ba8bbc30aeab27f4b491)
CANN-robotCANN-robot成员
7月16日 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
7月16日 评论:

流水线任务触发成功
任务链接 [26dd66a72aa84f10b8722a46520cfa47][流水线指导]

任务名称状态日志下载链接
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_A5 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_A5 ✅ SUCCESS >>>>> >>>>>
pre_comment ✅ SUCCESS >>>>>
Compile_Pre ✅ SUCCESS >>>>>
Compile_X86_monitor_910b ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910c ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_950 ✅ SUCCESS >>>>> >>>>>
UT_Test ✅ SUCCESS
PreSmoke_A900 ✅ SUCCESS >>>>>
PreSmoke_ATK_Test_A2 ✅ SUCCESS >>>>>
UT_Test_harmony-infer-chs-cv ✅ SUCCESS

[2026-07-16 15:37:08]    CI执行结束

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

流水线任务触发成功
任务链接 [5ba06eac98264ec2baf1d805dfe912c0][流水线指导]

任务名称状态日志下载链接
codecheck ✅ SUCCESS >>>>>
SCA ✅ SUCCESS >>>>>
antipoison ✅ SUCCESS >>>>>
codecheck_checkpr ✅ SUCCESS
StaticCheck_codespell ✅ SUCCESS
StaticCheck_link_validity ✅ SUCCESS
StaticCheck_resource_existence ✅ SUCCESS
StaticCheck_tag_closed ✅ SUCCESS
StaticCheck_markdownlint ✅ SUCCESS
codecheck_codestyle ✅ SUCCESS >>>>>
codecheck_precommit ⚠️ WARNING >>>>> >>>>>

[2026-07-16 15:14:58]    CI执行结束

likedislike
Wwkx12138成员
7月16日 修改了pull request 的描述
Wwkx12138成员
7月16日 修改了pull request 的描述
Wwkx12138成员
7月16日 修改了pull request 的描述
CANN-robotCANN-robot成员
7月16日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
7月16日 添加了label:ci-pipeline-passed
wkx12138成员
7月16日 评论:

/check-pr

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

The following labels are not ready.

lgtm: Please wait for reviewers to review the code.

approved: Please wait for committers to review the code.

likedislike
liulun0308成员
7月17日 评论:

/approve

likedislike
chenjiao成员
7月17日 评论:

/approve

likedislike
CANN-robotCANN-robot成员
7月17日 添加了label:approved
liu-wei
liu-wei成员
7月17日 评论:

/lgtm
/approve

likedislike
CANN-robotCANN-robot成员
7月17日 添加了label:lgtm
CANN-robotCANN-robot成员
7月17日 合入了pull request