David Beck | 591cdb7 | 2018-09-11 16:37:14 +0100 | [diff] [blame] | 1 | // |
Teresa Charlin | 93f0ad0 | 2023-03-23 15:28:02 +0000 | [diff] [blame] | 2 | // Copyright © 2017-2021,2023 Arm Ltd and Contributors. All rights reserved. |
David Beck | 591cdb7 | 2018-09-11 16:37:14 +0100 | [diff] [blame] | 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" |
Éanna Ó Catháin | 20e5880 | 2018-12-04 10:29:06 +0000 | [diff] [blame] | 8 | #include "Minimum.hpp" |
saoste01 | 2df12b3 | 2018-11-28 16:57:20 +0000 | [diff] [blame] | 9 | #include "Maximum.hpp" |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 10 | #include "Abs.hpp" |
Teresa Charlin | 93f0ad0 | 2023-03-23 15:28:02 +0000 | [diff] [blame] | 11 | #include "Ceil.hpp" |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 12 | #include "Exp.hpp" |
Teresa Charlin | 50de4fa | 2021-05-31 18:47:33 +0100 | [diff] [blame] | 13 | #include "Log.hpp" |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 14 | #include "Rsqrt.hpp" |
Teresa Charlin | 50de4fa | 2021-05-31 18:47:33 +0100 | [diff] [blame] | 15 | #include "Sin.hpp" |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 16 | #include "Sqrt.hpp" |
John Mcloughlin | 0ec0087 | 2023-05-15 17:03:49 +0100 | [diff] [blame] | 17 | #include "Power.hpp" |
| 18 | #include "SquaredDifference.hpp" |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 19 | |
saoste01 | 2df12b3 | 2018-11-28 16:57:20 +0000 | [diff] [blame] | 20 | |
David Beck | 591cdb7 | 2018-09-11 16:37:14 +0100 | [diff] [blame] | 21 | namespace armnn |
| 22 | { |
| 23 | |
Derek Lamberti | f30f7d3 | 2019-04-09 10:25:02 +0100 | [diff] [blame] | 24 | template <typename Functor> |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 25 | ElementwiseBinaryFunction<Functor>::ElementwiseBinaryFunction(const TensorShape& inShape0, |
| 26 | const TensorShape& inShape1, |
| 27 | const TensorShape& outShape, |
| 28 | Decoder<InType>& inData0, |
| 29 | Decoder<InType>& inData1, |
| 30 | Encoder<OutType>& outData) |
David Beck | 591cdb7 | 2018-09-11 16:37:14 +0100 | [diff] [blame] | 31 | { |
| 32 | BroadcastLoop(inShape0, inShape1, outShape).Unroll(Functor(), 0, inData0, inData1, outData); |
| 33 | } |
| 34 | |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 35 | template <typename Functor> |
| 36 | ElementwiseUnaryFunction<Functor>::ElementwiseUnaryFunction(const TensorShape& inShape, |
| 37 | const TensorShape& outShape, |
| 38 | Decoder<InType>& inData, |
| 39 | Encoder<OutType>& outData) |
| 40 | { |
| 41 | BroadcastLoop(inShape, outShape).Unroll(Functor(), 0, inData, outData); |
| 42 | } |
| 43 | |
James Conroy | aba90cd | 2020-11-06 16:28:18 +0000 | [diff] [blame] | 44 | template <typename Functor> |
| 45 | LogicalBinaryFunction<Functor>::LogicalBinaryFunction(const TensorShape& inShape0, |
| 46 | const TensorShape& inShape1, |
| 47 | const TensorShape& outShape, |
| 48 | Decoder<InType>& inData0, |
| 49 | Decoder<InType>& inData1, |
| 50 | Encoder<OutType>& outData) |
| 51 | { |
| 52 | BroadcastLoop(inShape0, inShape1, outShape).Unroll(Functor(), 0, inData0, inData1, outData); |
| 53 | } |
| 54 | |
| 55 | template <typename Functor> |
| 56 | LogicalUnaryFunction<Functor>::LogicalUnaryFunction(const TensorShape& inShape, |
| 57 | const TensorShape& outShape, |
| 58 | Decoder<InType>& inData, |
| 59 | Encoder<OutType>& outData) |
| 60 | { |
| 61 | BroadcastLoop(inShape, outShape).Unroll(Functor(), 0, inData, outData); |
| 62 | } |
| 63 | |
David Beck | 591cdb7 | 2018-09-11 16:37:14 +0100 | [diff] [blame] | 64 | } //namespace armnn |
| 65 | |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 66 | template struct armnn::ElementwiseBinaryFunction<std::plus<float>>; |
| 67 | template struct armnn::ElementwiseBinaryFunction<std::minus<float>>; |
| 68 | template struct armnn::ElementwiseBinaryFunction<std::multiplies<float>>; |
| 69 | template struct armnn::ElementwiseBinaryFunction<std::divides<float>>; |
| 70 | template struct armnn::ElementwiseBinaryFunction<armnn::maximum<float>>; |
| 71 | template struct armnn::ElementwiseBinaryFunction<armnn::minimum<float>>; |
John Mcloughlin | 0ec0087 | 2023-05-15 17:03:49 +0100 | [diff] [blame] | 72 | template struct armnn::ElementwiseBinaryFunction<armnn::power<float>>; |
| 73 | template struct armnn::ElementwiseBinaryFunction<armnn::squaredDifference<float>>; |
Aron Virginas-Tar | 77bfb5e | 2019-10-16 17:45:38 +0100 | [diff] [blame] | 74 | |
Finn Williams | cbd2c23 | 2020-06-22 15:58:32 +0100 | [diff] [blame] | 75 | template struct armnn::ElementwiseBinaryFunction<std::plus<int32_t>>; |
| 76 | template struct armnn::ElementwiseBinaryFunction<std::minus<int32_t>>; |
| 77 | template struct armnn::ElementwiseBinaryFunction<std::multiplies<int32_t>>; |
| 78 | template struct armnn::ElementwiseBinaryFunction<std::divides<int32_t>>; |
| 79 | template struct armnn::ElementwiseBinaryFunction<armnn::maximum<int32_t>>; |
| 80 | template struct armnn::ElementwiseBinaryFunction<armnn::minimum<int32_t>>; |
John Mcloughlin | 0ec0087 | 2023-05-15 17:03:49 +0100 | [diff] [blame] | 81 | template struct armnn::ElementwiseBinaryFunction<armnn::power<int32_t>>; |
| 82 | template struct armnn::ElementwiseBinaryFunction<armnn::squaredDifference<int32_t>>; |
Finn Williams | cbd2c23 | 2020-06-22 15:58:32 +0100 | [diff] [blame] | 83 | |
Aron Virginas-Tar | 77bfb5e | 2019-10-16 17:45:38 +0100 | [diff] [blame] | 84 | // Comparison |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 85 | template struct armnn::ElementwiseBinaryFunction<std::equal_to<float>>; |
| 86 | template struct armnn::ElementwiseBinaryFunction<std::greater<float>>; |
| 87 | template struct armnn::ElementwiseBinaryFunction<std::greater_equal<float>>; |
| 88 | template struct armnn::ElementwiseBinaryFunction<std::less<float>>; |
| 89 | template struct armnn::ElementwiseBinaryFunction<std::less_equal<float>>; |
| 90 | template struct armnn::ElementwiseBinaryFunction<std::not_equal_to<float>>; |
| 91 | |
| 92 | // Unary |
| 93 | template struct armnn::ElementwiseUnaryFunction<armnn::abs<float>>; |
Teresa Charlin | 93f0ad0 | 2023-03-23 15:28:02 +0000 | [diff] [blame] | 94 | template struct armnn::ElementwiseUnaryFunction<armnn::ceil<float>>; |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 95 | template struct armnn::ElementwiseUnaryFunction<armnn::exp<float>>; |
Teresa Charlin | 50de4fa | 2021-05-31 18:47:33 +0100 | [diff] [blame] | 96 | template struct armnn::ElementwiseUnaryFunction<armnn::log<float>>; |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 97 | template struct armnn::ElementwiseUnaryFunction<std::negate<float>>; |
| 98 | template struct armnn::ElementwiseUnaryFunction<armnn::rsqrt<float>>; |
Teresa Charlin | 50de4fa | 2021-05-31 18:47:33 +0100 | [diff] [blame] | 99 | template struct armnn::ElementwiseUnaryFunction<armnn::sin<float>>; |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 100 | template struct armnn::ElementwiseUnaryFunction<armnn::sqrt<float>>; |
James Conroy | aba90cd | 2020-11-06 16:28:18 +0000 | [diff] [blame] | 101 | |
| 102 | // Logical Unary |
| 103 | template struct armnn::LogicalUnaryFunction<std::logical_not<bool>>; |
| 104 | template struct armnn::LogicalBinaryFunction<std::logical_and<bool>>; |
| 105 | template struct armnn::LogicalBinaryFunction<std::logical_or<bool>>; |