Merged
fix(tile_with_axis): Tiling溢出/CeilDiv回绕与标量UB越界加固,补动态shape范围推导及golden #6647
tan_xinAdd on 19 days ago
fix(tile_with_axis): Tiling溢出/CeilDiv回绕与标量UB越界加固,补动态shape范围推导及golden #6647
Merged
tan_xinAdd on 19 days ago
tan_xinCollaborators
19 days ago

描述

对 TileWithAxis 算子(Ascend950 AICore 实现)进行加固,覆盖 Tiling 计算、动态 shape 推导与属性契约三个维度。

改动原因

  • Tiling 中 outerDim/innerDim/rowLength/rowOutElements/totalOutElements 乘积链缺少 int64 溢出守卫,超大 shape 下会回绕产生错误分块;
  • CeilDiv 对空张量(rowLength==0 / totalCount==0)存在除以 0 与负数回绕风险;
  • 标量输入(rank=0)时输出共 tiles 个元素,原实现单核整块搬运,tiles 超过单缓冲容量(ubSize/2/dtypeSize)时发生 UB 越界写;
  • axis/tiles 属性契约与 TBE/AICPU 基线不一致(axis 默认 0 vs 1,tiles 可选 vs 必选);
  • 算子声明支持动态 shape(DynamicShapeSupportFlag=true),但缺少 InferShapeRange 输出范围推导。

改动方法

  • 新增 CheckMulNoOverflow 对全部 int64 乘积链做符号与溢出校验,超限即返回 GRAPH_FAILED;
  • 空张量分支:ComputeUbFactor/ComputeTotalCount/MaxBlocksOnAxis/SelectInitialUbAxis 对 rowLength==0 返回 0 块数,多核切分 totalCount==0 时 SetBlockDim(1);
  • HandleScalarInput 引入 bufferSize/dtypeSize 单缓冲容量判断:tiles 超容量时沿 tiles 维分块(ubAxis=1,NDDMA dim1 源 stride=0 广播读),消除 UB 越界写;
  • axis 缺省值统一为 1(对齐 TBE/AICPU),tiles 改为 REQUIRED(对齐 proto/README/AICPU def);
  • 新增 InferShapeRange4TileWithAxis:输出 range = 输入 range,axis 维乘 tiles,-1/-2 未知维标记原样传播,带 int64 溢出检查;
  • proto 明确 x 仅支持 ND 格式,文档与 golden 补齐。

关联的Issue

测试

  • 更新 op_host UT:tiling(溢出/空张量/标量分块)与 infershape(未知维传播、axis/tiles 契约)用例;
  • 新增 tests/assets/golden.py:以 torch 小算子拼接实现 TileWithAxis 语义,提供 TTK kernel/GEIR 模式的 golden 与 binary_equal 容差声明。

文档更新

  • 更新 README.md(axis 默认值、tiles 必选、ND 格式约束、动态 shape 支持说明)。

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for tan_xin's contribution.)
Ttan_xinCollaborators
19 days ago Created pull request, commit 1ffca304
CANN-robotCANN-robotCollaborators
19 days ago Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
19 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
*/*/README.md ✅ 陈娇, 汤平川, zhanw_coding (3/2) ✅ 陈娇 (1/1)
*/*/op_graph/*_proto.h ✅ 汤磊, 汤平川, zhanw_coding (3/2) ✅ 汤磊 (1/1)
*/*/op_host/*_def.cpp ✅ 汤磊, zhanw_coding, 汤平川 (3/2) ✅ 汤磊 (1/1)
repo-cann/ops-math ✅ zhanw_coding, 汤平川 (2/2) ✅ zhanw_coding, 汤平川 (2/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robotCANN-robotCollaborators
19 days ago Set yue-ma,zhou-qilong,gitee-duhuiping,wangrui_,rxtfeng,loov1,tang-lei01,zhangzijie,jia0liang,zl_hw,songkai111,gitcode-chenjiao,chenxingyu18,pingchuantang,llimwang,gubaocheng,andong_hw,wangyongguang,fengying555682,xuejinghui,onanfield,zhanw_coding,clinglai0517,caiwenwen,yanglu-1 as approver
CANN-robotCANN-robotCollaborators
19 days ago Set yue-ma,zhou-qilong,gitee-duhuiping,wangrui_,rxtfeng,loov1,tang-lei01,zhangzijie,jia0liang,zl_hw,songkai111,gitcode-chenjiao,chenxingyu18,pingchuantang,llimwang,gubaocheng,andong_hw,wangyongguang,fengying555682,xuejinghui,onanfield,zhanw_coding,clinglai0517,caiwenwen,yanglu-1 as approver
44 messages are collapsed here。 See more
CANN-robotCANN-robotCollaborators
16 days ago Added label: lgtm
tang-lei01Collaborators
16 days ago Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
16 days ago Added label: approved
CANN-robotCANN-robotCollaborators
16 days ago Closed associated issue
CANN-robotCANN-robotCollaborators
16 days ago Merged pull request