已合并
fix(cv-ubfuse): host UB 约束按原始 tmp 需求计算, 修复 matmul+pow UB 越界 #2297
fix(cv-ubfuse): host UB 约束按原始 tmp 需求计算, 修复 matmul+pow UB 越界 #2297
已合并
tianbaolin创建于 20 天前
tianbaolin
tianbaolin成员
20 天前

Pull Request

描述

fix(cv-ubfuse): host UB 约束按原始 tmp 需求计算, 修复 matmul+pow UB 越界

CV UBFuse 的 Pow epilogue 内联调用 Power 高精度 API, tmp 需求为
12B/元素(如 stage=15488 时需 185856B)。device 侧已按原始公式分配
(去 v1 repeat cap), 但 host tiling 求解器的 UB 约束仍使用 capped
tmp(Min(size, 65312)), 两侧不一致: 求解器按 capped 值判定 UB 可行
并选出较大 stage, 而 device 实际按原始 tmp 分配, 导致
buf_cube + b0_raw + 队列超出 UB, 设备侧报 MTE2/MTE3 地址越界。

将 is_cv_ub_fusion 透传给 AscGraphUbExprBuilder, CV UBFuse 下 UB
约束对 tmp 剥离 v1 repeat cap, 与 device 分配保持一致, 求解器据此
收缩 stage(或走 common 兜底), 使原始 tmp 能落入 UB 预算。

验证: tc_af_MMBC_0287(mm+pow CV 融合)由设备越界 Failed 恢复 Pass
(100%); 新增 UT 覆盖 cap 剥离行为。

变更类型

请选择本次引入的变更类型:

关联的Issue

如何测试

描述测试此变更的步骤和前提条件:
baize 环境下测试tc_af_MMBC_0287

核对清单

其他信息

在此添加任何其他关于本次 PR 的说明。

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 tianbaolin 的贡献)
tianbaolintianbaolin成员
20 天前 添加了label:enhancement
tianbaolintianbaolin成员
20 天前 创建了 pull request,commit a82f82c0
atomgit-bot
atomgit-bot
20 天前 评论:

变更摘要

本 PR 修复 CV UBFuse 场景下 host tiling 求解器与 device 侧 tmp 分配不一致导致的 UB 越界问题。由于 GetTmpBuffer 会为 tmp 公式套上 v1 repeat cap 壳(Min(size, 255 * 256 + 32)),而 CV UBFuse 的 Pow epilogue 内联公式按原始需求分配 tmp,两侧不一致使求解器误判 UB 可行并选出较大 stage,最终 buf_cube + b0_raw + 队列 超出 UB。改动将 is_cv_ub_fusion 透传给 AscGraphUbExprBuilder,在 CV UBFuse 下对 tmp 剥离 v1 repeat cap,使 UB 约束与 device 分配保持一致,从而让求解器收缩 stage 或走 common 兜底。

主要改动

  • 新增 v1 repeat cap 剥离逻辑:在 asc_graph_ub_expr_builder.cpp 中新增常量 kMaxV1RepeatTmpBytes 与 StripV1RepeatCap,对形如 Min(size, 255 * 256 + 32) 的表达式剥离 cap 壳,还原原始 tmp 需求。
  • Build 接口增加原始 tmp 尺寸开关:AscGraphUbExprBuilder::Build 与 AddTmpBuffer 新增 use_raw_tmp_size 参数,为真时按原始 tmp 需求累加 node_tmp_buffer_bytes,默认值为 false 保持原有行为。
  • UbExprContext 新增字段:ub_expr_types.h 中 UbExprContext 增加 use_raw_tmp_size 字段,用于承载 CV UBFuse 下 UB 约束按原始 tmp 计算的语义。
  • host 侧透传 CV UBFuse 标识:gen_model_info.cpp 中 RefreshCommonUbExprContext 新增 is_cv_ub_fusion 参数并传入 Build,使 GenerateSingleModelInfoWithContext 能把 CV UBFuse 状态传递到 UB 表达式构建。
  • 补充单元测试:test_ub_expr_utils.cpp 新增 BuildStripsV1RepeatCapForRawTmpSize,验证默认构建得到 capped 值 65312、开启 use_raw_tmp_size 后得到原始值 80000。
likedislike
不准确?
atomgit-bot
atomgit-bot
20 天前 评论:

代码审查

✅ 未发现问题

likedislike
不准确?
CANN-robotCANN-robot成员
20 天前 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
20 天前 评论:

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
repo-cann/graph-autofusion ✅ yangyongqiang0606, zhang_shengjie, xuyafei (3/2) ✅ yangyongqiang0606 (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
tianbaolin
tianbaolin成员
20 天前 评论:

compile

likedislike
tianbaolintianbaolin成员
20 天前 预合并成功(commit_id: 58ac433fa5fc4698310674a1b23857c149f000b9)
CANN-robotCANN-robot成员
20 天前 将niuyuhu,yangyongqiang0606,liyuewei,xchu42,zhang_shengjie,depeng1994,wqtshg_wt,peiyang,shengnan666,XuebinYang,sjtulxh,zhanj,zhujingjing,xuyafei,wangxiaotian995设为评审人
CANN-robotCANN-robot成员
20 天前 将niuyuhu,yangyongqiang0606,liyuewei,xchu42,zhang_shengjie,depeng1994,wqtshg_wt,peiyang,shengnan666,XuebinYang,sjtulxh,zhanj,zhujingjing,xuyafei,wangxiaotian995设为审查人
CANN-robot
CANN-robot成员
20 天前 评论:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robot成员
20 天前 添加了label:ci-pipeline-running
此处折叠了6条事件消息 查看更多
CANN-robotCANN-robot成员
20 天前 添加了label:cann-cla/yes
tianbaolin
tianbaolin成员
20 天前 评论:

compile

likedislike
tianbaolintianbaolin成员
20 天前 预合并成功(commit_id: ae6077b7a18ccb93401bbaf2809238b067bbe429)
CANN-robot
CANN-robot成员
20 天前 评论:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robot成员
20 天前 删除了label:ci-pipeline-failed
CANN-robotCANN-robot成员
20 天前 添加了label:ci-pipeline-running
CANN-robotCANN-robot成员
20 天前 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
20 天前 添加了label:ci-pipeline-passed
xuyafei成员
20 天前 评论:

/lgtm

likedislike
zhang_shengjie成员
20 天前 评论:

/lgtm

likedislike
CANN-robotCANN-robot成员
20 天前 添加了label:lgtm
tianbaolintianbaolin成员
20 天前 修改了pull request 的描述
yangyongqiang
yangyongqiang成员
20 天前 评论:

/approve

likedislike
CANN-robotCANN-robot成员
20 天前 添加了label:approved
CANN-robotCANN-robot成员
20 天前 合入了pull request