Merged
float类型性能优化 #7121
xuyiyangAdd on 8 days ago
float类型性能优化 #7121
Merged
Pull Request has been successfully merged by CANN-robot.
(Thank you for xuyiyang's contribution.)atomgit-bot
8 days ago Comments:
8 days ago Comments:
变更摘要
本次变更针对 impl/simt_api/math_functions_impl.h 中的浮点数学函数进行性能优化,主要消减 atan2f 和 rnorm4df 中的分支路径。atan2f 由条件分支 + 多路选择重构为无分支的共享计算流程,统一用 base + sgn * t 的 __fma 形式还原象限;rnorm4df 将特殊值(inf/NaN/零范数)的提前返回改为计算完成后的结果覆盖,减少提前退出的分支。
主要改动
atan2f去除零分母分支:引入safe_hi = nz ? hi : 1.0f,使比值r = lo / safe_hi与多项式求值始终执行,避免hi == 0时的0/0路径发散,异常结果由后续选择丢弃。- 无理输入的特殊值处理改为选择:原先对
inf/inf产生的 NaN 与|y| == |x|对角线的特判,改为t = (t != t) ? pi/4 : t,使仿射公式自然产出pi/4与3pi/4。 - 象限还原合并为单次
fma:用xneg = __float_as_uint(x) >> 31提取符号,按y_gt_x与xneg选定base和sgn,以__fma(sgn, t, base)替换原先三分支的角度拼接。 - 零幅值与符号处理重构:
hi == 0时通过a0选择pi、0或pi/2,由nz决定最终取值;y 的符号改用__float_as_uint(y) >> 31按位判断,NaN 仍通过ax + ay传播。 rnorm4df特殊值判断后移:删除入口处的isinf/isnan提前返回与零范数提前返回,改为在完成倒数范数计算与一次 Newton 迭代后,依次用ASCRT_INF_F、ASCRT_NAN_F、0.0f覆盖result。


Incorrect?
atomgit-bot
8 days ago Comments:
8 days ago Comments:
8 days ago Added label: stat/needs-squash
8 days ago Added label: cann-cla/yes
CANN-robot
8 days ago Comments:
8 days ago 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.
You can self-configure the PR merge rules for this repository. For more details, please refer to 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 |
|---|---|---|
| impl/simt_api | ✅ wulinyu, louyuxuan (2/2) | ✅ wulinyu (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
xuyiyang0324, thanks for your pull request. All authors of the commits have signed the CLA. 👍


8 days ago Set zengjuan,zhanghao_0689,suqwe,wulinyu,kong0808,dengjing_aoe,YeZZzzz1,bluesky901,yangbinhua,zhudi22,chenyiyuan,xun_zhuge,XuebinYang,sjtulxh,bianque,houyuyang,Lycheeeee,YANXI_ZHAO,chentianyu19,shi_nanxiang,wuyang_hw,jiangxinyu3,ascendhjh,hujiawen_kaven,wangxiaozhi,DragonBornHD84,louyuxuan,hyolee,yukangchen as approver
8 days ago Set zengjuan,zhanghao_0689,suqwe,wulinyu,kong0808,dengjing_aoe,YeZZzzz1,bluesky901,yangbinhua,zhudi22,chenyiyuan,xun_zhuge,XuebinYang,sjtulxh,bianque,houyuyang,Lycheeeee,YANXI_ZHAO,chentianyu19,shi_nanxiang,wuyang_hw,jiangxinyu3,ascendhjh,hujiawen_kaven,wangxiaozhi,DragonBornHD84,louyuxuan,hyolee,yukangchen as approver
8 days ago Set wulinyu,wangxiaozhi,louyuxuan as approver
8 days ago Modify description of pull request
8 days ago Modify description of pull request
8 days ago Modify description of pull request
xuyiyang
8 days ago Comments:
8 days ago Comments:
compile


8 days ago Pre merge succeeded (commit_id: 621588184a5d25ab6dfb6af99ccdb51ac029f166)
CANN-robot
8 days ago Comments:
8 days ago Comments:
| 🚀 CI 流水线已启动 |
|---|
| 📋 执行详情: 点击查看流水线 |


8 days ago Added label: ci-pipeline-running
6 event messages are collapsed here。 See more
8 days ago Removed label: ci-pipeline-passed
CANN-robot
8 days ago Comments:
8 days ago Comments:
8 days ago Added label: cann-cla/yes
xuyiyang
8 days ago Comments:
8 days ago Comments:
compile


8 days ago Pre merge succeeded (commit_id: 49164c9693411b520200a9af4904a074f45c76b1)
CANN-robot
8 days ago Comments:
8 days ago Comments:
| 🚀 CI 流水线已启动 |
|---|
| 📋 执行详情: 点击查看流水线 |


8 days ago Added label: ci-pipeline-running
6 event messages are collapsed here。 See more
7 days ago Removed label: ci-pipeline-passedstat/needs-squash
CANN-robot
7 days ago Comments:
7 days ago Comments:
7 days ago Added label: cann-cla/yes
xuyiyang
7 days ago Comments:
7 days ago Comments:
compile


7 days ago Pre merge succeeded (commit_id: 708e941253c54b2db6159780e734678cd97a6f73)
CANN-robot
7 days ago Comments:
7 days ago Comments:
| 🚀 CI 流水线已启动 |
|---|
| 📋 执行详情: 点击查看流水线 |


7 days ago Added label: ci-pipeline-running
7 days ago Removed label: ci-pipeline-running
7 days ago Added label: ci-pipeline-passed
7 days ago Added label: lgtmapproved
7 days ago Merged pull request
描述
本次变更针对 impl/simt_api/math_functions_impl.h 中的浮点数学函数进行性能优化,主要消减 atan2f 和 rnorm4df 中的分支路径。atan2f 由条件分支 + 多路选择重构为无分支的共享计算流程,统一用 base + sgn * t 的 __fma 形式还原象限;rnorm4df 将特殊值(inf/NaN/零范数)的提前返回改为计算完成后的结果覆盖,减少提前退出的分支。
主要改动
无理输入的特殊值处理改为选择:原先对 inf/inf 产生的 NaN 与 |y| == |x| 对角线的特判,改为 t = (t != t) ? pi/4 : t,使仿射公式自然产出 pi/4 与 3pi/4。
零幅值与符号处理重构:hi == 0 时通过 a0 选择 pi、0 或 pi/2,由 nz 决定最终取值;y 的符号改用 __float_as_uint(y) >> 31 按位判断,NaN 仍通过 ax + ay 传播。
关联的Issue
https://gitcode.com/cann/asc-devkit/issues/1782
测试
--cce-use-fast-math=false: 847
--cce-use-fast-math=false: 820.62
--cce-use-fast-math=false: 544
--cce-use-fast-math=false: 367
文档更新
impl/simt_api/math_functions_impl.h
类型标签