已合并
feat: 优化Where性能建模 #1580
feat: 优化Where性能建模 #1580
已合并
gaoxin创建于 7月31日
gaoxin成员
7月31日

Pull Request

描述

完善 Where/Select V2 的 ATT 性能建模与 codegen 传参链路,修正 1D WhereImpl 和 2D WhereExtend 的计数建模。

背景

  • Where/Select V2 当前共享 codegen/perf 链路,但 specific params 未透传,导致 ATT 无法拿到 where 相关参数。
  • 1D WhereImpl 与 2D WhereExtend 的 Reg:: 调用模型不同,原有复用逻辑不能准确反映实际开销。
  • outer loop 的拆分方式需要和 codegen 的 where 参数结构一致,避免重复计入最后一层 outer。

修改方案

  • 为 Where/Select V2 透传 WhereNodeParams
  • 修正 Where V2 的 outer loop 传参与 WhereExtend 参数拆分
  • 按 WhereCompute 中的 Reg:: 调用补全 1D WhereImpl 性能模型
  • 保持 2D WhereExtend 路径的公共建模逻辑

变更类型

请选择本次引入的变更类型:

关联的Issue

如何测试

描述测试此变更的步骤和前提条件:

  1. source /home/developer/Ascend/cann/set_env.sh && export ASCEND_HOME_PATH=/home/developer/Ascend/cann
  2. cmake --build build --target aihac_codegen -j 8

核对清单

其他信息

无。

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 gaoxin 的贡献)
Ggaoxin成员
7月31日 创建了 pull request,commit 0231e684
atomgit-bot
atomgit-bot
7月31日 评论:

变更摘要

本 PR 旨在完善 Where/Select V2 的 ATT 性能建模与 codegen 传参链路:新增 WhereNodeParams 数据结构并将其从 codegen 侧经 AscirNodeParams 一路透传到 ATT 性能建模侧,同时修正 Where V2 的 outer loop 传参与参数拆分,并按 WhereCompute 中的 Reg:: 调用补全 1D WhereImpl 性能模型,2D WhereExtend 路径则复用公共建模逻辑。

主要改动

  • 新增 WhereNodeParams 并打通透传链路: 在 ascir_node_param.h 中新增 WhereNodeParams 结构体(含 valid、is_bcast_src0、is_bcast_src1、outer_call_count、output_dims、output_strides、mask_strides、input_strides 等字段)并加入 AnySpecificParams variant;api_perf.h 的 NodeDetail 与 tuning_space.h 的 NodeInfo 同步增加 where_node_params 字段;specific_params_builder.cpp 新增 FillWhereParams 并对 kWhere/kSelect 节点类型分发填充;ascir_api_perf_v2.cpp 的 WhereApi 将 node.where_node_params 赋值给 node_info。

  • codegen 侧填充 Where 参数并修正 outer loop 传参: reg_where_api_call.cpp 新增 FillWhereNodeParams(通过 SetExtAttr(kAscirNodeParams, ...) 将参数写入节点,缺失时自动创建 AscirNodeParams)、BuildWhereLoopParams(按 outer repeats 计算 outer_call_count 及 dims/strides)与 GetWhereOuterForRepeats(拆分 outer repeats,剔除最后一个内层 repeat);GenerateLoopParams 签名增加输出参数 merge_info,各 scalar/normal 分支按 x2/x3 是否为标量(即 src0/src1 是否 broadcast)分别调用 FillCurrentWhereNodeParams 填充参数。

  • 重构 WherePerf 性能模型并新增 1D WhereImpl 模型: ascendc_regbase_perf.cpp 中 WherePerf 改为按 where_node_params.valid 分流:有效时走 AddWhereExtendPerf(1D 走 AddWhereImplPerf,2D 走 AddWhereExtend2DPerf),否则回退 AddLegacyWherePerf;1D AddWhereImplPerf 按 Reg:: 调用序列(CreateMask/Placeholder、broadcast 源的 Duplicate、UpdateMask、condition LoadAlign、CompareScalarNE、MaskUnPack、src0/src1 LoadAlign、Select、StoreAlign)建模,repeat 次数由 Ceiling(count / repeat_elm) 计算。

  • 补充 2D WhereExtend 公共建模与辅助函数: AddWhereExtend2DPerf 以 block_count = counter_first * repeat_time 复用 AddWhereComputePerf 的公共建模逻辑;新增 GetWhereRepeatElm(按 dtype 取 repeat 元素数,int64/uint64 加倍)与 GetWhereMaskUnPackCount(按 dtype 计算 mask 解包次数);WherePerf 在参数有效时对结果乘以 outer_call_count。

likedislike
不准确?
atomgit-bot
atomgit-bot
7月31日 评论:

代码审查

✅ 未发现问题

likedislike
不准确?
CANN-robotCANN-robot成员
7月31日 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
7月31日 评论:

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 ✅ 张德鹏, xchu42, zhang_shengjie (3/2) ✅ 张德鹏 (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

gcw_V3YyYBt1, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
此处折叠了116条消息 查看更多
CANN-robotCANN-robot成员
8月11日 添加了label:lgtm
张德鹏成员
8月11日 评论:

/approve

likedislike
CANN-robotCANN-robot成员
8月11日 添加了label:approved
CANN-robotCANN-robot成员
8月11日 关闭了关联的issue
CANN-robotCANN-robot成员
8月11日 合入了pull request