Pull Request已成功合入, 合并人@CANN-robot
(感谢 kangjiaming 的贡献)变更摘要
此 PR 修复了 bessel_i1e 内核在 Ascend C 架构上的数值精度问题。核心改动是将 BesselI1e::Compute 中用于计算 exp(-|x|/4) 的泰勒级数从 9 项扩展到 13 项,并采用分阶段(staged)的 Horner 形式以避免深层嵌套导致编译器无法处理,从而将最大误差从约 2.6e-6 降低到 6.1e-10(约 4000 倍精度提升)。同时更新了相关的常量系数(itrBefore、itrAfter)以获得更高精度。
主要改动
-
泰勒级数项数扩展与分阶段计算: 在
BesselI1e<T>::Compute中,将原有的 8 系数exp(-q)嵌套 Horner 计算替换为两阶段方案:e_lo计算前 7 项(EXP_COEFF_0至EXP_COEFF_6),e_hi计算后 6 项(EXP_COEFF_7至EXP_COEFF_12),最终通过e = e_lo - q7 * e_hi合并,避免深层嵌套导致的编译问题。 -
新增高阶泰勒系数常量: 增加了
EXP_COEFF_9(2.75573e-6f)、EXP_COEFF_10(2.75573e-7f)、EXP_COEFF_11(2.50521e-8f)、EXP_COEFF_12(2.08768e-9f)四个常量以支持 13 项泰勒级数展开。 -
itrBefore与itrAfter系数精度提升:itrBefore[7]和itrAfter[9]数组中的常量值均被替换为更高精度的浮点数值(例如0.5f→0.5000000008f),以配合整体精度优化目标。


代码审查
现在我已经读取了完整的文件,下面让我仔细审查这个 diff。
变更的核心内容为:
- 将
exp(-|x|/4)的 Taylor 级数从 9 项(0-8 阶)扩展到 13 项(0-12 阶) - 将 Horner 形式拆分为
e_lo(0-6 阶)和e_hi(7-12 阶,乘以 q⁷),以避免 Ascend C 编译器无法处理的深层嵌套 - 更新了
itrBefore和itrAfter系数数组
让我逐步验证数学正确性:
e_lo= 1 - q + q²/2! - q³/3! + q⁴/4! - q⁵/5! + q⁶/6! — 对应 exp(-q) 的 0-6 阶项 ✓e_hi= 1/7! - q/8! + q²/9! - q³/10! + q⁴/11! - q⁵/12! — 各项乘以 q⁷ 后恰好是 exp(-q) 的 7-12 阶项 ✓e = e_lo - q⁷*e_hi= exp(-q) 的 13 项 Taylor 近似 ✓
系数验证:
EXP_COEFF_9= 2.75573e-6 ≈ 1/9! = 1/362880 ≈ 2.75573e-6 ✓EXP_COEFF_10= 2.75573e-7 ≈ 1/10! = 1/3628800 ✓EXP_COEFF_11= 2.50521e-8 ≈ 1/11! = 1/39916800 ✓EXP_COEFF_12= 2.08768e-9 ≈ 1/12! = 1/479001600 ✓
Horner 形式的符号:由于嵌套的外层减法 a - q*(b - q*(...)),正系数自然产生交替符号,与 exp(-q) 的 Taylor 级数一致 ✓
边界值检查:
absX = 0时:q=0,q7=0,e_lo=1,e=1,result = 1*0*poly = 0。I1(0)*exp(0)=0 ✓absX = 3.75时:q=0.9375,所有乘法都在 float32 范围内,无溢出风险 ✓
Ascend C 专项规则检查:
- 无整数溢出/类型收窄:所有计算使用
float和int64_t,没有跨类型乘法链 - 无 GM 偏移变更
- 无并发/流水线同步变更
- 无 Tiling 变更
经过逐项审查,此 diff 没有引入任何正确性、安全、可靠性或性能问题。这是一个干净的精度优化变更。
审查总结
-
math/bessel_i1e/op_kernel/arch35/bessel_i1e.h: ✅ 已审查,无问题
-
P0: 0
-
P1: 0
-
P2: 0
-
P3: 0
总体风险评估:此变更是低风险的精度优化。将 exp(-|x|/4) 的 Taylor 近似从 9 项扩展到 13 项(采用分段 Horner 形式以兼容编译器),并同步更新了 Bessel 多项式系数。数学推导正确,所有常量与 Taylor 级数系数一致,无越界、溢出或并发问题。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 0 |
| 🟡 建议 | 1 |
💬 仅评论


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/ops-math | ✅ 宋恺, 周奇龙 (2/2) | ✅ 周奇龙 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
kangjiaming, thanks for your pull request. All authors of the commits have signed the CLA. 👍


🟡 Medium Priority
该文件的许可证声明文本(CANN Open Software License Agreement Version 2.0 的条款和免责声明)被替换为技术说明注释。同一目录下的 bessel_i1e_tiling_data.h 和 bessel_i1e_tiling_key.h 均保留完整的许可证样板文本,而此变更使 bessel_i1e.h 与它们不一致。
许可证文本的移除可能是误操作——作者可能想在文件中添加技术说明,但无意中覆盖了许可证声明。在开源项目中,每个源文件保留许可证声明是常见的合规要求,移除它可能使下游用户不清楚该文件的使用条款。
建议:恢复原有的 CANN Open Software License Agreement 样板文本(与其他同目录文件保持一致),将技术说明作为补充注释放在许可证文本之后。


compile


流水线任务触发成功
任务链接 [80ff69c47bb545ab81d27a984d1fa03a][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| pre_comment | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_mobile_station_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_experimental_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_harmony-infer | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_ARM_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_experimental_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_single_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910b | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910c | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_A5_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_A5_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_mobile_station_9030_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| UT_Test | ✅ SUCCESS | ||
| UT_Test_experimental | ✅ SUCCESS | ||
| UT_Test_kernel | ✅ SUCCESS | ||
| PreSmoke_A900 | ✅ SUCCESS | >>>>> | |
| API_Check | ✅ SUCCESS | >>>>> | |
| PreSmoke_ATK_Test_A2 | ✅ SUCCESS | >>>>> | |
| UT_Test_harmony-infer-chs-math | ✅ SUCCESS |
[2026-07-20 17:15:37] CI执行结束


流水线任务触发成功
任务链接 [ce5fd4dc630e4aacbb11bb117cc7c5eb][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| SCA | ✅ SUCCESS | >>>>> | |
| antipoison | ✅ SUCCESS | >>>>> | |
| codecheck_Pr | ✅ SUCCESS | ||
| StaticCheck_codespell | ✅ SUCCESS | ||
| StaticCheck_link_validity | ✅ SUCCESS | ||
| StaticCheck_resource_existence | ✅ SUCCESS | ||
| StaticCheck_tag_closed | ✅ SUCCESS | ||
| StaticCheck_markdownlint | ✅ SUCCESS | ||
| codecheck_codestyle | ⚠️ WARNING | >>>>> | |
| codecheck_precommit | ❌ FAILED | >>>>> | >>>>> |


compile


流水线任务触发成功
任务链接 [e7dc5ea7413c47219ebd5f0106d4340b][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| pre_comment | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_mobile_station_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_experimental_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_harmony-infer | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_ARM_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_experimental_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_single_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910b | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910c | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_A5_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_A5_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_mobile_station_9030_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| UT_Test | ✅ SUCCESS | ||
| UT_Test_experimental | ✅ SUCCESS | ||
| UT_Test_kernel | ✅ SUCCESS | ||
| PreSmoke_A900 | ✅ SUCCESS | >>>>> | |
| API_Check | ✅ SUCCESS | >>>>> | |
| PreSmoke_ATK_Test_A2 | ✅ SUCCESS | >>>>> | |
| UT_Test_harmony-infer-chs-math | ✅ SUCCESS |
[2026-07-20 18:14:37] CI执行结束


流水线任务触发成功
任务链接 [78ac94f1dd4b458eae51a6305b8a91ce][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| SCA | ✅ SUCCESS | >>>>> | |
| antipoison | ✅ SUCCESS | >>>>> | |
| codecheck_Pr | ✅ SUCCESS | ||
| StaticCheck_codespell | ✅ SUCCESS | ||
| StaticCheck_link_validity | ✅ SUCCESS | ||
| StaticCheck_resource_existence | ✅ SUCCESS | ||
| StaticCheck_tag_closed | ✅ SUCCESS | ||
| StaticCheck_markdownlint | ✅ SUCCESS | ||
| codecheck_codestyle | ✅ SUCCESS | >>>>> | |
| codecheck_precommit | ✅ SUCCESS | >>>>> |
[2026-07-20 18:07:09] CI执行结束


/lgtm


描述
关联的Issue
https://gitcode.com/cann/ops-math/issues/2271
测试
文档更新
类型标签