Pull Request已成功合入, 合并人@CANN-robot
(感谢 OpenGood_WeChat 的贡献)变更摘要
本 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提供构建与测试入口。


/compile


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
/approveor/lgtm- Commenting
/approveimplies 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. 👍


🟠 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 除零。


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


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.


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.


闪捷信息科技有限公司
团队信息
成员
算子: 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