Pull Request已成功合入, 合并人@CANN-robot
(感谢 朱珉 的贡献)变更摘要
本次 PR 主要包含三条变更线:一是重构 codegen_kernel_loop.cpp 中的缓存守卫(cache guard)条件生成逻辑,将 Reduce 图与非 Reduce 图的缓存判定路径分离,并提取 GetCacheGuardCondition 辅助函数统一生成条件分支;二是新增 MicroRsqrtApiCall 类,通过组合 Duplicate、CompareScalar、Sqrt、Div、Select 等 MicroAPI 基础指令实现 Rsqrt 的向量函数(VF)代码生成,并在 RsqrtAscIrCodegenImplV2 中启用向量函数支持;三是新增 SameSourceBroadcastCsePass 图优化 Pass,在 Norm 结构图中识别并合并同源 Reduce 输出的等价 Broadcast 节点,减少冗余计算。
主要改动
- 缓存守卫条件重构与 Reduce 图支持:在
codegen_kernel_loop.cpp中,将GenerateBody的缓存守卫生成逻辑抽取为GetCacheGuardCondition函数,统一处理普通广播轴、融合广播轴以及双 Tile Reduce 三种场景;同时 Reduce 图的enable_cache判定改为通过IsNodeSplitB检查整条 Broadcast 输入链,而非依赖 AutoSchedule 缓存标记,并新增日志输出缓存资格判定结果。 - 新增
MicroRsqrtApiCall实现 Rsqrt 的 MicroAPI 指令组合:在micro_rsqrt_api_call.cpp中实现MicroRsqrtApiCall::Generate,因 3510/5102 公开 MicroAPI 未提供原生 Rsqrt,通过Duplicate(1.0)→CompareScalar(LT, 0.0)→Sqrt→Div→Select指令序列组合实现,并通过MicroApiCallRegister注册到工厂。 - Rsqrt 向量函数支持启用:在
v2_ascir_codegen_impl.h中为RsqrtAscIrCodegenImplV2添加GetMicroApiCallName、GetMicroApiName方法,并将IsVectorFunctionSupported返回true,同时增加kernel_reg_compute_intf.h头文件依赖,使 Rsqrt 可参与 VF 分区。 - 新增
SameSourceBroadcastCsePass同源 Broadcast 合并优化:新增same_source_broadcast_cse_pass.cpp/.h,在 Norm 结构图中按共同输入源(实际降维的 Reduce 输出)分组 Broadcast 节点,比较 Tensor 视图与调度属性等价性后合并重复节点,保留拓扑序最早的 canonical 节点,并在pass_runner_v2.h中注册该 Pass。 - 测试覆盖:新增
test_codegen_micro_rsqrt_api_call.cpp验证 Rsqrt 指令序列生成、工厂创建及输入输出类型不匹配拒绝;新增test_same_source_broadcast_cse.cpp验证 Broadcast 合并、不同视图/调度/控制边的保留、以及非降维 Reduce 的跳过;在vector_func_st.cpp和test_vf_partition.cpp中增加 TrueDiv+Add+Rsqrt 端到端集成测试。


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 | ✅ 张德鹏, xchu42, wangxiaotian995 (3/2) | ✅ 张德鹏 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
JaydenChu, thanks for your pull request. All authors of the commits have signed the CLA. 👍


流水线任务触发成功
任务链接 [538b5fecf7184550bd0e30a0f333b48a][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| codecheck | ✅ SUCCESS | >>>>> | |
| SCA | ✅ SUCCESS | >>>>> | |
| antipoison | ✅ SUCCESS | >>>>> | |
| codecheck_checkpr | ✅ SUCCESS | ||
| pre_comment | ✅ SUCCESS | >>>>> | |
| codecheck_codestyle | ⚠️ WARNING | >>>>> | |
| codecheck_precommit | ✅ SUCCESS | >>>>> |
[2026-08-05 09:32:20] CI执行结束


流水线任务触发成功
任务链接 [ca4fcd42b2cf44ec936cad2ebc18c735][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| UT_Test_Python_superkernel | ✅ SUCCESS | >>>>> | |
| ST_Test_Python_superkernel | ✅ SUCCESS | >>>>> | |
| UT_Test_superkernel | ✅ SUCCESS | >>>>> | |
| UT_Test_autofuse_framework | ✅ SUCCESS | >>>>> | |
| ST_Test_autofuse_framework | ✅ SUCCESS | >>>>> | |
| UT_Test_autofuse_ascendc_api | ✅ SUCCESS | >>>>> | |
| ST_Test_autofuse_ascendc_api | ✅ SUCCESS | >>>>> | |
| ST_Test_autofuse_e2e | ✅ SUCCESS | >>>>> | |
| pre_comment | ✅ SUCCESS | >>>>> | |
| UT_Test_Report | ✅ SUCCESS | >>>>> | |
| ST_Test_Report | ❌ FAILED | >>>>> |


流水线任务触发成功
任务链接 [619daa471a884562a881d68e3c4dcfa0][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| codecheck | ✅ SUCCESS | >>>>> | |
| SCA | ✅ SUCCESS | >>>>> | |
| antipoison | ✅ SUCCESS | >>>>> | |
| codecheck_checkpr | ✅ SUCCESS | ||
| pre_comment | ✅ SUCCESS | >>>>> | |
| codecheck_codestyle | ⚠️ WARNING | >>>>> | |
| codecheck_precommit | ✅ SUCCESS | >>>>> |
[2026-08-05 14:24:13] CI执行结束


流水线任务触发成功
任务链接 [29f57427e30246ff8b5c94d0eeff71f0][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| UT_Test_Python_superkernel | ✅ SUCCESS | >>>>> | |
| ST_Test_Python_superkernel | ✅ SUCCESS | >>>>> | |
| UT_Test_superkernel | ✅ SUCCESS | >>>>> | |
| UT_Test_autofuse_framework | ✅ SUCCESS | >>>>> | |
| ST_Test_autofuse_framework | ✅ SUCCESS | >>>>> | |
| UT_Test_autofuse_ascendc_api | ✅ SUCCESS | >>>>> | |
| ST_Test_autofuse_ascendc_api | ✅ SUCCESS | >>>>> | |
| ST_Test_autofuse_e2e | ✅ SUCCESS | >>>>> | |
| pre_comment | ✅ SUCCESS | >>>>> | |
| UT_Test_Report | ✅ SUCCESS | >>>>> | |
| ST_Test_Report | ✅ SUCCESS | >>>>> |
[2026-08-05 15:24:19] CI执行结束


/lgtm


/lgtm


Pull Request
描述
本次 Pull Request 针对 Norm 类计算中的通用性能问题进行优化,重点覆盖固定输入重复处理、同源 Broadcast 重复计算以及归约后 Elementwise API 碎片化等场景。
本次变更不匹配固定的 LayerNorm 完整 Pattern,也不依赖特定 Shape、节点名称或前端算子名称,而是根据图结构、Tensor View 和调度属性识别可优化的局部计算。当前主要以 LayerNorm 作为功能和性能验证对象。
主要变更如下:
1. 统一固定输入缓存逻辑
重构 Kernel Loop Codegen 中的缓存条件判断与 cache guard 生成流程:
2. 新增同源 Broadcast CSE Pass
新增面向 Norm-like 图的同源 Broadcast 公共子表达式消除能力:
该 Pass 已注册到 v35 GraphPassRunner,在 Tensor View 和调度属性稳定后、VF 分区前执行。
3. 支持归约后 Elementwise VF 融合
扩展 Rsqrt 和 TrueDiv 的 VF 能力,使 LayerNorm 等场景中的归约后 Elementwise 链能够连续执行:
MicroRsqrtApiCall。TrueDiv -> Add -> Rsqrt连续 VF 路径。4. 补充功能验证与回退场景
针对上述优化补充了以下测试能力:
TrueDiv -> Add -> RsqrtVF 分区和生成结果验证。5. 重构日志和测试代码
变更类型
请选择本次引入的变更类型:
关联的 Issue
暂无。
如何测试
测试前提
测试步骤
执行 LayerNorm 端到端功能测试
验证计算结果
验证固定输入缓存
验证同源 Broadcast CSE
验证归约后 Elementwise VF
TrueDiv -> Add -> Rsqrt统计量后处理链的 LayerNorm 场景。验证性能
Task Duration(us)作为性能指标。预期结果
TrueDiv -> Add -> Rsqrt在合法条件下进入同一个 VF。核对清单
其他信息