Merged
trans_data/tanh算子适配ascend350平台 #5560
trans_data/tanh算子适配ascend350平台 #5560
Merged
wenqi_wuAdd on Sep 10
wenqi_wu
Sep 10

描述

为 TransData、Tanh 两个算子补齐 ascend350 平台适配:

TransData(5 处改动)

  1. conversion/trans_data/CMakeLists.txt:SUPPORT_COMPUTE_UNIT 新增 ascend350,SUPPORT_TILING_DIR 对应新增 arch35(与 ascend950 共用同一 tiling 目录);同时将许可证头规范化为标准 CANN 格式。
  2. conversion/trans_data/op_host/trans_data_def.cpp:新增 this->AICore().AddConfig("ascend350", aicore_config),为 ascend350 注册 AICore 算子配置(与 ascend950 配置一致,复用 trans_data_apt)。
  3. conversion/trans_data/op_host/config/ascend350/trans_data_binary.json(新增):ascend350 平台的二进制算子配置,内容与 ascend950 的 trans_data_binary.json 一致。
  4. conversion/trans_data/op_api/aclnn_trans_matmul_weight.cpp 与 aclnn_trans_convolution_weight.cpp:将 SocVersion 平台判断改为 NpuArch 判断(ASCEND910B/ASCEND910_93 → DAV_2201,ASCEND310P → DAV_2002),IsRegBase() 改为传入 arch 参数,错误日志仍使用 SocVersion。
  5. scripts/kernel/binary_config/ascendc_config.json:TransData 条目的 compute_units 与 compile_options 新增 ascend350(编译选项 -mllvm -cce-aicore-dcci-before-kernel-end=false),为 ascend350 补齐内核编译配置。

Tanh(1 处改动)

  1. math/tanh/op_api/aclnn_tanh.cpp:GetOutDtypeSupportList 与 CheckDtypeValid 中 SocVersion 判断改为 NpuArch 判断(ASCEND910B/ASCEND910_93 及 ASCEND910B~ASCEND910E 区间判断 → DAV_2201 || IsRegBase(curArch)),使 350 平台走正确的 dtype 支持列表分支。op_host 侧(def.cpp 的 ascend350 AddConfig、config/ascend350/tanh_binary.json、CMakeLists)此前已具备,无需改动。

关联的Issue

https://gitcode.com/cann/ops-math/issues/3132

测试

  • pre-commit 本地检查通过(clang-format / codespell / JSON / OAT 合规扫描阻塞项为 0)
  • 现有 UT(test_aclnn_trans_matmul_weight_l2.cpp、test_aclnn_tanh.cpp 等)已基于 SetPlatformNpuArch 编写,与改动后各 arch 分支语义一致
  • 待在 ascend350 环境完成二级冒烟、算子泛化验证

文档更新

无需更新文档

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for wenqi_wu's contribution.)
Wwenqi_wu
Sep 10 Created pull request, commit 10abb529
Wwenqi_wu
Sep 10 Associated issue: [Requirement|需求建议]: trans_data算子不支持350适配
atomgit-bot
atomgit-bot
Sep 10 Comments:

变更摘要

本 PR 为 TransData、Tanh 两个算子补齐 ascend350 平台适配。核心思路是将 op_api 层原本基于 SocVersion 的平台判断统一改为基于 NpuArch(ASCEND910B/ASCEND910_93 → DAV_2201,ASCEND310P → DAV_2002),并让 IsRegBase() 接受 arch 参数,使 ascend350(复用 ascend950 的 tiling 与二进制配置)能够落入正确的 dtype 支持列表与参数校验分支;同时在 op_host 侧为 ascend350 注册 AICore 配置并新增对应的二进制算子配置文件。

主要改动

  • op_api 平台判断迁移到 NpuArch(aclnn_trans_matmul_weight.cpp): GetDtypeSupportList、CheckShapeDim、CheckSocValid 将 SocVersion::ASCEND910B/ASCEND910_93/ASCEND310P 判断改为 NpuArch::DAV_2201/DAV_2002,IsRegBase() 改为传入 curArch,使 ascend350 复用 ASCEND910B_DTYPE_DTYPE_SUPPORT_LIST 分支。
  • 卷积权重转换平台校验改造(aclnn_trans_convolution_weight.cpp): CheckParams 中将 SocVersion::ASCEND310P 校验改为 NpuArch::DAV_2002,错误日志仍保留 SocVersion 输出,确保 350 平台不再被误判为不支持。
  • 注册 ascend350 AICore 配置(trans_data_def.cpp): 在已有 AddConfig("ascend950", aicore_config) 基础上新增 this->AICore().AddConfig("ascend350", aicore_config),复用 trans_data_apt 算子配置。
  • 新增 ascend350 二进制算子配置(config/ascend350/trans_data_binary.json): 新增文件,内容与 ascend950 一致,覆盖 int8/float16/float32/int4/float4_e2m1/hifloat8/uint8 等 dtype 在 ND 与 FRACTAL_NZ/FRACTAL_NZ_C0_16/FRACTAL_NZ_C0_32 等格式间的转换场景。
  • Tanh dtype 支持判断适配(aclnn_tanh.cpp): GetOutDtypeSupportList 与 CheckDtypeValid 将 SocVersion 判断(含 ASCEND910B~ASCEND910E 区间判断)改为 curArch == NpuArch::DAV_2201 || IsRegBase(curArch),使 350 平台走 ASCEND910B_DTYPE_OUT_LIST/ASCEND910B_DTYPE_SUPPORT_LIST 分支。

此外,按 PR 描述,conversion/trans_data/CMakeLists.txt 中 SUPPORT_COMPUTE_UNIT 新增 ascend350、SUPPORT_TILING_DIR 新增 arch35(与 ascend950 共用 tiling 目录),并将许可证头规范化为标准 CANN 格式。

likedislike
Incorrect?
atomgit-bot
atomgit-bot
Sep 10 Comments:

代码审查

✅ 未发现问题

likedislike
Incorrect?
CANN-robot
CANN-robotCollaborators
Sep 10 Comments:

Hi @wenqi_wu, 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
59 messages are collapsed here。 See more
CANN-robotCANN-robotCollaborators
Sep 12 Added label: approved
rxtfengCollaborators
Sep 12 Comments:

/lgtm

likedislike
CANN-robotCANN-robotCollaborators
Sep 12 Added label: lgtm
CANN-robotCANN-robotCollaborators
Sep 12 Closed associated issue
CANN-robotCANN-robotCollaborators
Sep 12 Merged pull request