David Beck | 591cdb7 | 2018-09-11 16:37:14 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
Éanna Ó Catháin | d57415d | 2018-11-28 16:24:38 +0000 | [diff] [blame] | 6 | #include "ElementwiseFunction.hpp" |
David Beck | 591cdb7 | 2018-09-11 16:37:14 +0100 | [diff] [blame] | 7 | #include "Broadcast.hpp" |
| 8 | #include <functional> |
Éanna Ó Catháin | 20e5880 | 2018-12-04 10:29:06 +0000 | [diff] [blame] | 9 | #include "Minimum.hpp" |
saoste01 | 2df12b3 | 2018-11-28 16:57:20 +0000 | [diff] [blame] | 10 | #include "Maximum.hpp" |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 11 | #include "Abs.hpp" |
| 12 | #include "Exp.hpp" |
| 13 | #include "Rsqrt.hpp" |
| 14 | #include "Sqrt.hpp" |
| 15 | |
saoste01 | 2df12b3 | 2018-11-28 16:57:20 +0000 | [diff] [blame] | 16 | |
David Beck | 591cdb7 | 2018-09-11 16:37:14 +0100 | [diff] [blame] | 17 | namespace armnn |
| 18 | { |
| 19 | |
Derek Lamberti | f30f7d3 | 2019-04-09 10:25:02 +0100 | [diff] [blame] | 20 | template <typename Functor> |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 21 | ElementwiseBinaryFunction<Functor>::ElementwiseBinaryFunction(const TensorShape& inShape0, |
| 22 | const TensorShape& inShape1, |
| 23 | const TensorShape& outShape, |
| 24 | Decoder<InType>& inData0, |
| 25 | Decoder<InType>& inData1, |
| 26 | Encoder<OutType>& outData) |
David Beck | 591cdb7 | 2018-09-11 16:37:14 +0100 | [diff] [blame] | 27 | { |
| 28 | BroadcastLoop(inShape0, inShape1, outShape).Unroll(Functor(), 0, inData0, inData1, outData); |
| 29 | } |
| 30 | |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 31 | template <typename Functor> |
| 32 | ElementwiseUnaryFunction<Functor>::ElementwiseUnaryFunction(const TensorShape& inShape, |
| 33 | const TensorShape& outShape, |
| 34 | Decoder<InType>& inData, |
| 35 | Encoder<OutType>& outData) |
| 36 | { |
| 37 | BroadcastLoop(inShape, outShape).Unroll(Functor(), 0, inData, outData); |
| 38 | } |
| 39 | |
David Beck | 591cdb7 | 2018-09-11 16:37:14 +0100 | [diff] [blame] | 40 | } //namespace armnn |
| 41 | |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 42 | template struct armnn::ElementwiseBinaryFunction<std::plus<float>>; |
| 43 | template struct armnn::ElementwiseBinaryFunction<std::minus<float>>; |
| 44 | template struct armnn::ElementwiseBinaryFunction<std::multiplies<float>>; |
| 45 | template struct armnn::ElementwiseBinaryFunction<std::divides<float>>; |
| 46 | template struct armnn::ElementwiseBinaryFunction<armnn::maximum<float>>; |
| 47 | template struct armnn::ElementwiseBinaryFunction<armnn::minimum<float>>; |
Aron Virginas-Tar | 77bfb5e | 2019-10-16 17:45:38 +0100 | [diff] [blame] | 48 | |
Finn Williams | cbd2c23 | 2020-06-22 15:58:32 +0100 | [diff] [blame] | 49 | template struct armnn::ElementwiseBinaryFunction<std::plus<int32_t>>; |
| 50 | template struct armnn::ElementwiseBinaryFunction<std::minus<int32_t>>; |
| 51 | template struct armnn::ElementwiseBinaryFunction<std::multiplies<int32_t>>; |
| 52 | template struct armnn::ElementwiseBinaryFunction<std::divides<int32_t>>; |
| 53 | template struct armnn::ElementwiseBinaryFunction<armnn::maximum<int32_t>>; |
| 54 | template struct armnn::ElementwiseBinaryFunction<armnn::minimum<int32_t>>; |
| 55 | |
Aron Virginas-Tar | 77bfb5e | 2019-10-16 17:45:38 +0100 | [diff] [blame] | 56 | // Comparison |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 57 | template struct armnn::ElementwiseBinaryFunction<std::equal_to<float>>; |
| 58 | template struct armnn::ElementwiseBinaryFunction<std::greater<float>>; |
| 59 | template struct armnn::ElementwiseBinaryFunction<std::greater_equal<float>>; |
| 60 | template struct armnn::ElementwiseBinaryFunction<std::less<float>>; |
| 61 | template struct armnn::ElementwiseBinaryFunction<std::less_equal<float>>; |
| 62 | template struct armnn::ElementwiseBinaryFunction<std::not_equal_to<float>>; |
| 63 | |
| 64 | // Unary |
| 65 | template struct armnn::ElementwiseUnaryFunction<armnn::abs<float>>; |
| 66 | template struct armnn::ElementwiseUnaryFunction<armnn::exp<float>>; |
| 67 | template struct armnn::ElementwiseUnaryFunction<std::negate<float>>; |
| 68 | template struct armnn::ElementwiseUnaryFunction<armnn::rsqrt<float>>; |
| 69 | template struct armnn::ElementwiseUnaryFunction<armnn::sqrt<float>>; |