已关闭
[Requirement|需求建议]: Relu6D 算子支持 Ascend950 ascendc 实现 #4022
zhongheng创建于  7月10日关闭于  7月16日
zhongheng
7月10日 创建

Thanks for sending an requirement! Please fill in the following template to help quickly solve your problem.

Backgroud(背景信息)

Relu6D 算子支持 Ascend950 ascendc 实现

Origin(信息来源)

长尾算子开发

Benefit / Necessity (价值/作用)

Relu6D 是带缩放系数的 ReLU6 激活函数(y = min(max(x, 0), 6*scale)),源自 MobileNet 系列轻量级视觉网络。相比标准 ReLU6(固定阈值 6),Relu6D 通过 scale 属性提供可变上界阈值,在低精度量化(FP16/INT8)场景下提供更灵活的数值稳定性控制。当前 Ascend950 平台缺少该算子的 ascendc 实现,需新增以支持模型在 950 上的推理与训练。

Design(设计方案)

1. 算子规格

算子名 Relu6D
公式 y = min(max(x, 0), 6·scale),逐元素 clamp,值域 [0, 6·scale]
输入 x(单输入)
输出 y(shape/dtype 与 x 一致)
属性 scale(Float 4B,默认 1.0,可选)
dtype FLOAT16 / BFLOAT16 / FLOAT / INT32
平台 Ascend950(dav-3510 / arch35)单目标

2. 计算链路与实现方案

  • workspace=0,纯逐元素运算,无 workspace。
  • 多核切分:按 blockNum = ceil(totalElements / maxElemPerCore) 均匀切分;每个核再按 UB 切 former(满块)+ tail(尾块),通过 UpdateMask(rem) 精确屏蔽越界元素。
  • 按 dtype 分支 4 个 TilingKey(KEY_FP16 / KEY_BF16 / KEY_FP32 / KEY_INT32):
    • fp16 / fp32 / int32:原 dtype 直算,RegBase Vector 两步 clamp(Reg::Maxs(x, 0)Reg::Mins(_, 6·scale))。
    • bf16:DAV_3510 backend 物化层拒绝 bf16 标量 clamp(static_assert 声明层通过 ≠ backend 物化通过),走 cast-compute 模式:bf16 → Cast→fp32 → clamp → Cast(CAST_RINT)→bf16,真机零精度损失。
  • golden 独立于 kernel:用 torch 小算子拼接 clamp_min(x, 0) * 1 → min(_, 6·scale),不镜像 kernel 的 Reg::Maxs/Mins 与 tiling,保证交叉验证的独立性。

3. 关键设计决策

决策点 选择 理由
scale 属性类型 op 属性注册 Float(4B),aclnn L0 用 float(非 double double 会致 OP_ATTR 序列化错位、upperThreshold 恒 0(联调真机暴露)
scale<0 语义 输出 = 6·scale(负值),非 0 按真值源 golden/formula,min(max(x,0), 负数) 必为负(CP1.5 用户确认)
NaN 传播 不做显式 NaN 传播,遵从底层 min/max 指令硬件默认语义 spec.yaml 已声明;三方对比 56 个 with_nan 用例报 ratio=inf 属 NPU/GPU 硬件语义差异,设计内行为非缺陷
bf16 精度 坚守 rtol=atol=1e-3(未用 4e-3 社区松值) cast-compute 精确,clamp 误差实测恒 0
ACLNNTYPE aclnn_exclude 自动生成 aclnn 会撞符号,手写 L0/L2 仅内部验收
likedislike
Zzhongheng
7月10日 修改标题为 “[Requirement|需求建议]: Relu6D 算子支持 Ascend950 ascendc 实现”,原标题为“[Requirement|需求建议]: ”
Zzhongheng
7月10日 关联了pull request:[CANNBot]新增Relu6D算子
yuning_chenyuning_chen成员
7月10日 将 zhongheng 设为负责人
Zzhongheng
7月16日 issue状态由 进行中 改变为 已完成
Zzhongheng
7月16日 关闭了 issue
CANN-robotCANN-robot成员
7月16日 添加了label:Accepted
Zzhongheng
7月31日 修改了issue 的描述