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