已合并
[代码侦探(第七期)] 闪捷信息科技有限公司 - challenge07_sigmoidcustom #4216
[代码侦探(第七期)] 闪捷信息科技有限公司 - challenge07_sigmoidcustom #4216
已合并
OpenGood_WeChat创建于 22 天前
OpenGood_WeChat
22 天前

闪捷信息科技有限公司

团队信息

  • 提交者: gcw_LxlU8H9L (opengoodai@163.com)
  • 身份: 企业员工
  • 单位: 闪捷信息科技有限公司

成员

算子: challenge07_sigmoidcustom

基于Ascend C实现Sigmoid激活算子(y=1/(1+exp(-x)))。op_host侧完成形状推导与Tiling函数:按输入dtype选择模板实例(float16/float32),总元素数按8核均匀切分(blockFactor=totalNum/8),核内再按ubFactor分片搬入UB;op_kernel侧采用CopyIn→Compute→CopyOut三段式流水线,内部统一转float并使用0.5+0.5*tanh(x/2)数值稳定公式(经Muls/Tanh/Adds指令组合实现,避免fp16大负数exp溢出),结果写回GM后Cast回原dtype

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 OpenGood_WeChat 的贡献)
OpenGood_WeChatOpenGood_WeChat
22 天前 创建了 pull request,commit 362c8d3a
atomgit-bot
atomgit-bot
22 天前 评论:

变更摘要

本 PR 为「代码侦探」挑战赛提交,使用 Ascend C 实现 Sigmoid 激活算子(y=1/(1+exp(-x)))的完整交付,覆盖算子定义与注册、形状推导、Tiling、Kernel 三段式流水线实现,以及示例程序和 UT 测试基础设施。整体围绕 op_host、op_kernel、examples、tests/ut 四部分展开,支持 float16/float32 两种输入 dtype,并以 0.5+0.5*tanh(x/2) 的数值稳定形式替代直接 exp 计算。

主要改动

  • 算子定义与注册: 新增 op_host/sigmoid_def.cpp,以 Sigmoid 继承 OpDef,定义输入 x、输出 y 的 REQUIRED/AutoContiguous 属性,数据类型限定 DT_FLOAT、DT_FLOAT16,并通过 AICore().AddConfig("ascend910b") 绑定硬件平台。
  • Tiling 与多核切分: 新增 op_host/sigmoid_tiling.cpp,按输入 dtype 选择 GET_TPL_TILING_KEY(SIGMOID_TPL_SCH_MODE_0/1) 并 SetTilingKey;将输入 shape 逐维相乘得 totalNum,按 BLOCK_DIM=8 计算 blockFactor、再按 TILE_NUM=16 得到 ubFactor,通过 SetBlockDim(8) 配置核数,workspace 置 0。
  • Kernel 数值稳定实现: 新增 op_kernel/sigmoid.h 中的 NsSigmoid::Sigmoid 模板类,采用 CopyIn→Compute→CopyOut 流水线,内部将数据统一 Cast(或 Muls)到 float,以 Muls→Tanh→Muls→Adds 组合实现 0.5+0.5*tanh(x/2),输出再 Cast 回原 dtype;op_kernel/sigmoid.cpp 入口依据模板参数 schMode 分发到 Sigmoid<half> 或 Sigmoid<float>。
  • Tiling 数据结构与模板参数: 新增 op_kernel/sigmoid_tiling_data.h 的 SigmoidTilingData(含 totalNum、blockFactor、ubFactor)与 op_kernel/sigmoid_tiling_key.h 的 ASCENDC_TPL_ARGS_DECL/ASCENDC_TPL_SEL 声明,明确 schMode 的两个取值。
  • 示例与 UT 测试: 新增 examples/test_aclnn_sigmoid.cpp 演示 aclnnSigmoidGetWorkspaceSize+aclnnSigmoid 两段式调用;tests/ut 下新增 op_host Tiling 用例(test_sigmoid_tiling.cpp)、op_kernel 用例(test_sigmoid.cpp)及 tiling_case_executor、infershape_case_executor 等公共测试框架,配合 gen_data.py 与 compare_data.py 完成数据生成与 MERE/MARE 精度比对,build.sh、run.sh 提供构建与测试入口。
likedislike
不准确?
OpenGood_WeChat
OpenGood_WeChat
22 天前 评论:

/compile

likedislike
atomgit-bot
atomgit-bot
22 天前 评论:

代码审查

审查结论

  • [阻塞] 2026/CANN-Code-Detective/Challenge07-SigmoidCustom/PR_code/secsmart_OpenGoodCANNJu/code/challenge07_sigmoidcustom/op_host/sigmoid_tiling.cpp:36 fix: 多核切分整数除法截断,尾部元素永不计算(含 ubFactor=0 除零)
类型 数量
🔴 阻塞 1
🟡 建议 0

⛔ 需要修改

likedislike
不准确?
CANN-robotCANN-robot成员
22 天前 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
22 天前 评论:

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
repo-cann/cann-outreach ✅ shaoyf, 傅涛 (2/2) ✅ shaoyf, 傅涛 (2/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robot
CANN-robot成员
22 天前 评论:

CLA Signature Pass

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

likedislike
atomgit-bot
atomgit-bot22 天前进行代码检视1
2026/CANN-Code-Detective/Challenge07-SigmoidCustom/PR_code/secsmart_OpenGoodCANNJu/code/challenge07_sigmoidcustom/op_host/sigmoid_tiling.cpp
@@ -0,0 +34,4 @@
34+ // 多核切分:每核处理 blockFactor 个元素,核内再按 TILE_NUM 分片搬入 UB
35+ tiling->totalNum = totalLength;
36+ tiling->blockFactor = totalLength / BLOCK_DIM;
37+ tiling->ubFactor = tiling->blockFactor / TILE_NUM;
atomgit-bot
atomgit-bot22 天前评论:

🟠 High Priority

变更行(op_host/sigmoid_tiling.cpp:35-37)用 totalLength / BLOCK_DIM 与 blockFactor / TILE_NUM 做整除切分,既未处理余数也未校验商为 0:

建议:切分时显式处理余数与下界:blockFactor 至少为 1(或 totalLength<BLOCK_DIM 时下调 blockDim),并单独下发尾部块长度(lastBlock/lastTile)让 kernel 用 DataCopyPad 或独立分支处理余数,避免尾部元素丢失与 ubFactor==0 除零。

likedislike
不准确?
OpenGood_WeChat
OpenGood_WeChat
20 天前 评论:

已按审查意见修复:

  1. examples 示例:成功路径与三处失败早退路径均补充 aclReleaseOpExecutor(executor);
  2. 测试数据:输入改为固定种子 [-1,1) 随机数据(覆盖正负值两侧与零附近),并新增自检断言(禁止 golden==input、要求输入含正负号)。

/compile

likedislike
OpenGood_WeChatOpenGood_WeChat
20 天前 预合并成功(commit_id: 1b49391df7757b87d277d0213c1e46024940c7f4)
此处折叠了9条事件消息 查看更多
CANN-robotCANN-robot成员
20 天前 添加了label:cann-cla/yes
shaoyf成员
6 天前 评论:

/approve
/lgtm

likedislike
fulltower成员
6 天前 评论:

/approve
/lgtm

likedislike
CANN-robotCANN-robot成员
6 天前 添加了label:lgtmapproved
CANN-robot
CANN-robot成员
6 天前 评论:

The MR can not be merged, because of CodeReview discussion not resolved

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike
fulltower成员
6 天前 评论:

/check-pr

likedislike
CANN-robot
CANN-robot成员
6 天前 评论:

The MR can not be merged, because of CodeReview discussion not resolved

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike
Ffulltower成员
6 天前 解决了最后一个问题
fulltower成员
6 天前 评论:

/check-pr

likedislike
CANN-robotCANN-robot成员
6 天前 合入了pull request