Merged
float类型数学接口性能优化 #6500
xuyiyangAdd on Sep 29
float类型数学接口性能优化 #6500
Merged
Pull Request has been successfully merged by CANN-robot.
(Thank you for xuyiyang's contribution.)atomgit-bot
Sep 29 Comments:
Sep 29 Comments:
变更摘要
本 PR 针对 impl/simt_api/math_functions_impl.h 中的 float 类型数学接口进行性能优化,整体思路是调整 nextafterf、erff、erfcinvf、erfcxf、exp10f、expm1f、logbf、ilogbf 等函数的实现结构与分支顺序:将特殊值(NaN、±Inf、0)判断从函数入口移至计算之后,通过统一的结果变量与条件选择替代提前返回,使主计算路径更规整;同时改写 nextafterf 为基于整数位运算的方向步进实现,并将部分 exp2f/rsqrtf 调用替换为 __powf/__sqrtf 等价形式。
主要改动
nextafterf改为位运算实现: 使用__float_as_uint/__uint_as_float提取符号与幅值位,通过step_down判断步进方向、zero_res处理±0、并保留x==y与 NaN 传播逻辑,替代原先基于指针 reinterpret_cast 的多分支写法。erff、erfcinvf、erfcxf统一结果出口: 引入res/result变量,将各分支的return改为赋值后末尾统一返回;erff与erfcxf中把exp2f(x)替换为__powf(2.0f, x),erfcinvf中把rsqrtf(neg_log)替换为1.0f / __sqrtf(neg_log);erfcxf的x < -9.43f提前返回也调整为计算结果后再覆盖为ASCRT_INF_F。exp10f、expm1f特殊值处理后置: 移除入口处的 NaN/Inf(及expm1f的x == 0)提前返回,改为在完成__powf计算后按__isinf/__isnan/x == 0.0f覆盖结果;expm1f同时补充了__isnan(x) || x == 0.0f时返回y = x的收敛逻辑。logbf、ilogbf判断顺序调整: 先计算__internal_ilogbf_finite_abs(ax)作为默认结果,再依次用ax == ASCRT_INF_F、ax == 0.0f、__isnan(x)条件覆盖,替代原先依次提前返回的写法。log1pf特殊路径合并: 将原先嵌套在x_bits >= fp32_positive_inf_bits条件内的 inf 路径与-0处理,改为无条件计算inf_path并用need_inf、need_neg_zero两个布尔选择合并原外、内层条件。


Incorrect?
atomgit-bot
Sep 29 Comments:
Sep 29 Comments:
Sep 29 Added label: cann-cla/yes
CANN-robot
Sep 29 Comments:
Sep 29 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. 👍


61 messages are collapsed here。 See more
Oct 9 Added label: ci-pipeline-passed
29 days ago Added label: lgtmapproved
29 days ago Merged pull request
描述
本 PR 针对 impl/simt_api/math_functions_impl.h 中的 float 类型数学接口进行性能优化,整体思路是调整 nextafterf、erff、erfcinvf、erfcxf、exp10f、expm1f、logbf、ilogbf 等函数的实现结构与分支顺序:将特殊值(NaN、±Inf、0)判断从函数入口移至计算之后,通过统一的结果变量与条件选择替代提前返回,使主计算路径更规整;同时改写 nextafterf 为基于整数位运算的方向步进实现,并将部分 exp2f/rsqrtf 调用替换为 __powf/__sqrtf 等价形式。
主要改动
关联的Issue
https://gitcode.com/cann/asc-devkit/issues/1782
测试
--cce-use-fast-math=false: 51.39
优化前:152.72 优化后:114.70
--cce-use-fast-math=false:
优化前:146.30 优化后:115.45
--cce-use-fast-math=false: 49.85
优化前:129.32 优化后:98.53
--cce-use-fast-math=false:
优化前:129.40 优化后:98.96
--cce-use-fast-math=false: 147.20
优化前:64.23 优化后:44.99
--cce-use-fast-math=false:
优化前:62.98 优化后:44.91
--cce-use-fast-math=false: 37
优化前:133 优化后:103
--cce-use-fast-math=false:
优化前:133 优化后:103
--cce-use-fast-math=false: 306.50
优化前:167.86 优化后:159.99
--cce-use-fast-math=false:
优化前:327.58 优化后:323.14
--cce-use-fast-math=false: 98.53
优化前:97.21 优化后:53.27
--cce-use-fast-math=false:
优化前:93.32 优化后:56.16
文档更新
类型标签