Merged
feat: AngleV2算子新增ascend960dt平台适配 #7018
miaojingjingAdd on 8 days ago
feat: AngleV2算子新增ascend960dt平台适配 #7018
Merged
miaojingjingAdd on 8 days ago
miaojingjing
miaojingjingCollaborators
8 days ago

描述

本次变更为 AngleV2 增加 ascend960dt 平台适配:复用 A5 OpDef 配置,补齐 960DT binary 与 simplified key 配置,扩展 BF16 kernel 分发及测试数据/tiling 生成,并将 960DT 纳入 op_kernel UT 编译范围。同时完成 PR 变更文件的格式化、文件末尾换行和许可证头合规整改。

改动原因

  • AngleV2 的 OpDef 尚未注册 ascend960dt,且缺少对应的 binary 与 simplified key 配置。
  • BF16 原生比较分发分支仅覆盖 __NPU_ARCH__ == 3510,未覆盖 960DT 对应的 __NPU_ARCH__ == 9201。
  • op_kernel UT 的 SoC 列表未包含 ascend960dt,测试数据与 tiling 生成脚本缺少 BF16 处理逻辑。

改动方法

1. Host 侧平台与 binary 配置

  • 在 math/angle_v2/op_host/angle_v2_def.cpp 中新增 this->AICore().AddConfig("ascend960dt", aicore_a5_config),复用 ascend950 的 A5 配置;该配置启用 DynamicCompileStaticFlag、DynamicFormatFlag、DynamicRankSupportFlag 和 DynamicShapeSupportFlag。
  • 新增 math/angle_v2/op_host/config/ascend960dt/angle_v2_binary.json,包含以下 10 组输入/输出映射。所有输入 x 与输出 y 均为 required、ND、shape: [-2]、format_match_mode: FormatAgnostic:
输入 dtype 输出 dtype bin_filename
complex64 float32 AngleV2_5cfa8f3b14716c3317bcd193933a3613
float32 float32 AngleV2_1946086cc5d1bc19a4d66b5bd48e62cd
bfloat16 bfloat16 AngleV2_bf16
float16 float16 AngleV2_a8c107f79de7b47ce419f0ec015539f7
bool float32 AngleV2_bool
uint8 float32 AngleV2_uint8
int8 float32 AngleV2_int8
int16 float32 AngleV2_int16
int32 float32 AngleV2_int32
int64 float32 AngleV2_int64
  • 新增 math/angle_v2/op_host/config/ascend960dt/angle_v2_simplified_key.ini,设置 [AngleV2] default=0。

2. Kernel 侧 BF16 分发

  • 在 math/angle_v2/op_kernel/angle_v2.cpp 中,将 BF16 原生比较分支的编译条件扩展为 (__NPU_ARCH__ == 3510) || (__NPU_ARCH__ == 9201)。
  • 上述架构下,KEY_DTYPE_BF16(tiling key 10)继续调用 AngleV2N::AngleV2<bfloat16_t>。
  • __NPU_ARCH__ == 2201 的既有路径保持不变,仍调用 AngleV2N::AngleV2Bf16<bfloat16_t, bfloat16_t>;其他 dtype 的分发逻辑未修改。

3. UT 与测试数据/tiling 生成

  • math/angle_v2/tests/ut/op_kernel/CMakeLists.txt:AddOpTestCase 的 SoC 列表扩展为 ascend910b;ascend950;ascend960dt。
  • angle_v2_data/gen_data.py:新增 BF16 分支,生成 [-100, 100] 范围内的 float32 随机输入并转换为 BF16;golden 通过 torch.angle(inputX.float()).to(torch.bfloat16) 计算,输入与 golden 均通过 view(torch.int16) 写出二进制文件。
  • angle_v2_data/gen_tiling.py:新增 torch.bfloat16 映射及 bytesPerData["bfloat16"] = 15;BF16 与 FP16 共用 2 字节对齐计算(ALIGN_NUM = 16)和 dataPerRepeat = 128 的计算路径。
  • test_angle_v2.cpp:在 3510/9201 条件下新增 test_case_bf16,采用单 block、tiling key 10,并设置 totalLength=16、formerNum=1、tailNum=47、formerLength=16、tailLength=0、alignNum=16、totalLengthAligned=16、tileLength=12160、dataPerRepeat=128。

4. 合规与格式化

  • 对 test_angle_v2.cpp 应用 clang-format,对两个 Python 脚本应用 ruff 格式化和空白行等格式整改。
  • 为 angle_v2_binary.json、angle_v2_simplified_key.ini、UT CMakeLists.txt 和 gen_data.py 补齐文件末尾换行。
  • 按 OAT 要求更新 gen_data.py 与 gen_tiling.py 的许可证头。

关联的Issue

测试

  • 已对 PR 的全部 8 个变更文件执行 pre-commit run --files $(git diff --name-only upstream/master...HEAD),所有适用钩子均通过,包括 trailing whitespace、end-of-file-fixer、大文件检查、冲突检查、私钥检查、JSON 检查、clang-format、ruff-check、ruff-format、codespell 和 OAT;check-yaml 因本 PR 无 YAML 文件而跳过。
  • git diff --check 通过。
  • 本次检查未执行二级冒烟、算子泛化或 960DT 上板 UT/ST,PR 中亦未提供这些测试的结果记录。

文档更新

无文档更新;本 PR 未修改 README 或其他文档文件。

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for miaojingjing's contribution.)
miaojingjingmiaojingjingCollaborators
8 days ago Created pull request, commit 6fe1bccd
atomgit-bot
atomgit-bot
8 days ago Comments:

变更摘要

本 PR 为 angle_v2 算子新增 ascend960dt 平台(对应 __NPU_ARCH__ == 9201)的适配:在算子原型定义中复用 aicore_a5_config 注册该平台配置;在 kernel 侧将 bf16 原生比较分支的编译条件从仅 3510 扩展为 3510 或 9201;并补充了 bf16 数据生成、tiling 生成与 UT 用例,使 bf16 路径在新架构下可被测试验证。

主要改动

  • 新增 960DT 平台配置注册: 在 angle_v2_def.cpp 中通过 this->AICore().AddConfig("ascend960dt", aicore_a5_config) 为 ascend960dt 复用 A5 的 AICore 配置。
  • 扩展 bf16 kernel 分支的架构条件: angle_v2.cpp 中将 KEY_DTYPE_BF16 分支的编译开关由 __NPU_ARCH__ == 3510 改为 3510 或 9201,使 960DT 支持 AngleV2<bfloat16_t> 的 bf16 原生比较实现。
  • 补充 bf16 测试数据生成: gen_data.py 新增 bfloat16 分支,按 float32 生成随机输入后转为 bf16,并以 torch.angle 计算 golden,按 int16 视图写入 input_x.bin 与 golden.bin。
  • 补充 bf16 tiling 参数生成: gen_tiling.py 在 dtype 映射与对齐/重复相关逻辑中加入 bfloat16,使其与 float16 使用相同的 2 字节对齐与 dataPerRepeat 计算方式。
  • 新增 bf16 UT 用例: test_angle_v2.cpp 在 3510/9201 架构下新增 test_case_bf16,设置 bf16 对应 tiling 字段与 tiling key(10),调用 angle_v2 完成单 block 端到端校验流程。

🧩 本次 Review 已使用自定义 Skill:

likedislike
Incorrect?
CANN-robot
CANN-robotCollaborators
8 days ago Comments:

Hi @miaojingjing, welcome to submitting your first PR to CANN!

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
atomgit-bot
atomgit-bot
8 days ago Comments:

代码审查

检视结论

问题统计:P0 × 0,P1 × 0,P2 × 1,P3 × 1

已上报问题

  1. P2(confidence 0.6) math/angle_v2/op_host/angle_v2_def.cpp:97 — 新增 AddConfig("ascend960dt", ...) 后未同步补齐 op_host/config/ascend960dt/angle_v2_binary.json。本算子原有 6 个 soc 均一一对应配置目录(12 个文件),且仓内约 109 个已支持 960DT 的算子(math/*/op_host/config/ascend960dt/** 共 218 个文件)全部具备该配置,本算子成为唯一例外;960DT 侧可能因此缺少 kernel binary / simplified key 映射。
  2. P3(confidence 0.5,可选改进) math/angle_v2/tests/ut/op_kernel/test_angle_v2.cpp:114-123 — 新增 bf16 用例硬编码 tailNum=47 / tileLength=12160 / dataPerRepeat=128(隐含 48 核 + 192000B UB),且全程不与 golden.bin 比对,无法为本次新增的 __NPU_ARCH__ == 9201 bf16 分支提供有效回归保护。

逐文件检视确认

  • math/angle_v2/op_host/angle_v2_def.cpp — 1 个 P2(见上)。
  • math/angle_v2/op_kernel/angle_v2.cpp — 无问题。已核实 9201 即 DAV_9201(960DT,仓内 reduce_std_v2_update/tanh_grad 注释可证),新增分支与 950(3510)共用通用模板 AngleV2<bfloat16_t>(angle_v2.h 内为与架构无关的 Compare/Select 通用实现),#elif (__NPU_ARCH__ == 2201) 旧路径未受影响,BF16 tiling key 10 与 SetTilingKeyMode 的 BF16_MODE 对应一致。
  • math/angle_v2/tests/st/arch35/ttk_aclnn_angle_v2_st.csv — 无问题。列结构与仓内其他 36 个 ttk_aclnn_*_st.csv 一致,dtype 组合与 aclnn 接口/算子定义匹配。
  • math/angle_v2/tests/st/arch35/ttk_kernel_angle_v2_st.csv — 无问题。25 列结构与 sqrt_grad 等同目录用例一致,bf16 精度 0.004、fp16 0.002、fp32 1e-4 设置合理。
  • math/angle_v2/tests/ut/op_kernel/CMakeLists.txt — 无问题。仅按注释约定扩展 param2 的 soc 分号列表,AddOpTestCase 参数个数与引号均正确,tiling 依赖文件未变。
  • math/angle_v2/tests/ut/op_kernel/angle_v2_data/gen_data.py — 无问题。新增 bf16 分支置于 else 前、提前 return 避免落到后续 astype(np.bfloat16) 报错,view(torch.int16) 对同宽 bf16 合法,写入字节数(16 元素 × 2B)与 UT 申请的 32B 一致。
  • math/angle_v2/tests/ut/op_kernel/angle_v2_data/gen_tiling.py — 无问题。torch.bfloat16 与 bytesPerData["bfloat16"]=15 与 host tiling 非 2201 分支(2+2+1+3×2=15)一致,ALIGN_NUM=16、dataPerRepeat=128 与 kernel mask/bf16 原生比较相符;其中 formerLength 的浮点截断与 C++ 整型除法不一致属未改动的既有偏差,测试已覆盖该字段,非本次引入。
  • math/angle_v2/tests/ut/op_kernel/test_angle_v2.cpp — 1 个 P3(见上)。

总体风险判断

改动方向正确、风险可控:kernel 侧的 9201 扩展是纯新增分支,不改变既有 910B/910/950 行为;主要遗留风险在于 op_host 配置侧未随 960DT 声明同步补齐,可能使本 PR 的 960DT 适配在编译/打包环节拿不到 kernel binary,建议合并前确认。

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

💬 仅评论


🧩 本次 Review 已使用自定义 Skill:

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
8 days ago Added label: cann-cla/yes
78 messages are collapsed here。 See more
chenyifengCollaborators
4 days ago Comments:

您好,PR已满足合入指标,请尽快联系Committer进行合入。如暂时不需要合入,请在PR标题前加[WIP]

likedislike
TangPC
TangPCCollaborators
4 days ago Comments:

/lgtm
/approve

likedislike
CANN-robotCANN-robotCollaborators
4 days ago Added label: lgtm
CANN-robotCANN-robotCollaborators
4 days ago Closed associated issue
CANN-robotCANN-robotCollaborators
4 days ago Merged pull request