Merged
silu_mul 算子适配950芯片 #10658
chenqi_814540Add on Sep 17
silu_mul 算子适配950芯片 #10658
Merged
chenqi_814540Add on Sep 17
chenqi_814540Collaborators
Sep 17

描述

experimental/activation/silu_mul 算子(z = Silu(x) × y,其中 Silu(x) = x·sigmoid(x))原有实现仅支持 ascend910b(Atlas A2)与 ascend910_93(Atlas A3)。本 PR 为该算子新增 ascend950(Atlas A5)芯片适配,使其在 950 平台上完整支持 tiling 计算、kernel 执行与 aclnn 调用;ascend910b / ascend910_93 原有代码路径保持不变,无回归风险。

适配方式(定级 L1,参照仓库内 clipped_swiglu 的双平台适配范式,核心计算保留内存式 API,不重写 MicroAPI)。kernel 源按平台编译:新增 op_kernel/CMakeLists.txt,通过 add_kernel_sources 按 compute unit 分发——ascend910b / ascend910_93 编译默认源 op_kernel/silu_mul.cpp,ascend950 编译 op_kernel/arch35/silu_mul.cpp(写入生成算子信息的 kernelSrc.value 供 asc_opc 取源),不采用独立 apt 入口文件:

  1. op_host/silu_mul_def.cpp:新增 ascend950 独立 OpAICoreConfig(支持动态 Shape/Rank),kernel 入口为 arch35/silu_mul.cpp(opFile 默认取算子名,无需显式指定)。
  2. op_host/silu_mul_tiling.cpp:在单一 tiling 入口内通过 Ops::NN::OpTiling::IsRegbaseSocVersion(context) 分流——ascend950 走新增的 arch35 tiling 路径,910b / 910_93 走原逻辑。
  3. op_host/silu_mul_tiling_arch35.cpp(新增):950 专用 tiling,并落实两处相对 910b 实现的改进(仅作用于 950 路径):
    • UB 大小平台化:以 GetCoreMemSize(CoreMemType::UB) 动态查询替代硬编码 184KB,并预留 8KB headroom 供框架栈空间使用;PPMaxCalNum 与下发 kernel 的 maxUbSize 由预留后的同一可用 UB 推导,保证 host/kernel 自洽。
    • 核数估算判据修正:改用完整 lastDimSize 与 PPMaxCalNum 比较(原 910b 用 lastDimSize/2 估算,与 kernel 侧 d > PPMaxCalNum 的路径选择判据不一致),使 host 核数估算与 kernel 实际执行路径一致。
  4. op_kernel/arch35/silu_mul_tiling_struct.h(新增):arch35 独立 POD tiling 结构 SiluMulArch35TilingData(新增 maxUbSize 字段),与 910b 的 SiluMulTilingData 解耦,避免双平台重复注册。
  5. op_kernel/CMakeLists.txt(新增):add_kernel_sources 按 compute unit 分发 kernel 源(910b/910_93 → silu_mul.cpp,ascend950 → arch35/silu_mul.cpp)。
  6. op_kernel/arch35/silu_mul.cpp(新增):950 kernel 入口,使用 REGISTER_TILING_DEFAULT / GET_TILING_DATA_WITH_STRUCT;UT 编译模式下条件编译为 memcpy 读取 tiling 结构,保证 CPU 模拟 UT 可编译执行。
  7. op_kernel/arch35/silu_mul.h(新增):950 kernel 实现,计算逻辑与 910b 保持一致(Silu(x)×y 融合、全程 FP32 域计算、大/小尾轴双路径、Ping-Pong 双缓冲),UB 布局尺寸 maxUbSize 改由 tiling 下发,替代硬编码常量。
  8. op_host/config/ascend950/silu_mul_binary.json(新增):FP16 / FP32 / BF16 三种 dtype 的 950 binary 选择配置。
  9. tests/ut/op_kernel/:新增 ascend950pr_9599 kernel UT(arch35/test_silu_mul_apt.cpp,CPU 模拟执行 arch35 kernel,extern 链接入口);910b 根测试 test_silu_mul.cpp 增加 UT_SOC_VERSION 守卫,避免 opFile 同名导致非 910b 构建误执行;UT CMakeLists 按 soc 二选一(ascend950 用例 / ascend910b 用例)。

关联的Issue

新增silu_mul算子950芯片适配: https://gitcode.com/cann/ops-nn/issues/5315

测试

在 ascend950(Atlas A5)Linux + CANN 9.2.0-beta.2 环境完成如下验证:

  1. 编译验证:bash build.sh --pkg --experimental --ops=silu_mul --soc=ascend950 -j8 编译通过并生成 run 包,host tiling 分发、arch35 tiling、950 kernel binary(三种 dtype,由 op_kernel/CMakeLists.txt 按平台分发编译)与自动生成的 aclnn 接口均正常构建。
  2. 部署验证:run 包安装成功,vendors 目录下 kernel bin / opapi 库 / aclnn 头文件完整落盘,nm -D 可见 aclnnSiluMul 与 aclnnSiluMulGetWorkspaceSize 符号。
  3. 端到端精度验证:编译执行 examples/test_aclnn_silu_mul.cpp(x=[0,1,…,7],y=1),在 950 实机通过 aclnn 两段式调用执行,输出与理论值 x·sigmoid(x) 一致(最大偏差约 1.5e-4,为 FP32 正常舍入误差)。
  4. op_host UT:bash build.sh -u --ophost --experimental --ops=silu_mul --soc=ascend950,infershape 与 tiling 共 2 个用例全部 PASSED,验证 910b 原路径无回归。
  5. op_kernel UT:bash build.sh -u --opkernel --experimental --ops=silu_mul --soc=ascend950 执行 arch35/test_silu_mul_apt.cpp(ascend950pr_9599 用例)全部 PASSED,验证 arch35 kernel 的 CPU 模拟执行与精度比对;--soc=ascend910b 执行 910b 用例全部 PASSED,验证 UT_SOC_VERSION 守卫与既有路径无回归。

文档更新

  • 更新 experimental/activation/silu_mul/README.md 与 docs/aclnnSiluMul.md 的产品支持表,新增 Atlas A5 训练/推理系列产品支持。

类型标签

AI/Agent生成声明

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for chenqi_814540's contribution.)
Cchenqi_814540Collaborators
Sep 17 Created pull request, commit 137ba5c6
Cchenqi_814540Collaborators
Sep 17 Associated issue: [Requirement|需求建议]: 新增silu_and_mul算子
atomgit-bot
atomgit-bot
Sep 17 Comments:

变更摘要

本 PR 为 experimental/activation/silu_mul 算子新增 ascend950(Atlas A5)芯片适配,使其在 950 平台上支持 tiling 计算、kernel 执行与 aclnn 调用,同时保持 ascend910b / ascend910_93 原有路径不变。适配采用按平台编译 kernel 源与 tiling 入口分流的方式:op_host/silu_mul_def.cpp 新增独立的 ascend950 OpAICoreConfig(支持动态 Shape/Rank),op_host/silu_mul_tiling.cpp 通过 Ops::NN::OpTiling::IsRegbaseSocVersion 将 950 分流到新增的 Tiling4SiluMulArch35,950 专用 tiling 与 kernel 实现落在 op_kernel/arch35/ 下,并使用独立的 POD tiling 结构 SiluMulArch35TilingData。

主要改动

  • 950 平台算子定义与 tiling 分流: silu_mul_def.cpp 新增 ascend950 的 OpAICoreConfig(x/y/z 支持 FP16/FP32/BF16、FORMAT_ND,开启 DynamicCompileStaticFlag/DynamicRankSupportFlag/DynamicShapeSupportFlag);silu_mul_tiling.cpp 在 TilingSiluMulTiling 入口按 IsRegbaseSocVersion(context) 分流到 Tiling4SiluMulArch35。
  • 新增 arch35 专用 tiling: 新增 silu_mul_tiling_arch35.cpp,通过 GetCoreMemSize(CoreMemType::UB) 动态查询 UB 并以 ARCH35_UB_RESERVE(8KB)预留 headroom,PPMaxCalNum 与下发的 maxUbSize 由同一可用值推导;核数估算 GetNeedCoreNum 改用完整 lastDimSize 与 PPMaxCalNum 比较,与 kernel 侧 d > PPMaxCalNum 判据一致。
  • 新增 arch35 独立 tiling 结构与 kernel 实现: 新增 op_kernel/arch35/silu_mul_tiling_struct.h 定义 POD 结构 SiluMulArch35TilingData(含新增 maxUbSize 字段),与 910b 的 SiluMulTilingData 解耦;新增 op_kernel/arch35/silu_mul.cpp 与 silu_mul.h,计算逻辑与 910b 保持一致(Silu×y 融合、FP32 域计算、大/小尾轴双路径、Ping-Pong 双缓冲),UB 布局尺寸改由 tiling 下发的 maxUbSize 决定;kernel 入口在 __CCE_UT_TEST__/KERNELUT 下以 memcpy 读取 tiling 结构以支持 CPU 模拟 UT。
  • 新增 950 binary 配置: 新增 op_host/config/ascend950/silu_mul_binary.json,为 float32/bfloat16/float16 三种 dtype 提供 SiluMul 的 binary 选择配置(输入 x/y、输出 z,FormatAgnostic)。
  • UT 与构建适配: 新增 tests/ut/op_kernel/arch35/test_silu_mul_apt.cpp(通过 extern 链接 silu_mul 入口,CPU 模拟执行 arch35 kernel 并比对精度);tests/ut/op_kernel/test_silu_mul.cpp 增加 UT_SOC_VERSION 守卫,非 910b 构建时 GTEST_SKIP,避免 opFile 同名导致误执行。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
Sep 17 Comments:

代码审查

✅ 未发现问题

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Sep 17 Added label: stat/needs-squash
CANN-robotCANN-robotCollaborators
Sep 17 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Sep 17 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 ✅ 陈昊文, 唐玮玮 (2/2) ✅ 陈昊文 (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robotCANN-robotCollaborators
Sep 17 Set zengjuan,u010470851,sxb154714,cheng_gao,chenfeng61,chaotang233,kevin_huang1234,FelixTang7,crystalhu,yu-xinjie62,yangyang016,fanqirui,renruhai,su-yueming,zhajianqing123,yourealize,chenqi317,liu-wei,lileizheng,LinPX,fullt,wang-xing001,liubo75,LiuZonggu,tangweiwei2,wangzitao_leo,xubinglin,liujie12345678,pingchuantang,Chen_HaoWen,wangcimeng,huafeng793,qianzehong,liuyang_806,liuchuangdev,shi-xiangyang225,linruihan,shenchengzong,yuxin5 as approver
CANN-robotCANN-robotCollaborators
Sep 17 Set zengjuan,u010470851,sxb154714,cheng_gao,chenfeng61,chaotang233,kevin_huang1234,FelixTang7,crystalhu,yu-xinjie62,yangyang016,fanqirui,renruhai,su-yueming,zhajianqing123,yourealize,chenqi317,liu-wei,lileizheng,LinPX,fullt,wang-xing001,liubo75,LiuZonggu,tangweiwei2,wangzitao_leo,xubinglin,liujie12345678,pingchuantang,Chen_HaoWen,wangcimeng,huafeng793,qianzehong,liuyang_806,liuchuangdev,shi-xiangyang225,linruihan,shenchengzong,yuxin5 as approver
chenqi_814540Collaborators
Sep 17 Comments:

compile

likedislike
Cchenqi_814540Collaborators
Sep 17 Pre merge succeeded (commit_id: 0c294d09710ba1f4a4726d3c510dfd5a20e6f256)
CANN-robot
CANN-robotCollaborators
Sep 17 Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
Sep 17 Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Sep 17 Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Sep 17 Added label: ci-pipeline-passed
yuning_chen
yuning_chenCollaborators
Sep 17 Comments:

您好,pr合入已准备就绪,请尽快联系committer进行检视,谢谢!

likedislike
tangweiwei2Collaborators
Sep 18 Comments:

/lgtm

likedislike
Chen_HaoWenCollaborators
Sep 18 Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
Sep 18 Added label: lgtmapproved
CANN-robotCANN-robotCollaborators
Sep 18 Merged pull request
Cchenqi_814540Collaborators
Sep 22 Change title to "silu_mul 算子适配950算子", originally titled "新增 ascend950 (Atlas A5) 芯片适配".
Cchenqi_814540Collaborators
Sep 22 Change title to "silu_mul 算子适配950", originally titled "silu_mul 算子适配950算子".
Cchenqi_814540Collaborators
Sep 22 Change title to "silu_mul 算子适配950芯片", originally titled "silu_mul 算子适配950".