Matteo Martincigh | ab9e525 | 2019-06-13 17:27:46 +0100 | [diff] [blame] | 1 | // |
| 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 | |
| 10 | namespace armnn |
| 11 | { |
| 12 | |
| 13 | void 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 |