Thanks for sending an requirement! Please fill in the following template to help quickly solve your problem.
Relu6D 算子支持 Ascend950 ascendc 实现
长尾算子开发
Relu6D 是带缩放系数的 ReLU6 激活函数(y = min(max(x, 0), 6*scale)),源自 MobileNet 系列轻量级视觉网络。相比标准 ReLU6(固定阈值 6),Relu6D 通过 scale 属性提供可变上界阈值,在低精度量化(FP16/INT8)场景下提供更灵活的数值稳定性控制。当前 Ascend950 平台缺少该算子的 ascendc 实现,需新增以支持模型在 950 上的推理与训练。
y = min(max(x, 0), 6·scale)
[0, 6·scale]
x
y
scale
blockNum = ceil(totalElements / maxElemPerCore)
former
tail
UpdateMask(rem)
Reg::Maxs(x, 0)
Reg::Mins(_, 6·scale)
static_assert
bf16 → Cast→fp32 → clamp → Cast(CAST_RINT)→bf16
clamp_min(x, 0) * 1 → min(_, 6·scale)
Reg::Maxs/Mins
Float(4B)
float
double
upperThreshold
6·scale
min(max(x,0), 负数)
min/max
aclnn_exclude
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. 算子规格
y = min(max(x, 0), 6·scale),逐元素 clamp,值域[0, 6·scale]x(单输入)y(shape/dtype 与x一致)scale(Float 4B,默认 1.0,可选)2. 计算链路与实现方案
blockNum = ceil(totalElements / maxElemPerCore)均匀切分;每个核再按 UB 切former(满块)+tail(尾块),通过UpdateMask(rem)精确屏蔽越界元素。Reg::Maxs(x, 0)→Reg::Mins(_, 6·scale))。static_assert声明层通过 ≠ backend 物化通过),走 cast-compute 模式:bf16 → Cast→fp32 → clamp → Cast(CAST_RINT)→bf16,真机零精度损失。clamp_min(x, 0) * 1 → min(_, 6·scale),不镜像 kernel 的Reg::Maxs/Mins与 tiling,保证交叉验证的独立性。3. 关键设计决策
Float(4B),aclnn L0 用float(非double)double会致 OP_ATTR 序列化错位、upperThreshold恒 0(联调真机暴露)6·scale(负值),非 0min(max(x,0), 负数)必为负(CP1.5 用户确认)min/max指令硬件默认语义aclnn_exclude