Pull Request已成功合入, 合并人@CANN-robot
(感谢 xiebangrui2025 的贡献)变更摘要
此 PR 为 graph-autofusion 框架新增 IndirectLoad 算子支持,实现类似 Gather 的间接索引加载功能。核心改动包括:新增 IndirectLoad ASCIR 算子定义与 Python API、引入模板角色(TemplateRole)系统以区分 SIMD/SIMT 两种执行路径、实现 IndirectLoadScheduleCaseGenerator 自动生成双模调度候选、以及 IndirectLoadRegApiCall 代码生成器分别输出 SIMD(基于 UB 缓冲与 AscendC::Gather)和 SIMT(基于直接 GM 管线与 AscendC::Simt::VF_CALL)内核代码。同时新增 SIMT 标量表达式发射器,支持 Abs、Exp、Exp2、Relu 等算子的标量化内联。
主要改动
- 新增
IndirectLoad算子注册与 Python API:在v35/ascir/generator/ascir_builtin_ops_v2.cpp注册算子,定义axis、negative_index_support、need_check_bound、max属性;在pyascir.cpp/pyascir.h添加 IR 属性访问器,并在ascir_api.py提供IndirectLoad构图接口。 - 引入模板角色系统与 IndirectLoad 工具模块:在
schedule_result.h定义TemplateId(kIndirectLoadSimd/kIndirectLoadSimt)及角色属性存取函数;新增indirect_load_utils.h/.cpp,通过TemplateBehavior结构体控制节点在调度、代码生成、UB 表达式构建等阶段的行为(如跳过 API 发射、使用直接 GM 管线等)。 - 实现
IndirectLoadScheduleCaseGenerator双模调度候选生成:新增indirect_load_schedule_case_generator.cpp/.h,对图进行 SIMD/SIMT 两种模板的轴归一化、角色标注(kSimdInputPre、kSimtInputBoundary等)及固定 tile 切分,生成候选调度图与评分函数。 - 实现
IndirectLoadRegApiCall双路径代码生成:新增reg_indirect_load_api_call.cpp/.h,SIMD 路径通过 UB 临时缓冲搬运输入窗口并调用AscendC::Gather;SIMT 路径直接读取 GM 地址,生成IndirectLoadSimtKernel结构体与AscendC::Simt::VF_CALL调用,跳过 UB 生命周期管理。 - 新增 SIMT 标量发射器:新增
simt_scalar_emitter.cpp/.h,为 Abs、Exp、Exp2、Ln、Sqrt、Neg、Relu、LeakyRelu、BitwiseNot 等算子提供IsSimtScalarSupported和GenerateSimtScalarExpr接口,使 IndirectLoad SIMT 路径的前后处理链可内联为标量表达式。


代码审查
Now let me compile my final summary. All 57 files have been reviewed.
审查总结
按优先级统计
- P0: 1 个(编译失败风险)
- P1: 0 个
- P2: 1 个(错误被吞没)
- P3: 2 个(防御性代码缺失、魔数条件)
整体风险评估:中风险
P0 问题(EXPECT_EQ 对 void 函数调用)在测试文件中,若该测试文件被编译则必定失败;PR 声称 pre-commit 通过可能因测试不在编译范围内。P2 问题(InheritTemplateRoleIfIL 返回值丢弃)在运行时可能导致下游 codegen 行为异常。其余为低风险改进建议。
各文件审查结果
| 文件 | 结果 |
|---|---|
autofuse/att/base/att_const_values.h |
无问题 |
autofuse/att/gen_model_info/parser/ascend_graph_parser.cpp |
无问题 |
autofuse/att/generator/tiling_code_gen_impl.cpp |
无问题 |
autofuse/codegen/codegen_graph_check.cpp |
无问题 |
autofuse/codegen/codegen_kernel.cpp |
无问题 |
autofuse/codegen/codegen_kernel.h |
无问题 |
autofuse/codegen/codegen_kernel_loop.cpp |
无问题 |
autofuse/codegen/codegen_kernel_loop.h |
无问题 |
autofuse/common/ascgraph_info_complete.cpp |
无问题 |
autofuse/common/indirect_load_utils.cpp |
无问题 |
autofuse/common/indirect_load_utils.h |
无问题 |
autofuse/common/schedule_result.h |
无问题 |
autofuse/common/ub_expr/asc_graph_ub_expr_builder.cpp |
无问题 |
autofuse/compiler/py_module/pyascir.cpp |
无问题 |
autofuse/compiler/py_module/pyascir.h |
无问题 |
autofuse/compiler/python/ascir_api.py |
无问题 |
autofuse/inc/graph_metadef/graph/ascendc_ir/ascir_registry.h |
无问题 |
autofuse/optimize/autoschedule/autoschedule.cpp |
无问题 |
autofuse/optimize/autoschedule/autoschedule.h |
无问题 |
autofuse/optimize/autoschedule/schedule.cpp |
无问题 |
autofuse/optimize/autoschedule/schedule.h |
无问题 |
autofuse/optimize/autoschedule/tiling_group.cpp |
无问题 |
autofuse/optimize/buffer_allocate/buf_que_allocator.cpp |
无问题 |
autofuse/optimize/optimize.cpp |
无问题 |
autofuse/optimize/platform/common/base_alignment_strategy.cpp |
无问题 |
autofuse/optimize/schedule_utils.h |
P3: IsGatherLikeLoad 缺少空指针防御 |
autofuse/optimize/task_generator/indirect_load_schedule_case_generator.cpp |
P3: GenerateScoreFunc 魔数条件 |
autofuse/optimize/task_generator/indirect_load_schedule_case_generator.h |
无问题 |
autofuse/tests/framework/share_graph/include/share_graph.h |
无问题 |
autofuse/tests/framework/share_graph/src/share_graph.cc |
无问题 |
autofuse/tests/st/python/test_python_ascir.py |
无问题 |
autofuse/tests/ut/ascendc/compile/indirect_load_simd.py |
无问题 |
autofuse/tests/ut/ascendc/compile/indirect_load_simt.py |
无问题 |
autofuse/tests/ut/att/.../test_ascend_graph_parser.cpp |
无问题 |
autofuse/tests/ut/common/test_ub_expr_utils.cpp |
无问题 |
autofuse/tests/ut/optimize/autoschedule/test_autoschedule.cpp |
P0: EXPECT_EQ 对 void 函数 |
autofuse/tests/ut/optimize/task_generator/test_indirect_load_schedule_case_generator.cpp |
无问题 |
autofuse/tests/ut/optimize/test_optimizer.cpp |
无问题 |
autofuse/tests/ut/python/test_python_ascir.py |
无问题 |
autofuse/tests/v35/st/backend_e2e_v2/CMakeLists.txt |
无问题 |
autofuse/tests/v35/st/backend_e2e_v2/indirect_load_store_test/CMakeLists.txt |
无问题 |
autofuse/tests/v35/st/backend_e2e_v2/indirect_load_store_test/indirect_load_store_backend_generator.cpp |
无问题 |
autofuse/tests/v35/st/backend_e2e_v2/indirect_load_store_test/test_e2e_indirect_load_store_kernel.cpp |
无问题 |
autofuse/tests/v35/st/backend_e2e_v2/indirect_load_store_test/test_e2e_indirect_load_store_simt_kernel.cpp |
无问题 |
autofuse/v35/ascir/generator/ascir_builtin_ops_v2.cpp |
无问题 |
autofuse/v35/ascir/generator/v2_ascir_att_impl.h |
无问题 |
autofuse/v35/ascir/generator/v2_ascir_codegen_impl.h |
无问题 |
autofuse/v35/att/api_perf_register/ascir_api_perf_v2.cpp |
无问题 |
autofuse/v35/codegen/reg_api_call/reg_indirect_load_api_call.cpp |
无问题 |
autofuse/v35/codegen/reg_api_call/reg_indirect_load_api_call.h |
无问题 |
autofuse/v35/codegen/simt_scalar_call/simt_scalar_emitter.cpp |
无问题 |
autofuse/v35/codegen/simt_scalar_call/simt_scalar_emitter.h |
无问题 |
autofuse/v35/codegen/vec_func_call/vec_func_call.cpp |
无问题 |
autofuse/v35/optimize/partition/vector_func_partitioner.cpp |
P2: InheritTemplateRoleIfIL 返回值丢弃 |
autofuse/v35/optimize/platformv2.cpp |
无问题 |
autofuse/v35/optimize/template/nddma_template.cpp |
无问题 |
scripts/test/run_autofuse_test.sh |
无问题 |
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 1 |
| 🟡 建议 | 0 |
⛔ 需要修改


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, zhang_shengjie, xchu42 (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
xiebangrui2025, thanks for your pull request. All authors of the commits have signed the CLA. 👍


/approve


The following users do not have permission to comment /lgtm or /approve on any module in this PR:
liyuewei


描述
本 PR 提供 IndirectLoad 相关能力支持,覆盖 codegen、autoschedule、Python 绑定、测试与 v35 路径的配套实现。
变更类型
请选择本次引入的变更类型:
关联的Issue
无。
如何测试
描述测试此变更的步骤和前提条件:
核对清单
其他信息
xiebangrui2025/graph-autofusion:ILcann/graph-autofusion:develop