Merged
fix(math): handle atan2 zero boundaries in experimental kernel #6218
fix(math): handle atan2 zero boundaries in experimental kernel #6218
Merged
puppyAdd on Oct 11
puppy
puppy
Oct 11

描述

experimental Atan2 的 epsilon 符号近似使 atan2(+0,-1) 返回 0,预期为 π;原点的 0/0 则返回 NaN,与该算子 README 定义的原点结果 +0 不符。

改为精确比较选择象限,并从分子符号位形成 ±1,保留负半轴上的 ±π 和正半轴上的带符号零;所有原点 signed-zero 组合显式选择 +0。BF16 结果为 NaN 时写回 quiet-NaN 编码,使特殊值语义不依赖 FP32 到 BF16 的 narrowing 行为。

复用现有临时缓冲,host tiling 额外预留 8 KiB Select 临时空间,tile 按 64 个 FP32 元素对齐,并初始化短 core / 尾块最后一个比较 repeat。新增最小 UB 容量检查和边界回归,保留有限值、NaN、带符号零断言;现有 FP16 随机 UT 也检查数据生成、读写及比对状态,覆盖全部 8192 个输入元素。

CMake 为随机用例显式传入原始数据目录的绝对路径,再复制数据脚本,避免依赖构建 / 测试工作目录;复制、生成、读取与精度比对失败均保持断言。

主机侧改为显式缓冲区预算的纯调度函数:三路双缓冲队列、五路 FP32 scratch、Atan 临时空间和固定 8 KiB Select 预留分别计入 UB;统一计算大小核及尾 tile,保留原调度数据格式,拒绝超出内核 uint32_t 偏移范围的输入。图上下文适配只创建一个平台对象,统一读取资源和 workspace,消除原来分散重复的平台、类型与分块处理。原版权、许可证、检查规则与精度断言均保留。

关联的Issue

Fixes #3471
https://gitcode.com/cann/ops-math/issues/3471

测试

对应当前 HEAD b4ad3d285b49aa6fde63954b318390c9a12c8105,在 HiDevLab 的 A3 单卡 / CANN 9.0.0 环境完成:

  • 原生 host tiling UT 6/6,0 failure / error / disabled。覆盖 FP16、BF16、FP32 的固定 UB 与独立 golden,大小核分配、tile/tail 覆盖、UB 最小预算和偏移溢出检查。
  • CANN tikicpulib kernel UT 4/4,0 failure / error / disabled。保留 FP32/FP16/BF16 的有限值、NaN、signed-zero 和短 repeat 断言,以及原有 FP16 随机 8192 元素数据生成、读写与精度比对。
  • 工作目录独立性回归:在全新嵌套构建目录和含空格目录分别运行完整 kernel UT,均 4/4 通过,所有用例实际执行、无跳过;同时包含真实算子 CMake 配置,将 __FILE__ 裁剪为 basename 并核对实际预处理宏,覆盖 CI 的编译路径改写;两个目录均不存在旧版所依赖的相对数据路径。
  • 真实 A3 单卡 54/54 组 native ASC 回归,退出码均为 0、设备同步成功、结果错误为 0。直接运行当前生产 kernel,并由当前生产 BuildSchedule 生成全部分块参数;覆盖三种精度、单卡内 1 / 3 个 vector 核、四象限、零轴、原点、NaN、短 core / 尾块、完整 tile 加尾块,以及实际可用 UB 和较小 UB 预算。SDK 查询到可用 UB 为 196352 字节,设备有 48 个 AIV 核;测试仅使用逻辑设备 0。
  • 另在本机用独立旧版公式对照 1,152 组调度结果,全部一致,并验证资源不足和 uint32_t 偏移溢出拒绝行为。
  • 仓库规定的 clang-format 18.1.8、pre-commit 适用检查及整个 PR 范围 git diff --check 通过。

最终源码 / 测试文件均按 SHA256 核对。54 组硬件回归与最终 CPU 回归使用的全部生产源码字节一致;完整原始日志、退出状态、GoogleTest XML、运行脚本及 manifest 已归档。归档 SHA256:a0992d5b4b9d30daf2c70c40f0d8fbd727cd36b375509191c4c89092461482bc。

工作目录回归的补充归档 SHA256:fb11e139b9169b0606d6f1d73567260a639cdffc7e3667079d615a970f656302;对应最新源码 manifest SHA256:46c9194d13a1327e53dd7411b4559e51af7cf5a478f2a52cb3bb6179e3bd6bf5。

本地 OAT hook 要求的 Invalid File Type / License Header Invalid 均为 0。原始 OAT 另报 Huawei Device / Huawei Technologies 版权 policy 差异,已保留报告;未改变版权归属或扫描规则。当前提交的社区 CI/SCA 结果以对应流水线为准。

验证范围为原生 host UT、CPU 内核 UT,以及生产 kernel 和生产调度参数的真实单卡执行;未运行完整 ACLNN/C API 自定义算子包调度,未宣称全仓或其他架构硬件回归通过。

文档更新

README 明确负半轴的 ±0 对应 ±π、值域 [−π,π],以及所有原点 signed-zero 组合返回 +0。

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for puppy's contribution.)
puppypuppy
Oct 11 Created pull request, commit 365d292c
puppypuppy
Oct 11 Associated issue: [Bug-Report|缺陷反馈]: experimental Atan2 在负半轴零输入返回0,在原点返回NaN
CANN-robot
CANN-robotCollaborators
Oct 11 Comments:

Hi @hanggongmao1, welcome to submitting your first PR to ops-math!

PR Merge Steps

1. CLA Signing

If the current PR label includes cann-cla/yes, it means you have signed the CLA and can proceed to the next step. If the label includes cann-cla/no, please sign the CLA first. If you have any questions, please refer to the FAQ.

2. CI Check

Please comment /compile to trigger the CI pipeline check. If the CI run is successful, the PR will be tagged with ci-pipeline-passed and you can proceed to the next step. If the CI run fails, the PR will be tagged with ci-pipeline-failed, please check the CI logs to fix the issues in the PR. If you have any questions, please refer to the FAQ.

3. Code Review

After CI passes, please refer to the PR Approval Progress and proactively @ the committers in the table to review the code. After approval, committers will comment /lgtm and /approve. Once the lgtm and approved labels are successfully added, the PR will be merged automatically.

likedislike
CANN-robotCANN-robotCollaborators
Oct 11 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Oct 11 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
experimental ✅ 顾宝成, yue-ma (2/2) ✅ 顾宝成, yue-ma (2/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
94 messages are collapsed here。 See more
CANN-robotCANN-robotCollaborators
5 days ago Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
5 days ago Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
5 days ago Added label: ci-pipeline-passed
CANN-robotCANN-robotCollaborators
5 days ago Closed associated issue
CANN-robotCANN-robotCollaborators
5 days ago Merged pull request