已合并
fix: 支持Nddma Brc缓存建模和多Group无依赖场景Group间建模 #1960
zhang_shengjie创建于 5 天前
fix: 支持Nddma Brc缓存建模和多Group无依赖场景Group间建模 #1960
已合并
Pull Request已成功合入, 合并人@CANN-robot
(感谢 zhang_shengjie 的贡献)5 天前 创建了 pull request,commit a3e16e3e
atomgit-bot
5 天前 评论:
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 侧新增 GetSerializedGroupEdges 与 GenSerializedEdgePenalty,对非并行 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定义CacheGuardKind、CacheGuardInfo及CountGuardHits/IsBlockCountUniform/ValidateCacheGuardInfo,按 period/block_inner_extent 计算每 block 的实际 guard 命中次数(含尾部非整除块),对空/非法元数据、非正数或未证明符号范围、溢出等场景安全回退,避免缓存命中路径执行次数被低估。 - 执行时间 pass 接入 guard 计数:
ExeTimePassManager新增TryBuildCacheGuardInfo(从 parser 的 block-inner/outer 轴关系唯一重建 guard 元数据)与GetBlockDimExpr(由tuning_space_->block_dims求 block 维度),UpdateNodeExeTime在IsBlockCountUniform成立时用单 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 penalty:
tiling_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,将SerializedEdgePenaltyConfig(kPenaltyRatio=0.10、kPenaltyCapCycles=8000.0、kModelVersion="serialized_edge_v1")集中管理;新增 ATT STcache_guard_regression.cpp及多处 UT(test_exe_time_manager.cpp、test_ascend_graph_parser.cpp、att_generator_unittest.cpp、test_codegen_kernel.cpp)覆盖上述计数、parser 与 codegen 行为。


不准确?
atomgit-bot
5 天前 评论:
5 天前 评论:
5 天前 添加了label:stat/needs-squash
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”
4 天前 修改标题为 “fix: 支持Nddma Brc缓存建模和多Group无依赖场景Group间建模”,原标题为“fix: account for serialized cross-group edge cost in ATT objective”
wangxiaotian995
4 天前 评论:
4 天前 评论:
/lgtm


yangyongqiang
3 天前 评论:
3 天前 评论:
/approve


3 天前 添加了label:approved
3 天前 合入了pull request
Pull Request
主要解决的问题
修复 ATT 在 cache guard、NDDMA 计数及多 group 串行依赖建模上的不一致,避免缓存命中路径执行次数被低估,以及存在真实跨 group 依赖时 objective 偏小导致候选模板排序错误。
同时完善 schedule-result 性能日志:最终
The value of graph*_result*日志包含group_sum、edge_model、edge base、penalty 公式及对应数值,并保留数值紧跟在is后,兼容现有att_analyze结果性能解析。修改方案
att_group_perf_config.h,当前参数为ratio=0.10、cap=8000,便于后续基于 profiling 校准。group_sum汇总值;edge_model版本;min(cap, ratio * base)公式及计算值;The value of graph*_result* is <numeric> objective(...),不改变 objective 计算和模板选择逻辑。代码修改流程图
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:
本地
att_analyze日志解析测试:新增公式日志兼容性验证:
ATT LLT(CANN 9.2.0,
/workspace/third_party):新增 ATT ST 回归:
ATT ST 全量入口受既有环境问题影响(缺失
ReduceSplitPenalty生成可执行文件,以及 GCC 9.4/13.3 gcov 版本不匹配),不归因于本 patch。NPU 端使用 Ascend950PR_9579(硬件 block_dim=56)和当前源码 host/device 产物,在统一 DSO、独立 TorchInductor/NPU cache 后验证通过:
首次混用旧 CANN 动态库或旧 kernel cache 时曾出现
kernel init failed;清理并隔离运行时后可复现成功,说明该现象是环境/产物版本组合问题。核对清单
其他信息
源分支:
fix/att-cache-guard-final;目标分支:develop。最新提交:
f9926331 fix: preserve numeric tiling objective log prefix。