已合并
feat: 完善 IndirectLoad 广播融合、Reduce 后融合及 SIMT 地址处理 #1783
xiebangrui2025创建于 1 天前
feat: 完善 IndirectLoad 广播融合、Reduce 后融合及 SIMT 地址处理 #1783
已合并
xiebangrui2025创建于 1 天前
xiebangrui2025
xiebangrui2025成员
1 天前

描述

本 PR 完善 IndirectLoad 在 SIMD/SIMT 模板下的广播、前置融合与后融合 Reduce,并补充 embedding 相关场景覆盖。

  • 修复 SIMT 双输入前置算子与后融合 Reduce 的 codegen 生命周期:IndirectLoad 的输入不再进入通用 Wait/Free,输出生命周期保持独立管理,避免生成阶段出现 GetTensor not found 或空指针。
  • 完善 SIMD/SIMT Broadcast 重写:支持直连 outer Broadcast,区分 SK 与 SIMD/SIMT 的前置节点搬移策略,并补充 Broadcast 前 Abs 场景。
  • 扩展 embedding 图处理:覆盖 INT32 索引到 INT64 的 Cast 链路、后融合 Add/Mul/ReduceSum,以及 SIMD 模板下带正索引行步长的整行搬运路径。
  • 修正 zero-stride-compact 窗口的物理向量 stride 派生,避免 producer bitwidth 变化引入 padding 后视图 stride 错误。
  • 精简重复的 IndirectLoad 测试矩阵及 CI 构建清单,保留 SIMD、SIMT、SK 和后融合 Reduce 的代表性覆盖。

变更类型

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

关联的Issue

无。

如何测试

  1. 构建 IL backend codegen/E2E 用例。
  2. 运行 embedding、Broadcast、add-il-reduce 及 SIMD/SIMT/SK 代表性用例,验证 codegen 选择和模拟器执行结果。
  3. 对目标修改执行 pre-commit 与 OAT 增量检查,检查通过。

核对清单

其他信息

无。

本次提交补充

  • 修正 SIMT IndirectLoad 的 evaluator 索引语义:index 分支 GM Load 使用 index_offset,普通 output 分支 GM Load 使用 output_index,并同时向 Output evaluator 传递两类偏移,避免 IndirectLoad → index-dependent Mul → Reduce 场景的 GM 越界。
  • 新增最小 IndirectLoad + Mul + Reduce SIMT E2E 复现用例,覆盖该地址计算链路。
  • 已完成目标 E2E、IndirectLoad codegen UT、限定目标文件 pre-commit 与 OAT 增量检查。
likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 xiebangrui2025 的贡献)
xiebangrui2025xiebangrui2025成员
1 天前 创建了 pull request,commit d90245b5
atomgit-bot
atomgit-bot
1 天前 评论:

变更摘要

本 PR 主要完善 IndirectLoad 在 SIMD/SIMT 场景下的 Broadcast 重写、前置算子融合与后融合 Reduce 支持。核心是修复 SIMT 双输入前置算子 + 后融合 Reduce 的 codegen 失败:为 TemplateBehavior 新增 skips_input_lifecycle 开关,SIMT IndirectLoad 的 input0/input1 跳过通用 WaitInputs/FreeInputs,输出生命周期仍由 skips_ub_lifecycle 单独控制,避免 post-reduce SIMT 输出 Alloc/Sync/Free 缺失导致 GetTensor not found。同时调整 SIMD 广播重写策略(不再折叠/拒绝直连 outer Broadcast,SK 跳过 input-pre 搬移),修正 zero-stride-compact 窗口 stride 派生,并新增 IL_ADD_IL_REDUCE 最小回归用例、IL_INPUT_ABS_BEFORE_BROADCAST Abs 前置支持及 embedding 用例改造。

主要改动

  • SIMT 输入/输出生命周期拆分修复:在 codegen_kernel_loop.cppGenerateBody 中,SIMT IndirectLoad 的 input0/input1 不再进入通用 WaitInputs/FreeInputs,输出侧仍按 skips_ub_lifecycle 保留 Alloc/Sync/Free,修复 post-reduce SIMT codegen 的 GetTensor not found / WaitInputs tensor_ptr nullptr 问题;对应在 indirect_load_utils.h/.cpp 新增 TemplateBehavior::skips_input_lifecycle 字段与 IsSimtIndirectLoad() 判定函数。

  • SIMD/SIMT/SK 广播重写路径拆分indirect_load_schedule_case_generator.cpp 删除 HasDirectOuterBroadcast/IsSupportedDirectOuterBroadcast 等对直连 outer Broadcast 的折叠与拒绝逻辑,SIMD candidate 保留直连 Broadcast 节点;RewriteInputPreNodeskIndirectLoadSK 直接跳过,并拆分出 RewriteSkInputPaths/RewriteBroadcastPaths 分别处理 SK 与 SIMT/SIMD 的改写入口。

  • zero-stride-compact 窗口 stride 派生修正reg_indirect_load_api_call.cppBuildTensorWindowInfo 中仅 kDense 布局保留逻辑 row-major strides,kZeroStrideCompact 视图保留零 stride 轴、非零窗口 stride 改由物理向量视图派生,以规避 bitwidth 变化的 producer 在逻辑元素间引入 padding 的问题。

  • 新增回归用例与生成器扩展:新增 indirect_load_add_il_reduce_test(index 区双输入 Add 前置 + 后融合 ReduceSum 的 SIMT 最小场景,复用 where 生成器/E2E 文件,以 IL_ADD_IL_REDUCE 宏门控);indirect_load_broadcast_backend_generator.cpp 与对应 E2E kernel 新增 IL_INPUT_ABS_BEFORE_BROADCAST,支持 Broadcast 前插入 Abs 前置算子并补齐 oracle 计算。

  • embedding 用例改造与测试矩阵精简indirect_load_embedding_backend_generator.cpp 将索引改为 INT32 + Cast 到 INT64 链路,并在 IndirectLoad 后拼接 Add/Mul/ReduceSum 后融合;E2E 断言从 EXPECT_FLOAT_EQ 改为 EXPECT_NEAR(..., 0.0625F) 以对齐 IL 家族容差约定;indirect_load_backend_generator_common.hBackendGraph 构造新增 index_type 参数,同时精简 rank3 int64 gather exact、strided gap-kind 笛卡尔积等冗余用例并同步更新 run_autofuse_test.sh CI 清单。

likedislike
atomgit-bot
atomgit-bot
1 天前 评论:

代码审查

✅ 未发现问题

likedislike
CANN-robotCANN-robot成员
1 天前 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
1 天前 评论:

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 张德鹏, xchu42, wangxiaotian995 (3/2) 张德鹏 (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
此处折叠了192条消息 查看更多
CANN-robotCANN-robot成员
11 小时前 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
11 小时前 添加了label:ci-pipeline-passed
张德鹏成员
9 小时前 评论:

/approve

likedislike
CANN-robotCANN-robot成员
9 小时前 添加了label:approved
CANN-robotCANN-robot成员
9 小时前 合入了pull request