已合并
perf: 完善 Autofuse V2 Broadcast 性能建模(#235) #1812
perf: 完善 Autofuse V2 Broadcast 性能建模(#235) #1812
已合并
高煜博创建于 8月24日
高煜博
高煜博成员
8月24日

Broadcast 性能建模实施计划

For agentic workers: REQUIRED SUB-SKILL: 使用 superpowers:subagent-driven-development 或 superpowers:executing-plans,按任务逐项实施并在任务间进行验证。

目标: 为 Broadcast V2 建立与 AscendC 实现分支一致的 AIV_VEC 性能模型,并通过实现分支与 perf 分支一致性测试。

架构: 从 BroadcastRegApiCall::Generate 透传实际 Duplicate/BroadcastExtend 语义参数;ATT 侧按公共 tiling、last-axis、non-last-axis 分层复刻实现文件中的分支和 Reg API 调用。性能公式统一使用 Expression 和 TernaryOp,执行次数严格按源码循环层级计算。

技术栈: C++、ge::Expression、ATT VfPerfUtils、TernaryOp、gtest、现有 V35 ATT GLOB 构建体系。

全局约束

  • 入口必须是 autofuse/v35/codegen/reg_api_call/reg_broadcast_api_call.cpp。
  • 不建模 VectorFunc 融合使用的 Broadcast 微指令。
  • Reg/MicroAPI 依据为 autofuse/v35/ascendc/api_regbase/broadcast_3510_extend_impl.h 和 broadcast_gather_3510_extend_impl.h。
  • 次数按 repeatTimes * size0 * size1 * ... 及源码实际循环层级计算。
  • 性能表不存在的函数直接使用 kPlaceholder。
  • load/store 使用 kLoad 和 kStore。
  • 性能表缺少 dtype 时仍使用实现文件中的真实 dtype。
  • 不修改 Broadcast AscendC 实现、codegen/tiling 模板生成逻辑或无关模块。
  • 动态和静态统一使用 Expression。
  • IsBroadcastConstantTensor(x) 路径使用 kDuplicate 查表。
  • 测试通过标准:每个测试 shape 先根据 Broadcast 实现文件判定真实运行分支,再确认 perf 模型走同一分支;不能只比较最终性能表达式。
  • 每个 kPlaceholder 必须能追溯到唯一的真实 MicroAPI、方向/模式和 dtype。
  • DataCopy 分支按照一次kload计算。
  • 函数行数不超过 50 行,单个代码文件不超过 2000 行,圈复杂度不超过 20。
  • 所有除法表达式前 3 行内必须有明确的除零判断;包括 ceil、VL、block 元素数和 stride 派生计算。
  • 代码检查时允许忽略 kPlaceholder 引入的性能误差,但不能忽略分支选择、真实 MicroAPI、dtype 和执行次数错误。
  • 适合并行核对的独立任务应使用 subagent;subagent 只处理明确边界,不交叉修改同一文件。
  • 必须建立 Broadcast 实现分支矩阵:实现文件中的每个可达 if/else、wrapper 和 helper 都必须关联唯一 perf 分支、MicroAPI 计数和测试用例。
  • 任何任务不得仅因编译或测试通过而标记完成;只有“实现分支 -> perf 分支 -> 计数公式 -> 测试 oracle”四项逐条闭环后才能完成。
  • last-axis 和 non-last-axis 必须分别完成全量分支核对,不能用 non-last 覆盖情况推断 last-axis 已覆盖。
  • 每个叶子 helper 至少有一个正向测试;每个边界条件至少覆盖边界前、边界值和边界后三个形态,动态条件还必须覆盖符号表达式路径。
  • legacy fallback 只能对应 AscendC 实现明确返回 fallback 的路径;不得用 fallback 掩盖尚未实现或未测试的分支。
  • 最终验收前必须执行一次源码分支矩阵对账,列出已覆盖和未覆盖项;存在未覆盖项时不得宣称 Broadcast 全覆盖完成。

文件边界

参数链路

  • 修改 autofuse/common/ascir_node_param/ascir_node_param.h
  • 修改 autofuse/common/ascir_node_param/ascir_param_builder.cpp
  • 修改 autofuse/v35/codegen/reg_api_call/reg_broadcast_api_call.cpp
  • 修改 autofuse/att/gen_model_info/parser/specific_params_builder.cpp
  • 修改 autofuse/att/gen_model_info/parser/tuning_space.h
  • 修改 autofuse/att/gen_model_info/api_perf_register/api_perf.h
  • 修改 autofuse/v35/att/api_perf_register/ascir_api_perf_v2.cpp

性能模型

  • 新增 autofuse/v35/att/api_perf_register/ascendc_api_perf/broadcast_api_perf_v2.h
  • 新增 autofuse/v35/att/api_perf_register/ascendc_api_perf/broadcast_api_perf_v2.cpp
  • 新增 autofuse/v35/att/api_perf_register/ascendc_api_perf/broadcast_perf_utils_v2.h
  • 新增 autofuse/v35/att/api_perf_register/ascendc_api_perf/broadcast_perf_utils_v2.cpp
  • 新增 autofuse/v35/att/api_perf_register/ascendc_api_perf/broadcast_last_axis_perf_v2.h
  • 新增 autofuse/v35/att/api_perf_register/ascendc_api_perf/broadcast_last_axis_perf_v2.cpp
  • 新增 autofuse/v35/att/api_perf_register/ascendc_api_perf/broadcast_nlast_axis_perf_v2.h
  • 新增 autofuse/v35/att/api_perf_register/ascendc_api_perf/broadcast_nlast_axis_perf_v2.cpp

测试

  • 修改 autofuse/tests/ut/common/test_ascir_node_params.cpp
  • 修改 autofuse/tests/v35/ut/codegen/reg_api_call/test_codegen_broadcast_reg_api_call.cpp
  • 新增 autofuse/tests/v35/ut/att/gen_model_info/api_perf_register/test_broadcast_api_perf_v2.cpp
  • 修改 autofuse/tests/v35/ut/att/gen_model_info/api_perf_register/test_ascir_perf_v2.cpp

不修改 autofuse/v35/ascendc/api_regbase/broadcast*.h、autofuse/optimize/**、autofuse/att/gen_model_info/api_tiling_gen/**、CMake、VectorFunc Broadcast 相关文件。

Task 1:增加 Broadcast 参数载荷

文件: ascir_node_param.h、ascir_param_builder.cpp、tuning_space.h、api_perf.h、test_ascir_node_params.cpp

struct BroadcastNodeParams {
  bool valid{false};
  bool is_scalar{false};
  ge::Expression duplicate_count{ge::Symbol(1U)};
  std::vector<ge::Expression> dst_shape;
  std::vector<ge::Expression> src_shape;
};

验证:

sh build.sh -u --module=autofuse_framework -j 8

Task 2:从 Generate 透传实际参数

文件: reg_broadcast_api_call.cpp、test_codegen_broadcast_reg_api_call.cpp

Task 3:接通 ATT 参数链和 V2 注册

文件: specific_params_builder.cpp、ascir_api_perf_v2.cpp、test_ascir_perf_v2.cpp

Task 4:实现公共 tiling 和计数工具

文件: broadcast_perf_utils_v2.h/.cpp

Task 5:实现 scalar、equal-size 和 duplicate 模型

文件: broadcast_api_perf_v2.h/.cpp、test_broadcast_api_perf_v2.cpp

    • kLoad 一次;
    • kUpdateMask 为 ceil(dstSize / VF_LEN);
    • kStore 为相同 repeat 次数。

Task 6:实现 last-axis 分层模型

文件: broadcast_last_axis_perf_v2.h/.cpp、test_broadcast_api_perf_v2.cpp

Task 7:实现 non-last-axis 分层模型

文件: broadcast_nlast_axis_perf_v2.h/.cpp、test_broadcast_api_perf_v2.cpp

Task 8:汇总入口和一致性验收

文件: ascir_api_perf_v2.cpp、test_ascir_perf_v2.cpp、test_codegen_broadcast_reg_api_call.cpp

Expr res = VfPerfUtils::GetVFHeadCost() + max_latency + all_vf_instruct_cost;
res.Simplify();
perf.pipe_res[PipeType::AIV_VEC] = res;

Task 9:格式和构建验证

sh build.sh -u --module=autofuse_framework -j 8

Task 10:last-axis 全分支闭环

依据文件:

  • autofuse/v35/ascendc/api_regbase/broadcast_extend_impl.h

  • autofuse/v35/ascendc/api_regbase/broadcast_3510_extend_impl.h

  • autofuse/v35/ascendc/api_regbase/broadcast_gather_3510_extend_impl.h

  • autofuse/v35/att/api_perf_register/ascendc_api_perf/broadcast_last_axis_perf_v2.cpp

  • autofuse/tests/v35/ut/att/gen_model_info/api_perf_register/test_broadcast_api_perf_v2.cpp

Task 11:non-last-axis 全叶子计数闭环

依据文件:

  • autofuse/v35/ascendc/api_regbase/broadcast_3510_extend_impl.h

  • autofuse/v35/ascendc/api_regbase/broadcast_gather_3510_extend_impl.h

  • autofuse/v35/att/api_perf_register/ascendc_api_perf/broadcast_nlast_axis_perf_v2.cpp

  • autofuse/tests/v35/ut/att/gen_model_info/api_perf_register/test_broadcast_api_perf_v2.cpp

Task 12:constRank 动态 wrapper 和符号条件闭环

验收标准

  1. Broadcast V2 能从 BroadcastRegApiCall::Generate 追溯到 ATT 性能函数。
  2. scalar 和非 scalar 的实际 API 参数均能通过参数链传递到 perf。
  3. broadcast_extend_impl.h、broadcast_3510_extend_impl.h 和 broadcast_gather_3510_extend_impl.h 中的可达分支在 perf 中有对应模型。
  4. 每个 AddVfInstructPerf 都能追溯到真实 Reg/MicroAPI 调用、dtype 和源码循环次数。
  5. 每个测试 shape 根据实现文件判定的分支与 perf 选择的分支完全一致。
  6. 性能表缺少函数或 dtype 时按约束使用 kPlaceholder 或实现中的真实 dtype。
  7. AIV_VEC 最终公式和 TernaryOp 表达式可被现有 ATT 框架消费。
  8. 相关 UT 和 sh build.sh -u --module=autofuse_framework -j 8 通过。
  9. 未修改与本任务无关的 codegen、tiling、schedule、AscendC 实现或 VectorFunc 逻辑。
likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 高煜博 的贡献)
高煜博高煜博成员
8月24日 创建了 pull request,commit 5ad5af01
atomgit-bot
atomgit-bot
8月24日 评论:

🤖 正在生成合并请求摘要,请稍候…

likedislike
不准确?
atomgit-bot
atomgit-bot
8月24日 评论:

🤖 AI 代码检视正在进行中,请稍候…

likedislike
不准确?
CANN-robotCANN-robot成员
8月24日 添加了label:stat/needs-squash
CANN-robotCANN-robot成员
8月24日 添加了label:cann-cla/yes
此处折叠了236条消息 查看更多
CANN-robot
CANN-robot成员
9月10日 评论:

The following label is not ready.

approved: Please wait for committers to review the code.

likedislike
高煜博高煜博成员
9月10日 解决了最后一个问题
yangyongqiang
yangyongqiang成员
9月10日 评论:

/approve

likedislike
CANN-robotCANN-robot成员
9月10日 添加了label:approved
CANN-robotCANN-robot成员
9月10日 合入了pull request