Prelu
Applicability
Product |
Supported |
|---|---|
Atlas 350 Accelerator Card |
√ |
x |
|
x |
|
x |
|
x |
|
x |
|
x |
Function Usage
Writes src0 to dst directly if src0 is greater than 0. Otherwise, writes the result of src0*src1 to dst. The formula is as follows:

Prototype
template <typename T = DefaultType, MaskMergeMode mode = MaskMergeMode::ZEROING, typename U> __simd_callee__ inline void Prelu(U &dstReg, U &srcReg0, U &srcReg1, MaskReg &mask);
Parameters
Parameter |
Description |
|---|---|
T |
Data type of the vector destination operand and source operand. For the Atlas 350 Accelerator Card, the supported data types are half and float. |
mode |
|
U |
RegTensor type of the destination operand, for example, RegTensor<half>. It is automatically inferred by the compiler and does not need to be specified. |
Parameter |
Input/Output |
Description |
|---|---|---|
dstReg |
Output |
Destination operand. The type is RegTensor. |
srcReg0 |
Input |
Source operand. The type is RegTensor. The source and destination operands must have the same data type. |
srcReg1 |
Input |
Source operand. The type is RegTensor. The source and destination operands must have the same data type. |
mask |
Input |
Valid indication of the source operand element operation. For details, see MaskReg. |
Returns
None
Restrictions
None
Examples
template<typename T>
__simd_vf__ inline void Prelu(__ubuf__ T* dstAddr, __ubuf__ T* src0Addr, __ubuf__ T* src1Addr, uint32_t count, uint32_t oneRepeatSize, uint16_t repeatTimes)
{
AscendC::Reg::RegTensor<T> srcReg0;
AscendC::Reg::RegTensor<T> srcReg1;
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(srcReg0, src0Addr + i * oneRepeatSize);
AscendC::Reg::LoadAlign(srcReg1, src1Addr + i * oneRepeatSize);
AscendC::Reg::Prelu(dstReg, srcReg0, srcReg1, mask);
AscendC::Reg::StoreAlign(dstAddr + i * oneRepeatSize, dstReg, mask);
}
}