Pull Request已成功合入, 合并人@CANN-robot
(感谢 xiu_ling_wang 的贡献)变更摘要
该 PR 将 polar 算子从基于 broadcast 框架的 SIMD 实现回退到自定义 SIMT(单指令多线程)实现。原实现依赖 BroadcastBaseTiling / BroadcastSch 等 broadcast 基础设施,通过 PolarBrcDag 定义 DAG 流水线并使用 CopyInBrc 广播拷贝。回退后,tiling 逻辑改为手动实现:自行完成 dtype 校验、多维 shape 广播与归并、stride 计算、多核切分,并将 tilingData 通过 memcpy_s 写入 raw tiling data。kernel 侧则移除了 polar_dag.h / polar.h,新增 polar_simt.h,使用 asc_vf_call + Simt::Cos/Simt::Sin 直接在 GM 上完成 polar 计算,不再依赖 broadcast 调度和 UB 上的 SIMD 向量指令。
主要改动
-
Tiling 逻辑重写:
polar_tiling.cpp移除对BroadcastBaseTiling<PolarBrcDag>的调用,改为手动实现CheckDtype(校验输入为DT_FLOAT、输出为DT_COMPLEX64)、CheckBroadcastAndMergeShape(多维广播形状归并)、CalcStride(计算各输入的 broadcast stride),并在PostTiling中通过memcpy_s将PolarTilingData写入 raw tiling data,同时设置 workspace 为 0 和blockDim。 -
Tiling 数据结构变更:
polar_struct.h删除对broadcast_base_struct.h的依赖及BRC_TEMP_SCH_MODE_KEY模板参数,新增PolarTilingData结构体,包含totalElements、elementsPerCore、coreNum、formerCore、dimNum以及mergedStride/absStride/angleStride/yStride四个 stride 数组(最大维度POLAR_MAX_DIM=8)。 -
Kernel 实现从 SIMD 迁移到 SIMT:删除
polar_dag.h(含PolarMerge和PolarBrcDag的 DAG 定义)和polar.h(BroadcastSch入口),新增polar_simt.h,其中PolarSimt<float>类通过asc_vf_call调用SimtPolarCompute,在 GM 上使用Simt::Cos/Simt::Sin逐元素计算,并基于 stride 数组手动计算多维 broadcast 偏移。 -
Kernel 入口调整:
polar_apt.cpp不再 includepolar.h,改为 includepolar_simt.h和polar_struct.h,kernel 函数直接实例化PolarSimt<float>并调用Init+Process。 -
测试预期值更新:测试用例中所有
expectTilingKey从 8 改为 0,expectWorkspaces从{16777216}改为{0},并新增 dtype 不匹配的失败测试(输入DT_BF16和输出DT_FLOAT场景)。


代码审查
审查完成
我已完成对所有 6 个变更文件的逐行审查。以下是我的结论:
发现的问题
仅发现 1 个 P3 级别的问题:
polar_tiling.cpp:185:Tiling4Polar函数中 tiling 失败时使用OP_LOGD(debug 级别)而非OP_LOGE(error 级别)记录日志,生产环境中可能难以排查 tiling 失败问题。
各文件审查结论
| 文件 | 结论 |
|---|---|
math/polar/op_host/arch35/polar_tiling.cpp |
1 个 P3 问题(日志级别),其余逻辑正确 |
math/polar/op_host/arch35/polar_tiling.h |
无问题 |
math/polar/op_kernel/arch35/polar_simt.h |
无问题(SIMT kernel 实现正确:broadcast 坐标分解、stride 计算、输出交错写入均验证通过) |
math/polar/op_kernel/arch35/polar_struct.h |
无问题 |
math/polar/op_kernel/polar_apt.cpp |
无问题 |
math/polar/tests/ut/op_host/arch35/test_polar_tiling_arch35.cpp |
无问题(测试覆盖了正向/广播/类型不匹配/不可广播等场景,expectTilingKey/expectWorkspaces 均已正确更新) |
总体风险评估
风险:低。 此次变更将 polar 算子从 DAG(double-buffer pipeline)回退到 SIMT 实现,代码质量良好。关键路径(tiling shape 分析、broadcast 对齐、stride 计算、kernel 坐标分解、多核数据分配)均经过验证,逻辑正确。已删除的 polar.h / polar_dag.h 无残留引用,类型(int64_t)使用恰当,无 32 位溢出风险。唯一发现的问题是日志级别使用不当(P3),不影响功能正确性。
⚠️ 已识别出整体风险,但无法提取行内评论,请参考整体评估。


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
xiu_ling_wang, thanks for your pull request. All authors of the commits have signed the CLA. 👍


compile


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


流水线任务触发成功
任务链接 [59a2bc10462d4054a4092d7d18a83b67][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| codecheck | ✅ SUCCESS | >>>>> | |
| SCA | ✅ SUCCESS | >>>>> | |
| antipoison | ✅ SUCCESS | >>>>> | |
| codecheck_Pr | ✅ SUCCESS | ||
| StaticCheck_codespell_check | ✅ SUCCESS | ||
| StaticCheck_link_validity_check | ✅ SUCCESS | ||
| StaticCheck_resource_existence_check | ✅ SUCCESS | ||
| StaticCheck_tag_closed_check | ✅ SUCCESS | ||
| StaticCheck_markdownlint | ✅ SUCCESS | ||
| codecheck_codestyle | ⚠️ WARNING | >>>>> | |
| codecheck_precommit | ❌ FAILED | >>>>> | >>>>> |


compile


流水线任务触发成功
任务链接 [8c16749e4377498ea8a144c2ab1ab1b4][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| pre_comment | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_mobile_station_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_experimental_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_A5_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_harmony-infer | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_ARM_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_experimental_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_single_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_A5_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910b | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910c | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_harmony-infer-chs-math | ✅ SUCCESS | >>>>> | |
| Compile_kirin-harmony-infer-chs-math-1 | ✅ SUCCESS | >>>>> | |
| UT_Test | ✅ SUCCESS | ||
| UT_Test_experimental | ✅ SUCCESS | ||
| UT_Test_kernel | ✅ SUCCESS | ||
| PreSmoke_A900 | ✅ SUCCESS | >>>>> | |
| API_Check | ✅ SUCCESS | >>>>> | |
| PreSmoke_ATK_Test_A2 | ✅ SUCCESS | >>>>> |
[2026-07-09 15:08:24] CI执行结束


流水线任务触发成功
任务链接 [a6d5079b9bee4858adfb838f67cb25c8][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| codecheck | ✅ SUCCESS | >>>>> | |
| SCA | ✅ SUCCESS | >>>>> | |
| antipoison | ✅ SUCCESS | >>>>> | |
| codecheck_Pr | ✅ SUCCESS | ||
| StaticCheck_codespell_check | ✅ SUCCESS | ||
| StaticCheck_link_validity_check | ✅ SUCCESS | ||
| StaticCheck_resource_existence_check | ✅ SUCCESS | ||
| StaticCheck_tag_closed_check | ✅ SUCCESS | ||
| StaticCheck_markdownlint | ✅ SUCCESS | ||
| codecheck_codestyle | ✅ SUCCESS | >>>>> | |
| codecheck_precommit | ✅ SUCCESS | >>>>> |
[2026-07-09 15:04:57] CI执行结束


/lgtm
/approve


描述
回退polar算子到simt实现。
关联的Issue
https://gitcode.com/cann/ops-math/issues/2177
测试
文档更新
类型标签