Skip to content

LeakyRelu

产品支持情况

  • Ascend 950PR/Ascend 950DT:支持
  • Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持
  • Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持
  • Atlas 200I/500 A2 推理产品:不支持
  • Atlas 推理系列产品AI Core:不支持
  • Atlas 推理系列产品Vector Core:不支持
  • Atlas 训练系列产品:不支持

功能说明

头文件路径:"basic_api/reg_compute/kernel_reg_compute_vec_binary_scalar_intf.h"

该接口用于按元素执行Leaky ReLU(Leaky Rectified Linear Unit)操作:当源操作数中某元素大于0时,直接将该元素写入目的操作数;否则将该元素乘以标量值scalarValue后写入目的操作数。计算公式如下:

函数原型

C++
template <typename T = DefaultType, typename U, MaskMergeMode mode = MaskMergeMode::ZEROING, typename S>
__simd_callee__ inline void LeakyRelu(S& dstReg, S& srcReg, U scalarValue, MaskReg& mask)

参数说明

表 1 模板参数说明

参数名描述
T操作数数据类型。支持的数据类型请参考数据类型
U标量源操作数的数据类型。支持的数据类型请参考数据类型
modeMaskMergeMode枚举类型,选择MERGING模式或ZEROING模式。
• ZEROING模式下,mask未筛选的元素在dstReg中置零。
• MERGING模式当前不支持。
S源操作数和目的操作数的RegTensor类型,例如RegTensor<half>,由编译器自动推导,用户不需要填写。

表 2 参数说明

参数名输入/输出描述
dstReg输出目的操作数。
类型为RegTensor
srcReg输入源操作数。
类型为RegTensor
源操作数的数据类型需要与目的操作数保持一致。
scalarValue输入源操作数。类型为标量,数据类型需与目的操作数保持一致。
mask输入源操作数中元素有效性的指示,详细说明请参考MaskReg

数据类型

目的操作数与源操作数的数据类型需要保持一致。支持的数据类型为:half、float。

返回值说明

约束说明

调用示例

C++
template<typename T>
__simd_vf__ inline void LeakyReluVF(__ubuf__ T* dstAddr, __ubuf__ T* srcAddr, T scalarValue, uint32_t count, uint16_t oneRepeatSize, uint16_t repeatTimes)
{
    AscendC::Reg::RegTensor<T> srcReg;
    AscendC::Reg::RegTensor<T> dstReg;
    AscendC::Reg::MaskReg mask;
    for (uint16_t i = 0; i < repeatTimes; i++) {
        mask = AscendC::Reg::UpdateMask<T>(count);
        AscendC::Reg::LoadAlign(srcReg, srcAddr + i * oneRepeatSize);
        AscendC::Reg::LeakyRelu(dstReg, srcReg, scalarValue, mask);
        AscendC::Reg::StoreAlign(dstAddr + i * oneRepeatSize, dstReg, mask);
    }
}

免责声明:本站内容由 asc-devkit 仓 master 分支自动编译生成,属于持续开发版本,可能存在缺陷,仅供预览与参考。如需稳定及商用资料,请查阅官方 昇腾社区