已合并
feat: 支持静态Shape根据ub大小过滤非法template #964
zhang_shengjie创建于 6月21日
feat: 支持静态Shape根据ub大小过滤非法template #964
已合并
Pull Request已成功合入, 合并人@CANN-robot
(感谢 zhang_shengjie 的贡献)6月21日 创建了 pull request,commit 00e3103c
6月21日 添加了label:stat/needs-squash
6月21日 添加了label:cann-cla/yes
CANN-robot
6月21日 评论:
6月21日 评论:
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 |
|---|---|---|
| repo-cann/graph-autofusion | ✅ zhanj, xchu42, xuyafei (3/2) | ✅ zhanj (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
zhang_shengjie, thanks for your pull request. All authors of the commits have signed the CLA. 👍


6月21日 修改了pull request 的描述
此处折叠了131条消息 查看更多
7月6日 添加了label:lgtm
zhanj
7月7日 评论:
7月7日 评论:
/approve


7月7日 添加了label:approved
7月7日 合入了pull request
Pull Request
描述
一、主要解决的问题
Autofuse 在 schedule 模板生成后,所有模板会进入 ATT 生成 tiling func 和 solver 阶段。部分模板在所有可调 tile 取最小值 1、动态轴取 1 时的最小 UB 占用已超过平台 UB 上限,属于必然无解模板,但仍消耗后续编译资源。
本 PR 在
BufQueAllocator().AllocBufQue()之后新增StaticUbTemplateFilter,提前丢弃必然无解的模板,减少无效编译开销。同时将 ATT 与 Schedule 共用的 UB 表达式构建逻辑抽取到autofuse/common/ub_expr/,保证两端使用同一份 UB 表达式来源。二、修改方案
2.1 新增 StaticUbTemplateFilter(optimize 层)
optimize.cpp的AllocBufQue之后调用StaticUbTemplateFilter().Filter()FusedScheduledResult中每个ScheduledResult的 schedule group/impl graphAscGraphUbExprBuilder构建 UB 表达式上下文min_ub_usagemin_ub_usage > platform_info.ub_size时丢弃模板2.2 新增公共 UB 表达式层(common/ub_expr)
ub_expr_types.h:定义UbExprContext、UbExprBuildResult、UbExprCmp等公共类型asc_graph_ub_expr_builder.{h,cpp}:基于AscGraph构建 UB 表达式上下文,覆盖 Queue/Buffer/TmpBuffer size 表达式、container 命名、tile 变量、动态轴变量等ub_expr_utils.{h,cpp}:从UbExprContext获取原始 UB 表达式2.3 扩展 PlatformContext
TryGetInitializedPlatformInfo:无副作用读取已初始化的平台信息,不触发 runtime 初始化TryGetUbSizeOverride:支持上层通过SetPlatformInfo注入 UB size(soc_ver为空时)GetPlatformInfo/SetPlatformInfo既有行为不变2.4 ATT 侧适配
gen_model_info.cpp:新增RefreshCommonUbExprContext,基于公共AscGraphUbExprBuilder刷新 UB 表达式上下文,替换旧的 container 表达式ub_named_expr_builder.{h,cpp}:ATT 内部命名化 UB 表达式构建,复用公共BuildUbExpr获取原始表达式axes_reorder_solver_gen.cpp:适配公共 UB 表达式接口2.5 测试覆盖
test_static_ub_template_filter(过滤器正向/异常/边界)、test_ub_expr_utils(BuildUbExpr)、test_platform_context(新接口)test_gen_model_info(UB 刷新)、test_axes_reorder_gen(命名化 UB 表达式)optimize_st、optimize_st_v2、test_optimizer_v2、test_python_ascir三、代码修改流程图
flowchart TD A[Optimize 生成 schedule 模板] --> B[BufQueAllocator::AllocBufQue] B --> C[StaticUbTemplateFilter::Filter] C --> D{PlatformInfo 可用且 ub_size > 0?} D -- 否 --> E[跳过过滤, 保留全部模板] D -- 是 --> F[遍历 ScheduledResult] F --> G[AscGraphUbExprBuilder::Build] G --> H[UbExprUtils::BuildUbExpr] H --> I[tile=1, 动态轴=1 替换] I --> J{静态求值成功?} J -- 否 --> K[WARNING, 保留模板] J -- 是 --> L{min_ub > ub_size?} L -- 是 --> M[丢弃模板] L -- 否 --> N[保留模板] M --> O[继续后续流程] N --> O K --> O E --> O style C fill:#90EE90,stroke:#006400,stroke-width:2px style G fill:#90EE90,stroke:#006400,stroke-width:2px style H fill:#90EE90,stroke:#006400,stroke-width:2px变更类型
关联的Issue
如何测试
一、测试用例说明
1.1 单元测试
test_static_ub_template_filter:覆盖平台信息可用/不可用、UB 超限/未超限、表达式求值失败、全部模板被过滤等场景test_ub_expr_utils:覆盖 BuildUbExpr 正向和空表达式场景test_platform_context:覆盖 TryGetInitializedPlatformInfo 和 TryGetUbSizeOverridetest_gen_model_info:覆盖 UB 表达式刷新test_axes_reorder_gen:覆盖命名化 UB 表达式构建1.2 系统测试
optimize_st、optimize_st_v2:验证 optimize 全流程包含 UB 过滤test_optimizer_v2:v35 optimize 流程适配test_python_ascir:Python ASCIR 测试适配二、构建命令
核对清单
其他信息
验证方法
注意事项
提交记录
修改文件清单