已合并
Swish算子Ascend C实现 #4020
fulltower创建于 4月20日
Swish算子Ascend C实现 #4020
已合并
fulltower创建于 4月20日
fulltower成员
4月20日

描述

参考版本内置Swish算子的TBE实现,在昇腾NPU上使用Ascend C编程语言实现相同功能的算子。

关联的Issue

https://gitcode.com/cann/ops-nn/issues/306

测试

aclnn测试

类型标签

  • Bug修复
  • 新特性
  • 性能优化
  • 文档更新
  • 其他,请描述:
likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 fulltower 的贡献)
Ffulltower成员
4月20日 创建了 pull request,commit e002ab50
Ffulltower成员
4月20日 关联了issue:[Requirement|需求建议]: 【社区任务】Ascend C实现Swish算子贡献
CANN-robot
CANN-robot成员
4月20日 评论:

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
experimental/activation 陈琦, liujie12345678 (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

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

likedislike
CANN-robotCANN-robot成员
4月20日 添加了label:cann-cla/yes
CANN-robotCANN-robot成员
4月20日 将crystalhu,yangyang016,fanqirui,zhou-qilong,zhajianqing123,chenqi317,liubo75,tangweiwei2,liujie12345678,Chen_HaoWen,wangyongguang,zhang-wu设为评审人
CANN-robotCANN-robot成员
4月20日 将crystalhu,zhou-qilong,zhajianqing123,chenqi317,liubo75,tangweiwei2,liujie12345678,Chen_HaoWen,wangyongguang,zhang-wu设为审查人
fulltower成员
4月20日 评论:

compile

likedislike
CANN-robotCANN-robot成员
4月20日 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
4月20日 评论:

流水线任务触发成功
任务链接 [6168237fef714506929ef8b7bf716fb5][流水线指导]

任务名称状态日志下载链接
Compile_Ascend_X86_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_X86_mobile_station ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_single ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_950 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_950 ✅ SUCCESS >>>>> >>>>>
Pre_Compile ✅ SUCCESS
pre_comment ✅ SUCCESS >>>>>
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_X86_950_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_ARM_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_single_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_experimental_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_ARM_950_ubuntu24 ✅ SUCCESS >>>>>
Compile_X86_monitor ✅ SUCCESS >>>>> >>>>>
Compile_ARM_monitor ✅ SUCCESS >>>>> >>>>>
UT_Test_ophost ✅ SUCCESS
UT_Test_opapi ✅ SUCCESS
UT_Test_kernel ✅ SUCCESS
UT_Test_opgraph ✅ SUCCESS
Smoke_A900_npupool ✅ SUCCESS >>>>>
API_Check ⚠️ WARNING >>>>>
ATK_Test_A2 ✅ SUCCESS

[2026-04-20 20:57:11]    CI执行结束

likedislike
CANN-robot
CANN-robot成员
4月20日 评论:

流水线任务触发成功
任务链接 [daae171a19fc4d4b8d963cf8229b1824][流水线指导]

任务名称状态日志下载链接
codecheck ❌ FAILED >>>>>
anti_virus ✅ SUCCESS >>>>>
Check_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_style ✅ SUCCESS
likedislike
CANN-robotCANN-robot成员
4月20日 添加了label:api-check-failed
CANN-robotCANN-robot成员
4月20日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
4月20日 添加了label:ci-pipeline-failed
CANN-robot
CANN-robot成员4月20日进行代码检视1
experimental/activation/swish/op_graph/swish_proto.h
@@ -0,0 +9,4 @@
9+ */
10+ 
11+ 
12+/*!
CANN-robot
CANN-robot4月20日评论:
代码结构与可维护性: 文件头注释中的文件名与实际文件名不一致。注释中描述的文件名为'nonlinear_fuc_ops.h',但实际文件名为'swish_proto.h'。这种不一致会导致开发者在查找文件时产生困惑,降低代码的可读性和可维护性。
问题类型: 代码结构与可维护性
文件路径: experimental/activation/swish/op_graph/swish_proto.h
行号: 12
问题代码:
/*!
 * \file nonlinear_fuc_ops.h
 * \brief
 */
修改建议:
将文件头注释中的文件名修改为实际文件名'swish_proto.h',保持注释与代码的一致性。
---
此评论由代码审查工具自动生成
likedislike
CANN-robot
CANN-robot成员4月20日进行代码检视2
experimental/activation/swish/op_graph/swish_proto.h
已过期
@@ -0,0 +20,4 @@
20+ 
21+namespace ge {
22+/**
23+*@brief Computes the for the Swish of "x" .
CANN-robot
CANN-robot4月20日评论:
代码结构与可维护性: 注释中存在语法错误和表述不清的问题。'Computes the for the Swish of "x"'这句话语法不通顺,'the for'可能是多余或错误的表述。这会影响文档的可读性和专业性。
问题类型: 代码结构与可维护性
文件路径: experimental/activation/swish/op_graph/swish_proto.h
行号: 23
问题代码:
*@brief Computes the for the Swish of "x" .
修改建议:
修改为更清晰准确的描述,例如:'*@brief Computes the Swish activation function for input tensor x.'
---
此评论由代码审查工具自动生成
likedislike
System
系统消息系统
4月20日 评论:
likedislike
CANN-robot
CANN-robot成员4月20日进行代码检视2
experimental/activation/swish/op_graph/swish_proto.h
已过期
@@ -0,0 +27,4 @@
27+* x: A tensor, which supports 1D-8D defaultly and must be one of the following types: float16, bfloat16, float32. \n
28+ 
29+*@par Outputs:
30+* y: A tensor of the same type, shape and format as "x", and y = x / (1 + e ^ (-scale * x)). \n
CANN-robot
CANN-robot4月20日评论:
代码结构与可维护性: 输出张量的数学公式描述中,指数运算的表示可能不够清晰。'e ^ (-scale * x)'中的'^'符号在C/C++中表示按位异或,而不是指数运算。虽然在注释中使用可以理解,但为了更精确,建议使用数学上更标准的表示法。
问题类型: 代码结构与可维护性
文件路径: experimental/activation/swish/op_graph/swish_proto.h
行号: 30
问题代码:
* y: A tensor of the same type, shape and format as "x", and y = x / (1 + e ^ (-scale * x)). \n
修改建议:
修改为更清晰的数学表示,例如:'* y: A tensor of the same type, shape and format as "x", and y = x / (1 + exp(-scale * x)).' 或者使用LaTeX风格的表示法。
---
此评论由代码审查工具自动生成
likedislike
System
系统消息系统
4月20日 评论:
likedislike
CANN-robot
CANN-robot成员4月20日进行代码检视2
experimental/activation/swish/op_graph/swish_proto.h
已过期
@@ -0,0 +30,4 @@
30+* y: A tensor of the same type, shape and format as "x", and y = x / (1 + e ^ (-scale * x)). \n
31+ 
32+*@par Attributes:
33+* scale: scalar parameter, the multiplier of x. Must be one of the following types: float. Default value = 1.0. \n
CANN-robot
CANN-robot4月20日评论:
代码结构与可维护性: 属性'scale'的类型描述与代码实现不完全一致。注释中说'Must be one of the following types: float.',但代码中只指定了'Float'类型(对应DT_FLOAT)。如果确实只支持float32,注释应该更精确;如果需要支持其他浮点类型,代码需要相应调整。
问题类型: 代码结构与可维护性
文件路径: experimental/activation/swish/op_graph/swish_proto.h
行号: 33
问题代码:
* scale: scalar parameter, the multiplier of x. Must be one of the following types: float. Default value = 1.0. \n
修改建议:
如果只支持float32,将注释修改为'Must be of type float32.';如果需要支持float16或bfloat16,需要在REG_OP中相应调整ATTR的类型指定。
---
此评论由代码审查工具自动生成
likedislike
System
系统消息系统
4月20日 评论:
likedislike
CANN-robot
CANN-robot成员4月20日进行代码检视2
experimental/activation/swish/op_graph/swish_proto.h
已过期
@@ -0,0 +20,4 @@
20+ 
21+namespace ge {
22+/**
23+*@brief Computes the for the Swish of "x" .
CANN-robot
CANN-robot4月20日评论:
文档/注释错误: 注释中存在语法错误,语句不通顺。'Computes the for the Swish of "x" .' 这句话存在冗余和语法问题,无法清晰表达函数的功能。
问题类型: 文档/注释错误
文件路径: experimental/activation/swish/op_graph/swish_proto.h
行号: 23
问题代码:
*@brief Computes the for the Swish of "x" .
修改建议:
修改为更清晰、准确的描述,例如:"@brief Computes the Swish activation function for the input tensor 'x'."
---
此评论由代码审查工具自动生成
likedislike
System
系统消息系统
4月20日 评论:
likedislike
Ffulltower成员
4月20日 update merge request[project id: 7665709, iid: 4020, commit_id: 66db48ca91f8e354248684d084699031aeae0ec3] virtual merging success
Ffulltower成员
4月20日 强制推送  1 个提交:6a21fbfe-add Swish operator
Ffulltower成员
4月20日 update merge request[project id: 7665709, iid: 4020, commit_id: 2de77d88478a3be37e4631579633d183686c5103] virtual merging success
fulltower成员
4月20日 评论:

compile

likedislike
CANN-robotCANN-robot成员
4月20日 删除了label:ci-pipeline-failed
CANN-robotCANN-robot成员
4月20日 添加了label:ci-pipeline-running
CANN-robotCANN-robot成员
4月20日 删除了label:api-check-failed
CANN-robot
CANN-robot成员
4月20日 评论:

流水线任务触发成功
任务链接 [72ecd73130814e31910d34ebdc5064a9][流水线指导]

任务名称状态日志下载链接
Compile_Ascend_X86_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_X86_mobile_station ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_single ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_950 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_950 ✅ SUCCESS >>>>> >>>>>
Pre_Compile ✅ SUCCESS
pre_comment ✅ SUCCESS >>>>>
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_X86_950_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_ARM_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_single_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_experimental_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_ARM_950_ubuntu24 ✅ SUCCESS >>>>>
Compile_X86_monitor ✅ SUCCESS >>>>> >>>>>
Compile_ARM_monitor ✅ SUCCESS >>>>> >>>>>
UT_Test_ophost ✅ SUCCESS
UT_Test_opapi ✅ SUCCESS
UT_Test_kernel ✅ SUCCESS
UT_Test_opgraph ✅ SUCCESS
Smoke_A900_npupool ✅ SUCCESS >>>>>
API_Check ⚠️ WARNING >>>>>
ATK_Test_A2 ✅ SUCCESS

[2026-04-20 21:25:06]    CI执行结束

likedislike
CANN-robot
CANN-robot成员
4月20日 评论:

流水线任务触发成功
任务链接 [9103d5e9d2a74ccf8abff22e1d9c6564][流水线指导]

任务名称状态日志下载链接
codecheck ❌ FAILED >>>>>
anti_virus ✅ SUCCESS >>>>>
Check_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_style ✅ SUCCESS
likedislike
CANN-robotCANN-robot成员
4月20日 添加了label:api-check-failed
CANN-robotCANN-robot成员
4月20日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
4月20日 添加了label:ci-pipeline-failed
CANN-robotCANN-robot成员
4月21日 删除了label:ci-pipeline-failed
CANN-robotCANN-robot成员
4月21日 添加了label:ci-pipeline-running
CANN-robotCANN-robot成员
4月21日 删除了label:api-check-failed
CANN-robot
CANN-robot成员
4月21日 评论:

流水线任务触发成功
任务链接 [c882ee99147c4549ac2282c2396b2ae6][流水线指导]

任务名称状态日志下载链接
codecheck ✅ SUCCESS >>>>>
anti_virus ✅ SUCCESS >>>>>
Check_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_style ✅ SUCCESS

[2026-04-21 11:43:15]    CI执行结束

likedislike
CANN-robotCANN-robot成员
4月21日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
4月21日 添加了label:ci-pipeline-passed
liujie12345678成员
4月21日 评论:

/lgtm

likedislike
Ffulltower成员
4月22日 解决了最后一个问题
chenqi317成员
4月22日 评论:

/lgtm
/approve

likedislike
CANN-robotCANN-robot成员
4月22日 添加了label:lgtmapproved
CANN-robot
CANN-robot成员
4月22日 评论:

Review Guide

This pull-request passes review.
Committers who wrote a comment of /approve are: 陈琦.
Reviewers who wrote a comment of /lgtm are: 陈琦, liujie12345678.

likedislike
CANN-robotCANN-robot成员
4月22日 合入了pull request