已合并
fix: 支持Nddma Brc缓存建模和多Group无依赖场景Group间建模 #1960
fix: 支持Nddma Brc缓存建模和多Group无依赖场景Group间建模 #1960
已合并
zhang_shengjie创建于 5 天前
zhang_shengjie成员
5 天前

Pull Request

主要解决的问题

修复 ATT 在 cache guard、NDDMA 计数及多 group 串行依赖建模上的不一致,避免缓存命中路径执行次数被低估,以及存在真实跨 group 依赖时 objective 偏小导致候选模板排序错误。

同时完善 schedule-result 性能日志:最终 The value of graph*_result* 日志包含 group_sumedge_model、edge base、penalty 公式及对应数值,并保留数值紧跟在 is 后,兼容现有 att_analyze 结果性能解析。

修改方案

  1. 增加统一的 cache guard 计数逻辑,按符号 guard 范围和 block 维度计算实际执行次数,并对空/非法元数据安全回退。
  2. 修正 parser 对共享 cache guard parent、block 外层 guard 和非连续轴的识别,保持 NDDMA 执行计数与 codegen 一致。
  3. 在 codegen 中生成确定性的跨 group 串行 edge relation;对有效且非并行的 group 边增加可控惩罚,空 relation、单 group、并行 group 保持原逻辑。
  4. 将 edge penalty 参数集中到 att_group_perf_config.h,当前参数为 ratio=0.10cap=8000,便于后续基于 profiling 校准。
  5. 在最终 schedule-result 日志中输出:
    • group_sum 汇总值;
    • edge_model 版本;
    • edge base 公式及计算值;
    • penalty 的 min(cap, ratio * base) 公式及计算值;
    • 最终 objective 值。
  6. 保持原日志解析契约:最终结果格式为 The value of graph*_result* is <numeric> objective(...),不改变 objective 计算和模板选择逻辑。
  7. 补充 cache guard、parser、生成器及 codegen 的 UT,并新增 ATT ST 回归用例。

代码修改流程图

flowchart TD
    A["解析 ASCIR cache guard 与 group relation"] --> B{"元数据有效吗"}
    B -->|否| C["安全回退原有估值"]
    B -->|是| D["按符号范围计算 guard/NDDMA 次数"]
    D --> E["确定性生成跨 group edge"]
    E --> F{"存在串行依赖吗"}
    F -->|否| G["保持原 objective"]
    F -->|是| H["加入 edge penalty"]
    G --> I["生成数值前缀日志"]
    H --> I
    I --> J["追加 group_sum 与 edge_model 公式"]
    J --> K["进行模板比较与 PGO 候选排序"]

测试用例说明

本地 ATT Generator UT:

GeneratorUT.GenUpdatePerf*: 11/11 passed

本地 att_analyze 日志解析测试:

python3 -m pytest -q autofuse/tools/att_analyze/tests/unit/test_summary_templates.py autofuse/tools/att_analyze/tests/unit/test_log_parser.py
27 passed

新增公式日志兼容性验证:

The value of graph0_result0 is 85205.982063 objective(...)
result_performance=85205.982063

ATT LLT(CANN 9.2.0,/workspace/third_party):

att_ut_aggregate: Passed
100% tests passed, 0 tests failed

新增 ATT ST 回归:

CacheGuardRegression.*: 6/6 passed

ATT ST 全量入口受既有环境问题影响(缺失 ReduceSplitPenalty 生成可执行文件,以及 GCC 9.4/13.3 gcov 版本不匹配),不归因于本 patch。

NPU 端使用 Ascend950PR_9579(硬件 block_dim=56)和当前源码 host/device 产物,在统一 DSO、独立 TorchInductor/NPU cache 后验证通过:

PGO topn 首次编译耗时 (ms) eager (ms) autofusion (ms) speedup 最大误差
1 24332.7870 0.36129 0.33658 1.073x 4.768e-07
10 51401.0540 0.06997 0.06719 1.041x 4.768e-07

首次混用旧 CANN 动态库或旧 kernel cache 时曾出现 kernel init failed;清理并隔离运行时后可复现成功,说明该现象是环境/产物版本组合问题。

核对清单

其他信息

源分支:fix/att-cache-guard-final;目标分支:develop

最新提交:f9926331 fix: preserve numeric tiling objective log prefix

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 zhang_shengjie 的贡献)
Zzhang_shengjie成员
5 天前 创建了 pull request,commit a3e16e3e
atomgit-bot
atomgit-bot
5 天前 评论:

变更摘要

本 PR 修复 ATT 自动 tiling 在 cache guard 执行次数、NDDMA 计数及多 group 串行依赖建模上的不一致:新增 cache_guard_count.h/cpp 模块,按符号 guard 范围与 block 维度计算缓存命中路径的真实执行次数;ExeTimePassManager 通过 TryBuildCacheGuardInfo 从 parser 轴关系重建 guard 元数据,使 UpdateNodeExeTime 在命中数均匀时采用 CountGuardHits 结果;parser 侧在 Reduce 图中为 Load/Nddma/Broadcast 节点保留 cache condition,保持 NDDMA 执行计数与 codegen 一致;codegen 侧新增 GetSerializedGroupEdgesGenSerializedEdgePenalty,对非并行 group 的真实串行依赖在 objective 中加入 min(cap, ratio * Σmax(src,dst)) 惩罚,避免存在跨 group 依赖时候选模板排序错误;惩罚参数集中到新增的 att_group_perf_config.h。同时补充了 ST/UT 回归用例,覆盖 cache guard 计数、parser、generator 与 codegen。

主要改动

  • 新增 cache guard 计数模块cache_guard_count.h/cpp 定义 CacheGuardKindCacheGuardInfoCountGuardHits/IsBlockCountUniform/ValidateCacheGuardInfo,按 period/block_inner_extent 计算每 block 的实际 guard 命中次数(含尾部非整除块),对空/非法元数据、非正数或未证明符号范围、溢出等场景安全回退,避免缓存命中路径执行次数被低估。
  • 执行时间 pass 接入 guard 计数ExeTimePassManager 新增 TryBuildCacheGuardInfo(从 parser 的 block-inner/outer 轴关系唯一重建 guard 元数据)与 GetBlockDimExpr(由 tuning_space_->block_dims 求 block 维度),UpdateNodeExeTimeIsBlockCountUniform 成立时用单 block 命中数替换原 exe_time,否则记录日志并回退原估值;同时 NDDMA 节点允许尾部 vector 轴不破坏 guard 识别。
  • 修正 parser 对共享 cache guard parent 的识别ascend_graph_parser.cpp 新增 ShouldPreserveCacheCondition,在 Reduce 图中仅对 kLoad/Nddma/kBroadcast 节点保留显式 cache condition(与 codegen 的 NDDMA 执行计数一致),reduction 节点维持历史保守行为,并对空节点指针做保护。
  • codegen 生成跨 group 串行 edge penaltytiling_code_gen_impl.cpp 新增 GetSerializedGroupEdges(按 var_relation 确定性、去重提取有效跨 group 边,并行 group 或空 relation 返回空)与 GenSerializedEdgePenalty(生成 serialized_edge_base += std::max(src, dst)serialized_edge_penalty = std::min(cap, ratio * base) 并累加到 cur_perf 的更新代码),GenSingleGroupScheduleResult/GenUpdatePerf 将非连续 group id 映射到 perf 位置后接入;单 group、并行 group、无效边场景保持原 group-sum 逻辑。
  • 参数集中管理与测试补充:新增 att_group_perf_config.h,将 SerializedEdgePenaltyConfigkPenaltyRatio=0.10kPenaltyCapCycles=8000.0kModelVersion="serialized_edge_v1")集中管理;新增 ATT ST cache_guard_regression.cpp 及多处 UT(test_exe_time_manager.cpptest_ascend_graph_parser.cppatt_generator_unittest.cpptest_codegen_kernel.cpp)覆盖上述计数、parser 与 codegen 行为。
likedislike
不准确?
atomgit-bot
atomgit-bot
5 天前 评论:

代码审查

✅ 未发现问题

likedislike
不准确?
CANN-robotCANN-robot成员
5 天前 添加了label:stat/needs-squash
CANN-robotCANN-robot成员
5 天前 添加了label:cann-cla/yes
此处折叠了60条消息 查看更多
Zzhang_shengjie成员
4 天前 修改标题为 “fix: 支持Nddma Brc缓存建模和多Group无依赖场景Group间建模”,原标题为“fix: account for serialized cross-group edge cost in ATT objective”
wangxiaotian995成员
4 天前 评论:

/lgtm

likedislike
yangyongqiang
yangyongqiang成员
3 天前 评论:

/approve

likedislike
CANN-robotCANN-robot成员
3 天前 添加了label:approved
CANN-robotCANN-robot成员
3 天前 合入了pull request