Pull Request已成功合入, 合并人@CANN-robot
(感谢 zhang_shengjie 的贡献)变更摘要
此 PR 修复了 Gather 与 Reduce 融合且拆分为多个串行 Schedule Group 时,Reduce Group 沿 R 轴切分的核数惩罚过重的问题。原逻辑按 128B Cache Line 计算惩罚系数 Rational(1, 32),导致仅使用约 2 核。修改后,在特定场景下将 Reduce 核数惩罚粒度从默认 Cache Line 调整为 32B,使惩罚系数放宽至 Rational(1, 8),提升整体并行度。场景识别条件包括:非 Group Parallel、多 Schedule Group、原始图中包含 Gather 算子(即使已降级为 Load 仍按原始 op type 判断)、当前 Group 包含 Reduce。同时在 TuningSpace 中新增 penalty_cache_line_size 字段支持独立粒度配置,并增加 DEBUG 级别决策日志及回归测试。
主要改动
TuningSpace新增penalty_cache_line_size字段:在tuning_space.h中增加uint32_t penalty_cache_line_size{0},允许 Reduce 核数惩罚使用独立于物理 Cache Line 的粒度,0 表示沿用默认配置。CalcPenaltyCoreNumRatio支持独立惩罚粒度:在generate_tiling_expr.cpp中,核数惩罚计算优先使用tuning_space_->penalty_cache_line_size,若为 0 则回退到GetCacheLineSize(),使特殊融合场景可覆盖默认粒度。- 新增
ShouldEnableGatherReducePenalty场景识别函数:在gen_model_info.cpp中新增该函数及辅助函数HasComputeType、HasGatherNode,按条件判断是否启用 32B 放宽惩罚,并在各分支输出 DEBUG 日志说明命中/未命中原因。 GenerateModelInfo重载扩展:新增接受enable_gather_reduce_penalty参数的重载版本,在ProcessAndSetScheduleGroupInfo中调用场景识别函数并传递给下游,同时保留原始单参接口向后兼容。GatherToLoadPass保留原始 compute_type:在gather_to_load.cpp中先保存original_compute_type再改写为kComputeLoad,确保后续HasGatherNode按原始 op type(而非 Load)判断 Gather 是否存在,并在日志中输出类型变更详情。


代码审查
经过对所有 7 个变更文件的逐一审查,包括调用链分析、边界条件检查和测试覆盖率验证,以下是审查结论:
Closing Summary
- P0: 0
- P1: 0
- P2: 0
- P3: 1(
gather_to_load.cpp中int32_t与%d格式说明符的类型可移植性隐患,confidence 0.3)
Overall risk judgment: 此变更风险较低。核心逻辑正确:Gather+Reduce 融合场景的惩罚粒度判断链完整(非 Group Parallel → 多 Group → 当前 Group 含 Reduce → 全局存在 Gather),且 HasGatherNode 使用 op type 而非 compute_type 来识别已 Lower 为 Load 的 Gather 节点,与 PR 描述一致。新增测试覆盖了正向、Gather→Load、Group Parallel、单 Group、无 Gather 等回归场景。TearDown 新增 PlatformContext::Reset() 调用属于良好的测试清理实践。
各文件审查结果:
| 文件 | 结论 |
|---|---|
autofuse/att/gen_model_info/expr_gen/generate_tiling_expr.cpp |
no issues |
autofuse/att/gen_model_info/gen_model_info.cpp |
no issues |
autofuse/att/gen_model_info/gen_model_info.h |
no issues |
autofuse/att/gen_model_info/parser/tuning_space.h |
no issues |
autofuse/tests/ut/att/testcase/gen_model_info/expr_gen/test_generate_tiling_expr_penalty.cpp |
no issues |
autofuse/tests/ut/att/testcase/gen_model_info/parser/test_ascend_graph_parser.cpp |
no issues |
autofuse/v35/optimize/graph_pass/gather_to_load.cpp |
1 个 P3 建议 |
⚠️ 已识别出整体风险,但无法提取行内评论,请参考整体评估。


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, wangxiaotian995 (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. 👍


compile


流水线任务触发成功
任务链接 [5118f17432234a70a9a4e86c9b5ac80a][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| 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 | >>>>> |
[2026-07-17 13:38:54] CI执行结束


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


/lgtm


/lgtm


/approve


描述
一、主要解决的问题
Gather 与 Reduce 融合且拆分为多个串行 Schedule Group 时,Reduce Group 沿 R 轴切分仍按 128B Cache Line 计算核数惩罚,生成
Rational(1, 32),倾向仅使用约 2 核。Gather 容易受 Vector Bound 限制,该场景需要放宽 Reduce 核数惩罚,以提升整体并行度。二、修改方案
Rational(1, 32)调整为Rational(1, 8)。compute_type被改写后规则失效。三、代码修改流程图
flowchart TD A[遍历 Schedule Group] --> B{非 Group Parallel 且多 Group} B -->|否| F[使用默认 Cache Line] B -->|是| C{当前 Group 包含 Reduce} C -->|否| F C -->|是| D{原始 op type 包含 Gather} D -->|否| F D -->|是| E[Reduce 惩罚粒度设为 32B] E --> G[生成 Rational 1/8 核数惩罚] F --> H[生成默认核数惩罚]变更类型
关联的Issue
无。
如何测试
一、测试用例说明
1.1 单元测试
Rational(1, 8)。compute_type已转换为 Load 后仍命中Rational(1, 8)。Rational(1, 32)。1.2 系统测试
核对清单
其他信息
验证方法
注意事项
提交记录
修改文件清单
autofuse/att/gen_model_info/gen_model_info.cppautofuse/att/gen_model_info/gen_model_info.hautofuse/att/gen_model_info/parser/tuning_space.hautofuse/att/expr_gen/generate_tiling_expr.cppautofuse/v35/optimize/graph_pass/gather_to_load.cppautofuse/tests/ut/att/testcase/gen_model_info/parser/test_ascend_graph_parser.cppautofuse/tests/ut/att/testcase/expr_gen/test_generate_tiling_expr_penalty.cpp