Merged
reduceprod性能优化 #690
reduceprod性能优化 #690
Merged
sunzhongwen1Add on Jul 31
sunzhongwen1
sunzhongwen1Collaborators
Jul 31

描述

ARpattern下,reduce to 1的累加计算从逐元素累乘改为使用deinterleave+mul的树形规约。

关联的Issue

测试

文档更新

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for sunzhongwen1's contribution.)
sunzhongwen1sunzhongwen1Collaborators
Jul 31 Created pull request, commit a9258f97
atomgit-bot
atomgit-bot
Jul 31 Comments:

变更摘要

本 PR 针对 reduceprod(归约乘积)算子进行性能优化,改动集中在 pkg_inc/op_common/atvoss/reduce/reduce_operator.h。核心思路是将 ReduceAR / ReduceARI64 中"归约到 1"的最终阶段由逐元素串行乘法改为基于 DeInterleave + Mul 的对数树形归约,将指令循环次数从 O(reservedR) 降为 O(log2(eleCount)),同时精简了 ReduceARFoldBase 中冗余的块重复归约第二段循环及相关参数。

主要改动

  • 新增 LogBase2 辅助函数: 在文件中新增 LogBase2(uint16_t n) 用于计算以 2 为底的对数(对 n <= 0 返回 0),作为树形归约的迭代次数 repeatTime。
  • 精简 ReduceARFoldBase 签名与逻辑: 移除 dstAddr、maskElems、blkElems、isBlkRepeat、blkRepeats 参数,并删除其中基于 DIST_BLK 加载的块重复归约第二段循环(含 LocalMemBar),块内归约改由调用方统一完成。
  • "Reduce to 1" 阶段改为对数树形归约: ReduceAR 与 ReduceARI64 中将原先"Duplicate 置 1 + 广播 DataCopy + Mul 循环 reservedR 次"的串行实现,替换为"Select 结合全 1 的 tempOne 将掩码外元素置 1,再循环 repeatTime = LogBase2(eleCount) 次执行 DeInterleave + Mul",并在归约前新增 LocalMemBar 屏障。
  • vLElems / blkElems 计算简化: ReduceAR 中去除 IsB64<PromteT>() 条件分支,统一按 VL_LEN / sizeof(PromteT)、BLOCK_SIZE / sizeof(PromteT) 计算;ReduceARI64 中统一按 float 计算;同时移除 blkRepeats、isBlkRepeat、reservedR 等中间变量,改为 eleCount 与 repeatTime。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
Jul 31 Comments:

代码审查

✅ 未发现问题

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Jul 31 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Jul 31 Comments:

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.
For more, you also can visit HICANN.


PR Approval Progress

✅ Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
pkg_inc ✅ 王永光, 王瑞 (2/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

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

likedislike
CANN-robot
CANN-robotCollaborators
Jul 31 Comments:

CLA Signature Pass

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

likedislike
CANN-robotCANN-robotCollaborators
Jul 31 Set zhou-qilong,wangrui_,rxtfeng,loov1,tang-lei01,jia0liang,zl_hw,songkai111,pingchuantang,llimwang,gubaocheng,wangyongguang as approver
10 event messages are collapsed here。 See more
CANN-robotCANN-robotCollaborators
Aug 11 Added label: cann-cla/yes
sunzhongwen1
sunzhongwen1Collaborators
Aug 17 Comments:

compile

likedislike
sunzhongwen1sunzhongwen1Collaborators
Aug 17 Pre merge succeeded (commit_id: e9dd1b1dde8d52af9786e33cc44b09ec27100816)
5 event messages are collapsed here。 See more
sunzhongwen1sunzhongwen1Collaborators
Aug 18 Modify description of pull request
wangyongguang
wangyongguangCollaborators
Aug 18 Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
Aug 18 Added label: approved
RuiWang_
RuiWang_Collaborators
Aug 18 Comments:

/lgtm
/approve

likedislike
CANN-robotCANN-robotCollaborators
Aug 18 Added label: lgtm
CANN-robotCANN-robotCollaborators
Aug 18 Closed associated issue
CANN-robotCANN-robotCollaborators
Aug 18 Merged pull request