Merged
fix(cumsum): 修复整数空Tensor tiling除零 #7177
fix(cumsum): 修复整数空Tensor tiling除零 #7177
Merged
wangweidongAdd on 5 days ago
wangweidong
5 days ago

问题描述

Cumsum 整数 tiling 未处理空 Tensor。当任一维度为 0 时,根据 0 维位于 axis 的前/中/后位置,leftAxisLen、midAxisLen 或 rightAxisLen 会变为 0,后续进入如下路径:

  • rightAxisLen=0:vlSize_ / (raLpUnit_ * dtypeSize) 触发除 0(SIGFPE);
  • midAxisLen=0:rLpUnit_=0,后续产生非法分核;
  • leftAxisLen=0:laLpCnt=0,CeilDiv(0, CeilDiv(0, coreNum)) 产生非法 tiling。

ACLNN 通路已有 self->IsEmpty() 早返回,但 TTK kernel/GE direct 会直接进入整数 tiling,因此仍需算子侧兜底。

修改内容

  1. 新增整数 empty tilingKey 11003;
  2. GetInputDims() 后检测 leftAxisLen/midAxisLen/rightAxisLen == 0,下发 blockDim=1/key=11003/workspace=0;
  3. kernel empty 分支通过 GET_TILING_DATA_WITH_STRUCT 注册 tiling struct size 后立即返回,不访问 GM;
  4. 初始化整数 tiling 成员,保证 empty 分支序列化数据确定;
  5. 增加 int32/int64/uint8 × axis 前/中/后三类空 Tensor UT。

关联的Issue

验证结果

  • Cumsum tiling UT:3/3 PASS;
  • empty UT:int32/int64/uint8 × axis 0/3/5,均 key=11003、blockDim=1、workspace=0;
  • Ascend950 kernel 二进制编译成功,opc 接受 11003;
  • TTK direct:int32/int64/uint8 空 Tensor 均 perf_status=PASS;
  • 非空回归 [105,2239]:axis0 key=11000/blockDim=35、axis1 key=11001/blockDim=53,precision 2/2 PASS;
  • git diff --check 通过。
likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for wangweidong's contribution.)
Wwangweidong
5 days ago Created pull request, commit 7f6cadf0
atomgit-bot
atomgit-bot
5 days ago Comments:

变更摘要

本次变更针对 Cumsum 整数 Tiling 路径在空 Tensor(任一维度为 0)场景下出现除零、非法分核与非法 tiling 的问题,在算子侧补充了兜底处理:在 GetInputDims() 之后由 Cumsum4IntTiling::CalcTilingData() 检测轴向切分长度是否为 0,并提前下发新的整数空 Tensor tilingKey CUM_EMPTY(11003)、blockDim=1 与 workspace=0;kernel 侧新增该 key 的立即返回分支,并将整数 tiling 成员统一初始化为 0,以保证空分支序列化数据的确定性。同时补充了覆盖多数据类型与多个 axis 位置的空 Tensor UT。

主要改动

  • 新增空 Tensor tilingKey 11003: 在 host 侧常量区新增 CUM_EMPTY = 11003,并注册 Cumsum_11003 对应的 Cum4IntTilingData,kernel 侧同步定义同名宏 CUM_EMPTY。
  • 空 Tensor 提前返回: Cumsum4IntTiling::CalcTilingData() 在获取输入维度信息后判断 leftAxisLen、midAxisLen、rightAxisLen 任一为 0,即设置 tilingKey_ = CUM_EMPTY、usedCoreCnt_ = 1 并直接返回成功,跳过 GetAxisLpUnit()、GetMCTilingInfo() 等后续切分计算。
  • kernel 空分支: cumsumSimdInt() 中新增 TILING_KEY_IS(CUM_EMPTY) 判断,通过 GET_TILING_DATA_WITH_STRUCT 读取 Cum4IntTilingData 后立即返回,不做任何 GM 访问或计算,同时保证 opc 可推导该 key 的 tiling 数据大小。
  • tiling 成员确定性初始化: 将 Cumsum4IntTiling 中 tilingKey_、isExclusive_、usedCoreCnt_、laLpUnit_、rLpUnit_、raLpUnit_ 等全部整型成员改为 {0} 默认初始化,避免空分支序列化未定义值。
  • 新增空 Tensor UT: 在 test_cumsum_tiling.cpp 中新增用例,覆盖 int32/int64/uint8 与 axis 为 0/3/5(对应 0 维位于前、中、后)的组合,校验 tilingKey=11003、blockNum=1、workspaceSizes[0]=0。

🧩 本次 Review 已使用自定义 Skill:

likedislike
Incorrect?
atomgit-bot
atomgit-bot
5 days ago Comments:

代码审查

审查结论

逐文件审查结果

  • math/cumsum/op_host/arch35/cumsum_tiling_ascendc_int_arch35.cpp:已审查。CalcTilingData 中在 GetInputDims() 之后新增的 leftAxisLen/midAxisLen/rightAxisLen == 0 早返回位置正确,位于所有除 0 / 非法分核点(GetAxisLpUnit、GetMCTilingInfo、CalcTilingKey)之前;三条轴通路(axis 在前/中/后)均能被该条件覆盖,usedCoreCnt_=1 与 WriteTilingData 的 SetBlockDim/SetTilingKey/workspace=0 语义自洽 — no issues。
  • math/cumsum/op_host/arch35/cumsum_tiling_ascendc_int_arch35.h:已审查。新增 CUM_EMPTY=11003、REGISTER_TILING_DATA_CLASS(Cumsum_11003, ...) 与 tiling data 结构字段一一对应;成员改为 {0} 初始化后逐项核对,非空路径仍会赋值全部 18 个成员,不改变原有序列化语义,仅使空 Tensor 分支数据确定 — no issues。
  • math/cumsum/op_kernel/cumsum_apt.cpp:已审查。CUM_EMPTY key 与 host 一致,空分支不做任何 GM 访问,放于 cumsumSimdInt 分派链首正确;发现 2 项问题(P2 修复单侧化未覆盖浮点通路、P3 未使用变量告警风险)。
  • math/cumsum/tests/ut/op_host/arch35/test_cumsum_tiling.cpp:已审查。新增用例的 {1,2,3,0,4,5} × axis {0,3,5} 确实分别命中 rightAxisLen=0、midAxisLen=0、leftAxisLen=0 三条分支,断言 tilingKey=11003 / blockDim=1 / workspace=0 与实现一致,SCOPED_TRACE 亦能区分失败组合 — no issues。

问题统计:P0 0 项,P1 0 项,P2 1 项,P3 1 项。

整体风险判断:整数通路的除零兜底本身实现正确、放置合理、UT 覆盖到位,不会引入回归;主要风险是本修复对空 Tensor 的处理呈现“单侧化”——仅整数 kernel 分支获得 empty key,浮点/半精度 AICore 通路(cumsumSimd 及浮点 tiling)未同步,在 TTK/GE direct 直调下可能残留同类除零风险,建议确认后补齐或明确说明已由其他机制覆盖。

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

💬 仅评论


🧩 本次 Review 已使用自定义 Skill:

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
5 days ago Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
5 days ago Comments:

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
math/cumsum ✅ 顾宝成, 周奇龙 (2/2) ✅ 周奇龙, 顾宝成 (2/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robotCANN-robotCollaborators
5 days ago Set FelixTang7,yue-ma,zhou-qilong,wangrui_,rxtfeng,loov1,zhangzijie,jia0liang,zl_hw,songkai111,chenxingyu18,pingchuantang,llimwang,gubaocheng,andong_hw,xuejinghui,onanfield,zhanw_coding,jiangjiawei,clinglai0517 as approver
CANN-robotCANN-robotCollaborators
5 days ago Set FelixTang7,yue-ma,zhou-qilong,wangrui_,rxtfeng,loov1,zhangzijie,jia0liang,zl_hw,songkai111,chenxingyu18,pingchuantang,llimwang,gubaocheng,andong_hw,xuejinghui,onanfield,zhanw_coding,jiangjiawei,clinglai0517 as approver
atomgit-bot
atomgit-bot5 days agoStart code review1
math/cumsum/op_kernel/cumsum_apt.cpp
@@ -189,0 +187,4 @@
187+ // 空 Tensor 无数据搬运或计算。保留 tiling struct 读取,供 opc 推导该 key 的 tiling 数据大小。
188+ GET_TILING_DATA_WITH_STRUCT(Cum4IntTilingData, emptyTilingData, tiling);
189+ return;
190+ } else if (TILING_KEY_IS(CUM_NO_SPLIT)) {
atomgit-bot
atomgit-bot5 days agoComments:

🟡 Medium Priority

变更点:cumsum_apt.cpp 在 cumsumSimdInt 中新增 TILING_KEY_IS(CUM_EMPTY) 空 Tensor 分支(186-189 行),配套的 tiling 兜底只加在 Cumsum4IntTiling::CalcTilingData(host 331 行)。

问题链条:本 PR 的背景说明中确认“ACLNN 通路已有 self->IsEmpty() 早返回,但 TTK kernel/GE direct 会直接进入 tiling”,因此空 Tensor 的兜底必须由算子自身在 所有 AICore 通路上完成。然而同文件的兄弟函数 cumsumSimd(half/float/bfloat16,处理 1001/1002/1011/1012/1101/1102/1111/1112/3011/3012/3112 等 key)完全没有 CUM_EMPTY 分支,host 侧的浮点 tiling 也不在本 diff 的改动范围内(只改了 cumsum_tiling_ascendc_int_arch35.*)。

失效模式:当 half/float/bfloat16 的空 Tensor 走 TTK direct(tests/st/arch35/ttk_kernel_cumsum_st.csv 这类直调)或 GE direct(不经过 ACLNN 的 IsEmpty 早返回)时,浮点 tiling 仍按原始逻辑计算,rightAxisLen/leftAxisLen/midAxisLen 为 0 会重演本 PR 描述的除 0(SIGFPE)或非法分核,kernel 侧也没有 any key 可退化为空实现 —— 即整数通路已修、浮点通路保持旧形态,两条路径的处理约定出现分歧。

建议:先确认浮点 tiling(cumsum_tiling_ascendc_arch35.cpp)是否已有空 Tensor 早返回;若没有,则在浮点/半精度 tiling 中同样下发 empty tilingKey,并在 cumsumSimd 中增加对应的空分支早返回,保持两条通路的约定一致,同时补 float 空 Tensor 的 UT/ST 用例。

likedislike
Incorrect?
Wwangweidong
5 days ago Pre merge succeeded (commit_id: 29fd90c80bf66a9ca204e4ce6aeefeb010632b4b)
Wwangweidong
5 days ago Pushed 1 commits:8a7f34ba-style(cumsum): apply clang-format
Wwangweidong
5 days ago Pre merge succeeded (commit_id: 5d7438c315ccb063c3f992cab5e5f5bc59a34d24)
CANN-robotCANN-robotCollaborators
5 days ago Removed label: cann-cla/yes
CANN-robotCANN-robotCollaborators
5 days ago Added label: stat/needs-squash
CANN-robotCANN-robotCollaborators
5 days ago Added label: cann-cla/yes
wangweidong
5 days ago Comments:

compile

likedislike
Wwangweidong
5 days ago Pre merge succeeded (commit_id: 1985145e772059df664aa9f7d1cf0225080cd2aa)
CANN-robot
CANN-robotCollaborators
5 days ago Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
5 days ago Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
5 days ago Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
5 days ago Added label: ci-pipeline-passed
gubaochengCollaborators
4 days ago Comments:

/lgtm
/approve
by agent

likedislike
CANN-robotCANN-robotCollaborators
4 days ago Added label: approved
chenyifengCollaborators
4 days ago Comments:

您好,PR已满足合入指标,请尽快联系Committer进行合入。如暂时不需要合入,请在PR标题前加[WIP]

likedislike
sundayCollaborators
1 day ago Comments:

/lgtm
/approve

likedislike
CANN-robotCANN-robotCollaborators
1 day ago Added label: lgtm
CANN-robotCANN-robotCollaborators
1 day ago Removed label: ci-pipeline-passed
CANN-robot
CANN-robotCollaborators
1 day ago Comments:

The following label is not ready.

ci-pipeline-passed: The ci-pipeline-passed label is expired as added over 72 hours. Please use /compile to recompile.

likedislike
wangweidong
1 day ago Comments:

compile

likedislike
Wwangweidong
1 day ago Pre merge succeeded (commit_id: 1fa96e7359ad0ebca427acaad3d3532a63c1306a)
CANN-robot
CANN-robotCollaborators
1 day ago Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
1 day ago Added label: ci-pipeline-running
5 event messages are collapsed here。 See more
CANN-robotCANN-robotCollaborators
1 day ago Merged pull request