xref: /aosp_15_r20/external/armnn/src/backends/reference/workloads/ElementwiseFunction.cpp (revision 89c4ff92f2867872bb9e2354d150bf0c8c502810)
1 //
2 // Copyright © 2017-2021,2023 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "ElementwiseFunction.hpp"
7 #include "Broadcast.hpp"
8 #include "Minimum.hpp"
9 #include "Maximum.hpp"
10 #include "Abs.hpp"
11 #include "Ceil.hpp"
12 #include "Exp.hpp"
13 #include "Log.hpp"
14 #include "Rsqrt.hpp"
15 #include "Sin.hpp"
16 #include "Sqrt.hpp"
17 
18 
19 namespace armnn
20 {
21 
22 template <typename Functor>
ElementwiseBinaryFunction(const TensorShape & inShape0,const TensorShape & inShape1,const TensorShape & outShape,Decoder<InType> & inData0,Decoder<InType> & inData1,Encoder<OutType> & outData)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)
29 {
30     BroadcastLoop(inShape0, inShape1, outShape).Unroll(Functor(), 0, inData0, inData1, outData);
31 }
32 
33 template <typename Functor>
ElementwiseUnaryFunction(const TensorShape & inShape,const TensorShape & outShape,Decoder<InType> & inData,Encoder<OutType> & outData)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 
42 template <typename Functor>
LogicalBinaryFunction(const TensorShape & inShape0,const TensorShape & inShape1,const TensorShape & outShape,Decoder<InType> & inData0,Decoder<InType> & inData1,Encoder<OutType> & outData)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>
LogicalUnaryFunction(const TensorShape & inShape,const TensorShape & outShape,Decoder<InType> & inData,Encoder<OutType> & outData)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 
62 } //namespace armnn
63 
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>>;
70 
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 
78 // Comparison
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>>;
88 template struct armnn::ElementwiseUnaryFunction<armnn::ceil<float>>;
89 template struct armnn::ElementwiseUnaryFunction<armnn::exp<float>>;
90 template struct armnn::ElementwiseUnaryFunction<armnn::log<float>>;
91 template struct armnn::ElementwiseUnaryFunction<std::negate<float>>;
92 template struct armnn::ElementwiseUnaryFunction<armnn::rsqrt<float>>;
93 template struct armnn::ElementwiseUnaryFunction<armnn::sin<float>>;
94 template struct armnn::ElementwiseUnaryFunction<armnn::sqrt<float>>;
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>>;
100