blob: 458025bb0a917757e2bb8bacea3f58146e027c9c [file] [log] [blame]
Matteo Martincighab9e5252019-06-13 17:27:46 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "PreluImpl.hpp"
7#include "RefWorkloadUtils.hpp"
8#include "Broadcast.hpp"
9
10namespace armnn
11{
12
13void PreluImpl(const PreluQueueDescriptor& data,
14 Decoder<float>& inputData,
15 Decoder<float>& alphaData,
16 Encoder<float>& outputData)
17{
18 const TensorInfo& inputInfo = GetTensorInfo(data.m_Inputs[0]);
19 const TensorInfo& alphaInfo = GetTensorInfo(data.m_Inputs[1]);
20 const TensorInfo& outputInfo = GetTensorInfo(data.m_Outputs[0]);
21
22 const TensorShape& inputShape = inputInfo.GetShape();
23 const TensorShape& alphaShape = alphaInfo.GetShape();
24 const TensorShape& outputShape = outputInfo.GetShape();
25
26 // PReLU activation: f(x) = alpha * x for x < 0, f(x) = x for x >= 0
27 auto prelu = [](float x, float alpha)
28 {
29 return x < 0 ? alpha * x : x;
30 };
31
32 BroadcastLoop(inputShape, alphaShape, outputShape).Unroll(prelu, 0, inputData, alphaData, outputData);
33}
34
35} // namespace armnn