Merged
docs新增:技术附录新增浮点计算章节 #7321
docs新增:技术附录新增浮点计算章节 #7321
Merged
xuyiyangAdd on 17 days ago
xuyiyang
xuyiyangCollaborators
17 days ago

描述

本文介绍浮点计算在Ascend C中的基本性质、数据类型与运算行为,帮助开发者理解浮点运算的精度特性,在保证精度的前提下充分发挥硬件性能。浮点数只能近似表示实数,相同的运算在不同实现(硬件、计算顺序)下可能产生不同的结果;理解这些特性是编写正确且高性能浮点算子的基础。

章节组织

  • 浮点计算基础:浮点数的IEEE-754编码格式、正规数与非正规数、特殊值、结合律与运算顺序、乘加融合、饱和与溢出处理以及舍入模式。
  • Ascend C数据类型汇总:Ascend C支持的各浮点数据类型的类型总览、数据范围与精度属性,以及FP8与FP4浮点数格式(含MX缩放计算)、hifloat数据格式、HF计算模式等低精度与高性能浮点特性。
  • 浮点操作:按API与编程范式介绍浮点数参与的运算,包括Reg矢量计算、SIMT运算与Cube运算的浮点相关接口及浮点行为差异。

关联的Issue

https://gitcode.com/cann/asc-devkit/issues/1985

测试

无

文档更新

docs/zh/guide/technical_appendix/floating_point_computation/1_floating_point_basics.md
docs/zh/guide/technical_appendix/floating_point_computation/2_ascendc_data_type_summary.md
docs/zh/guide/technical_appendix/floating_point_computation/3_floating_point_operation.md
docs/zh/guide/technical_appendix/floating_point_computation/overview.md
docs/zh/guide/technical_appendix/technical_appendix.md

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for xuyiyang's contribution.)
xuyiyangxuyiyangCollaborators
17 days ago Created pull request, commit ea47a173
atomgit-bot
atomgit-bot
17 days ago Comments:

变更摘要

本 PR 为技术附录新增「浮点计算」章节,系统整理 Ascend C 中浮点数的编码格式、数据类型属性、运算与转换行为,并在技术附录目录 technical_appendix.md 与章节索引 floating_point_computation.md 中接入导航。文档围绕「基础理论—数据类型—实际运算」三层组织,说明浮点近似表示、舍入、饱和溢出等特性如何影响算子结果,并链接到对应的 API 手册。

主要改动

  • 新增章节骨架与目录入口:新增 floating_point_computation.md 章节索引与 overview.md 概述(给出章节组织与阅读建议),并在 technical_appendix.md 中挂载「浮点计算」及其 4 个子页面链接。
- **`1_floating_point_basics.md` 梳理浮点基础规则**:覆盖 IEEE-754 的符号/指数/尾数字段编码、正规数与非正规数(含 `--cce-ftz=true`、`--cce-use-fast-math` 关闭非正规数)、零/无穷/NaN 特殊值、结合律失效与运算顺序、乘加融合(FMA)以及饱和与溢出处理。
  • 饱和与舍入的配置方式文档化:说明全局/单接口饱和策略 SetSaturationStrategy、SetSaturationFlag 的四类 SaturationMode,以及通过 SetCtrlSpr/asc_set_ctrl 直接控制 CTRL 寄存器比特位;同时给出 IEEE-754 四种舍入模式与类型转换接口的 CAST_RINT、CAST_FLOOR、CAST_CEIL、CAST_ROUND、CAST_TRUNC、CAST_ODD、CAST_HYBRID 行为及「源类型—目标类型—支持舍入模式」对照表。
  • 2_ascendc_data_type_summary.md 汇总浮点数据类型:列出 half、bfloat16_t、float、double、各 FP8/FP4 类型与 hifloat8_t 的位分布、取值范围、机器精度 epsilon、特殊值支持与转入/转出饱和行为;并补充 MX 微缩放格式与 MxMatmul/MmadMx 的量化系数矩阵形状、支持类型组合与配置接口,以及 HF32 与 HF 计算模式(SetHF32Mode、SetHF32TransMode、asc_enable_hf32 等)的生效范围与性能收益。
  • 3_floating_point_operation.md 按编程范式拆分运算说明:将浮点运算划分为 Reg 矢量计算、SIMT 运算、Cube 运算三类,分别说明其寄存器/线程/矩阵计算模型与相关 API 层级;并明确 Cube 侧 Mmad 累加恒为 float、Fixpipe 随路量化的饱和由 CTRL[48] 直接决定而不受 CTRL[60] 策略限制。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
17 days ago Comments:

代码审查

审查结论

发现汇总:P2 × 1,P3 × 6,无 P0/P1。

主要风险集中在新文档的数值表格准确性:2_ascendc_data_type_summary.md 表3 的「机器精度(epsilon)」数值与同文第71行给出的定义(2^(1-有效位数))互相矛盾,且 6 行与 2 行 FP4 分别遵循两种不同约定,读者按文档推导精度容差会得到相差 2 倍的结果——这是本批文档中唯一有实质误导性的问题。其余为文档自相矛盾(hifloat8_t inf/NaN 支持性、表1 缺 b64)、符号名笔误(fp8_e4m3_t)、残留草稿文字(「感觉表述有问题」空 NOTE、「硬件乘算几块」残句)以及需确认的图片资源缺失。未发现任何不安全命令、危险配置或供应链误导(本批为纯数学/API 说明文档),也未涉及运行时代码,无编译与安全风险。

逐文件审查确认

  • docs/zh/guide/technical_appendix/floating_point_computation/1_floating_point_basics.md:2 个问题(第72行残留空 NOTE 批注;第17行起 figures 图片资源未随改动提供)。其余数值内容核对通过:表1 位宽/偏置、表2 的 -192 编码、表4 各类型非正规数范围、表5 特殊值编码、NaN 编码计数 2^24-2、结合律与 FMA 示例、表10/表12 舍入与饱和行为、CTRL[48]/[60] 语义在文档内一致。
  • docs/zh/guide/technical_appendix/floating_point_computation/2_ascendc_data_type_summary.md:4 个问题(epsilon 定义与表3 矛盾 P2;表4 hifloat8_t inf/NaN 与第420-421行矛盾 P3;表12 fp8_e4m3_t 类型名笔误 P3;表1 缺 b64 行 P3)。各类型取值范围、subnormal 边界(half 2^-14-2^-24、bfloat16_t 2^-126-2^-133、fp8 各档、fp4 ±0.5/0.25-0.75)、MX 块大小与位宽开销(8.25/4.25 位)核对通过。
  • docs/zh/guide/technical_appendix/floating_point_computation/3_floating_point_operation.md:no issues(VL=256B 与 float 64 个/half 128 个元素一致;Fixpipe 饱和由 CTRL[48] 直接决定、不受 CTRL[60] 限制,与 1_floating_point_basics.md 第337行一致)。
  • docs/zh/guide/technical_appendix/floating_point_computation/floating_point_computation.md:no issues(4 个相对链接目标均存在)。
  • docs/zh/guide/technical_appendix/floating_point_computation/overview.md:no issues(链接与章节描述与正文一致)。
  • docs/zh/guide/technical_appendix/technical_appendix.md:no issues(新增两级目录的缩进层级与既有 concepts_and_terms、cpp_standard_support 章节风格一致,无重复条目)。

补充说明(未作为问题上报)

2_ascendc_data_type_summary.md 的表/图编号次序错乱(表10~表12 出现在表8/表9 之前,图7~图13 出现在图4~图6 之前),属于版式编号问题,按规则未计入 finding;若发布要求严格的交叉引用编号,建议一并重排。

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

💬 仅评论

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

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies 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. 👍

likedislike
281 messages are collapsed here。 See more
CANN-robotCANN-robotCollaborators
8 days ago Added label: ci-pipeline-passed
louyuxuan
louyuxuanCollaborators
8 days ago Comments:

/lgtm

likedislike
ai_xin
ai_xinCollaborators
8 days ago Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
8 days ago Added label: lgtmapproved
CANN-robotCANN-robotCollaborators
8 days ago Merged pull request