Merged
修复基础API、CAPI PRELU公式和边界场景说明 #7007
LycheeeeeAdd on 11 days ago
修复基础API、CAPI PRELU公式和边界场景说明 #7007
Merged
LycheeeeeAdd on 11 days ago
LycheeeeeCollaborators
11 days ago

描述

修复基础API、CAPI PRELU公式和边界场景说明

关联的Issue

测试

文档更新

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for Lycheeeee's contribution.)
LLycheeeeeCollaborators
11 days ago Created pull request, commit 76afdec0
atomgit-bot
atomgit-bot
11 days ago Comments:

变更摘要

本 PR 为文档修订,统一修正 PReLU 相关接口说明中零值边界的判定规则:将原先「大于 0 直接输出、小于等于 0 相乘」改为「大于等于 0 直接输出、小于 0 相乘」,并补充浮点数正零(+0)与负零(-0)的处理约定。改动覆盖 SIMD-API 基础 API 的 Prelu 与 C API 融合计算接口 asc_prelu 两处文档,使公式、正文描述与约束说明保持一致。

主要改动

  • Prelu 公式边界修正:docs/zh/api/SIMD-API/basic_api/reg_vector_compute/basic_arithmetic/Prelu.md 中的计算公式由 srcReg0_i > 0 / srcReg0_i \leq 0 调整为 srcReg0_i >= 0 / srcReg0_i < 0,即零值归入直接输出分支。
  • Prelu 有符号零处理说明:正文新增说明,srcReg0 为浮点正零(+0)时按正数直接输出,为浮点负零(-0)时按负数处理并与 srcReg1 相乘。
  • Prelu 约束说明补充:约束说明 章节由「无」改为明确 +0 直接输出、-0 与 srcReg1 相乘且乘法满足 IEEE 754 浮点乘法规则。
  • asc_prelu 公式与描述同步修正:docs/zh/api/SIMD-API/c_api/reg_compute/reg_fused/asc_prelu.md 的公式改为 src0_i >= 0 / src0_i < 0,正文中的边界描述与有符号零处理说明同步更新。
  • asc_prelu 计算约束更新:计算约束 由仅说明负零按负数处理,扩展为同时说明正零(+0)直接输出、负零(-0)与 alpha 相乘并遵循 IEEE 754 浮点乘法规则。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
11 days ago Comments:

代码审查

审查结论

按文件确认(共 2 个文件,均已逐一审查):

  1. docs/zh/api/SIMD-API/basic_api/reg_vector_compute/basic_arithmetic/Prelu.md — 发现问题 2 项(P2×2):公式 >= 0 无法表达「-0 归负分支」,与新增文字说明自相矛盾;概览页 overview.md:28 与索引页 basic_api_list.md:348 仍保留旧公式/旧文案,单边改动造成同接口两套口径。
  2. docs/zh/api/SIMD-API/c_api/reg_compute/reg_fused/asc_prelu.md — 发现问题 3 项(P2×2、P3×1):公式条件与 -0 说明矛盾;C API 索引页 c_api.md:497 仍写「大于0」且参数名仍为 src1;调用示例期望值判定仍用 > 0.0f,与新的 >= 0 契约不一致。

优先级统计: P0 = 0,P1 = 0,P2 = 4,P3 = 1。

整体风险判断: 本次仅文档改动,不含代码/配置/依赖变更,无引入安全风险(未新增危险命令、弱权限、明文密钥等内容),也无破坏构建的语法问题。核心问题是「同一接口的零值边界契约在多处文档中只改了一半」以及「分段公式用 IEEE 比较运算符表达符号位语义,导致公式与文字说明互斥」——会让用户按概览页/索引页/示例写出与详情页契约相反的边界处理代码,需在合入前统一口径。

类型 数量
🔴 阻塞 0
🟡 建议 4

💬 仅评论

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
11 days ago Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
11 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
docs ✅ munanhw, wuyang_hw (2/2) ✅ munanhw (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robot
CANN-robotCollaborators
11 days ago Comments:

CLA Signature Pass

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

likedislike
LycheeeeeCollaborators
11 days ago Comments:

compile

likedislike
CANN-robotCANN-robotCollaborators
11 days ago Set zengjuan,zhanghao_0689,suqwe,wulinyu,kong0808,dengjing_aoe,YeZZzzz1,bluesky901,yangbinhua,zhudi22,chenyiyuan,xun_zhuge,XuebinYang,sjtulxh,bianque,houyuyang,YANXI_ZHAO,chentianyu19,shi_nanxiang,wuyang_hw,jiangxinyu3,munanhw,ai_xin,ascendhjh,hujiawen_kaven,wangxiaozhi,DragonBornHD84,louyuxuan,hyolee,yukangchen as approver
CANN-robotCANN-robotCollaborators
11 days ago Set bianque,munanhw,ai_xin,ascendhjh as approver
LLycheeeeeCollaborators
11 days ago Pre merge succeeded (commit_id: a8ac2dd3299a62294813bf54770194e8a72b2f6e)
CANN-robot
CANN-robotCollaborators
11 days ago Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
11 days ago Added label: ci-pipeline-running
atomgit-bot
atomgit-bot11 days agoStart code review1
docs/zh/api/SIMD-API/basic_api/reg_vector_compute/basic_arithmetic/Prelu.md
@@ -45,3 +45,3 @@
4545 
4646$$
47-dstReg_i = \begin{cases} srcReg0_i & srcReg0_i > 0 \\ srcReg0_i \times srcReg1_i & srcReg0_i \leq 0 \end{cases}
47+dstReg_i = \begin{cases} srcReg0_i & srcReg0_i >= 0 \\ srcReg0_i \times srcReg1_i & srcReg0_i < 0 \end{cases}
atomgit-bot
atomgit-bot11 days agoComments:

🟡 Medium Priority

本次只改了 Prelu.md 的分段条件(> 0/\leq 0 → >= 0/< 0),但同一接口在其他文档中的公式与描述仍是旧形式:

失败模式:同一接口现在存在两套互斥的公式——概览页与索引页把 srcReg0 == 0 判到乘法分支,详情页判到直接输出分支。用户在概览页速查或由索引页跳转时,对零值边界(尤其本次新增强调的 +0/-0)会得到与详情页相反的结论,导致按概览页写出的边界处理代码与详情页契约不符。这类「契约在一侧改了、兄弟文档保留旧形态」的不一致属于本次改动单边引入。

建议:同步更新 overview.md:28 的 Prelu 公式(改为与详情页一致的条件,并同步 -0 归负说明)与 basic_api_list.md:348 的描述文案(「大于0」改为「大于等于0」,或直接改为「非负(含 +0)时直接输出」),保证概览、索引与详情页三处口径一致。

likedislike
Incorrect?
atomgit-bot
atomgit-bot11 days agoStart code review1
docs/zh/api/SIMD-API/basic_api/reg_vector_compute/basic_arithmetic/Prelu.md
@@ -45,3 +45,3 @@
4545 
4646$$
47-dstReg_i = \begin{cases} srcReg0_i & srcReg0_i > 0 \\ srcReg0_i \times srcReg1_i & srcReg0_i \leq 0 \end{cases}
47+dstReg_i = \begin{cases} srcReg0_i & srcReg0_i >= 0 \\ srcReg0_i \times srcReg1_i & srcReg0_i < 0 \end{cases}
atomgit-bot
atomgit-bot11 days agoComments:

🟡 Medium Priority

改动把分段条件从 srcReg0_i > 0 / srcReg0_i \leq 0 改为 srcReg0_i >= 0 / srcReg0_i < 0,同时在第 44、86 行新增说明「+0 按正数直接输出,-0 按负数并乘 srcReg1」。

问题在于:按 IEEE 754 比较语义,-0 >= 0 为真、-0 < 0 为假,即新公式把 -0 判到「直接输出」分支;而第 44/86 行的文字说明要求 -0 走乘法分支。二者互相矛盾。第 44/86 行的行为只能由符号位判定(signbit)实现,而不是由 >=/< 比较实现。

失败模式:用户按公式编写参考实现/校验代码 src >= 0 ? src : src * alpha,在 src 为 -0 且 alpha 为负数时,参考实现得到 -0(直接输出),硬件按文字说明得到 +0(=-0 × 负斜率),符号零不一致,进而影响后续 1/x(±inf)、log 等运算,导致自测误判或下游数值异常。校验示例第 208 行正是这种写法。

另外该行用 ASCII >= 而非与仓库其他文档一致的 LaTeX 记法 \geq,渲染排版不一致。

建议:把分段条件改为按符号位判定,并明确 +0/-0 的归属,使其与第 44/86 行文字一致,例如将两个分支条件写成 \operatorname{sign}(srcReg0_i) \geq 0(含 +0)与 \operatorname{sign}(srcReg0_i) < 0(含 -0),或在公式后紧跟一句「分支由符号位判定,+0 归正、-0 归负」;同时把 >= 改为 \geq。

likedislike
Incorrect?
atomgit-bot
atomgit-bot11 days agoStart code review1
docs/zh/api/SIMD-API/c_api/reg_compute/reg_fused/asc_prelu.md
@@ -35,2 +35,2 @@
35-src0_i, & src0_i > 0 \\
36-src0_i \times \alpha_i, & src0_i \leq 0
35+src0_i, & src0_i >= 0 \\
36+src0_i \times \alpha_i, & src0_i < 0
atomgit-bot
atomgit-bot11 days agoComments:

🟡 Medium Priority

asc_prelu.md 的公式条件改为 src0_i >= 0 / src0_i < 0(第 35、36 行),但第 31、102 行新增文字要求「+0 直接输出、-0 按负数并与 alpha 相乘」。

按 IEEE 754 比较语义,-0 >= 0 为真、-0 < 0 为假,即公式把 -0 归入「直接输出」分支,与第 31/102 行的说明(-0 走乘法分支)矛盾;说明所述行为只能由符号位判定实现,无法用 >=/< 表达。

失败模式:用户以公式为准编写参考实现或精度比对脚本 src0 >= 0 ? src0 : src0 * alpha,在 src0 为 -0 且 alpha 为负时得到 -0,而硬件按说明得到 +0,符号零不一致,会使自测误判或让下游 1/x、log 等产生 ±inf 差异。对照 asc_leakyrelu.md:99 与 tensor_api/.../prelu.md:74 均以「负零按负数处理」表述,说明仓库内约定是按符号位判定,本条公式与之不符。

建议:将分段条件改为按符号位判定以与第 31/102 行说明一致(如 \operatorname{sign}(src0_i) \geq 0 含 +0 / \operatorname{sign}(src0_i) < 0 含 -0),或在公式后补一句「分支由符号位判定,+0 归正、-0 归负」;同时把 ASCII >= 改成与仓库其他文档一致的 LaTeX \geq。

likedislike
Incorrect?
atomgit-bot
atomgit-bot11 days agoStart code review1
docs/zh/api/SIMD-API/c_api/reg_compute/reg_fused/asc_prelu.md
@@ -29,3 +29,3 @@
2929头文件路径为:`"c_api/reg_compute/compute/reg_fused.h"`。
3030 
31-根据掩码对源操作数矢量数据寄存器`src0`中的元素执行PReLU(Parametric ReLU)运算,负半轴斜率由矢量数据寄存器`alpha`中的对应元素指定,并将结果通过函数返回值返回或写入目的操作数矢量数据寄存器。`src0`大于0时直接写入输出结果,否则将`src0`与`alpha`相乘后写入输出结果。掩码对应位置为1的元素参与计算,为0的元素在输出结果中置零。计算公式如下:
31+根据掩码对源操作数矢量数据寄存器`src0`中的元素执行PReLU(Parametric ReLU)运算,负半轴斜率由矢量数据寄存器`alpha`中的对应元素指定,并将结果通过函数返回值返回或写入目的操作数矢量数据寄存器。`src0`大于等于0时直接写入输出结果,否则将`src0`与`alpha`相乘后写入输出结果。注:源矢量数据寄存器中数据为浮点数正零(+0)时按正数处理并直接输出;为浮点数负零(-0)时按负数处理并与`alpha`相乘。掩码对应位置为1的元素参与计算,为0的元素在输出结果中置零。计算公式如下:
atomgit-bot
atomgit-bot11 days agoComments:

🟡 Medium Priority

本次只改了详情页 asc_prelu.md 的分支条件与零值说明(第 31、35-36、102 行),但 C API 索引页 docs/zh/api/SIMD-API/c_api/c_api.md:497 仍是旧口径:

|[asc_prelu](reg_compute/reg_fused/asc_prelu.md)|源操作数src0大于0的情况下直接将src0写入目的操作数dst,否则将src0 * src1的结果写入dst。|

失败模式:索引页把 src0 == 0 判到乘法分支,详情页判到直接输出分支,同一接口在两页给出相反的零值契约;用户从 c_api.md 速查接口语义时无法得知本次修正的 +0/-0 边界行为,按索引页写的边界用例会按旧语义构造期望值。此外索引页的 src1 参数名与详情页的 alpha 也不一致(历史遗留,本次改动使两页口径差距进一步扩大)。

建议:同步更新 docs/zh/api/SIMD-API/c_api/c_api.md:497 的 asc_prelu 描述为「源操作数 src0 大于等于 0(含 +0)时直接写入 dst,否则将 src0 与 alpha 相乘后写入 dst」,并把参数名 src1 改为 alpha,使其与详情页契约一致。

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
11 days ago Removed label: ci-pipeline-running
7 event messages are collapsed here。 See more
CANN-robotCANN-robotCollaborators
11 days ago Removed label: ci-pipeline-passed
CANN-robot
CANN-robotCollaborators
11 days ago Comments:

Notification

This pull request has been changed(code update) or closed, so removes the following label(s): ci-pipeline-passed.

likedislike
LycheeeeeCollaborators
11 days ago Comments:

compile

likedislike
LLycheeeeeCollaborators
11 days ago Pre merge succeeded (commit_id: ddb77ffffce4aec91cfb3fb0ca04597d1e834a84)
LLycheeeeeCollaborators
11 days ago Resolved final issue
CANN-robot
CANN-robotCollaborators
11 days ago Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
11 days ago Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
11 days ago Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
11 days ago Added label: ci-pipeline-passed
LycheeeeeCollaborators
11 days ago Comments:

compile

likedislike
CANN-robot
CANN-robotCollaborators
11 days ago Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
11 days ago Removed label: ci-pipeline-passed
CANN-robotCANN-robotCollaborators
11 days ago Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
11 days ago Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
11 days ago Added label: ci-pipeline-passed
munanhwCollaborators
11 days ago Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
11 days ago Added label: approved
吴洋Collaborators
11 days ago Comments:

/lgtm
/approve

likedislike
CANN-robot
CANN-robotCollaborators
11 days ago Comments:

The following users do not have permission to comment /lgtm or /approve on any module in this PR:
/approve: wuyang_hw

likedislike
CANN-robotCANN-robotCollaborators
11 days ago Added label: lgtm
CANN-robotCANN-robotCollaborators
11 days ago Merged pull request