blob: c5b0ad1f24a8790f5d270b843829d1e522e6c563 [file] [log] [blame]
David Beck591cdb72018-09-11 16:37:14 +01001//
Teresa Charlin93f0ad02023-03-23 15:28:02 +00002// Copyright © 2017-2021,2023 Arm Ltd and Contributors. All rights reserved.
David Beck591cdb72018-09-11 16:37:14 +01003// SPDX-License-Identifier: MIT
4//
5
Éanna Ó Catháind57415d2018-11-28 16:24:38 +00006#include "ElementwiseFunction.hpp"
David Beck591cdb72018-09-11 16:37:14 +01007#include "Broadcast.hpp"
Éanna Ó Catháin20e58802018-12-04 10:29:06 +00008#include "Minimum.hpp"
saoste012df12b32018-11-28 16:57:20 +00009#include "Maximum.hpp"
josh minor4a3c6102020-01-06 16:40:46 -060010#include "Abs.hpp"
Teresa Charlin93f0ad02023-03-23 15:28:02 +000011#include "Ceil.hpp"
josh minor4a3c6102020-01-06 16:40:46 -060012#include "Exp.hpp"
Teresa Charlin50de4fa2021-05-31 18:47:33 +010013#include "Log.hpp"
josh minor4a3c6102020-01-06 16:40:46 -060014#include "Rsqrt.hpp"
Teresa Charlin50de4fa2021-05-31 18:47:33 +010015#include "Sin.hpp"
josh minor4a3c6102020-01-06 16:40:46 -060016#include "Sqrt.hpp"
17
saoste012df12b32018-11-28 16:57:20 +000018
David Beck591cdb72018-09-11 16:37:14 +010019namespace armnn
20{
21
Derek Lambertif30f7d32019-04-09 10:25:02 +010022template <typename Functor>
josh minor4a3c6102020-01-06 16:40:46 -060023ElementwiseBinaryFunction<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 Beck591cdb72018-09-11 16:37:14 +010029{
30 BroadcastLoop(inShape0, inShape1, outShape).Unroll(Functor(), 0, inData0, inData1, outData);
31}
32
josh minor4a3c6102020-01-06 16:40:46 -060033template <typename Functor>
34ElementwiseUnaryFunction<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 Conroyaba90cd2020-11-06 16:28:18 +000042template <typename Functor>
43LogicalBinaryFunction<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
53template <typename Functor>
54LogicalUnaryFunction<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 Beck591cdb72018-09-11 16:37:14 +010062} //namespace armnn
63
josh minor4a3c6102020-01-06 16:40:46 -060064template struct armnn::ElementwiseBinaryFunction<std::plus<float>>;
65template struct armnn::ElementwiseBinaryFunction<std::minus<float>>;
66template struct armnn::ElementwiseBinaryFunction<std::multiplies<float>>;
67template struct armnn::ElementwiseBinaryFunction<std::divides<float>>;
68template struct armnn::ElementwiseBinaryFunction<armnn::maximum<float>>;
69template struct armnn::ElementwiseBinaryFunction<armnn::minimum<float>>;
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +010070
Finn Williamscbd2c232020-06-22 15:58:32 +010071template struct armnn::ElementwiseBinaryFunction<std::plus<int32_t>>;
72template struct armnn::ElementwiseBinaryFunction<std::minus<int32_t>>;
73template struct armnn::ElementwiseBinaryFunction<std::multiplies<int32_t>>;
74template struct armnn::ElementwiseBinaryFunction<std::divides<int32_t>>;
75template struct armnn::ElementwiseBinaryFunction<armnn::maximum<int32_t>>;
76template struct armnn::ElementwiseBinaryFunction<armnn::minimum<int32_t>>;
77
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +010078// Comparison
josh minor4a3c6102020-01-06 16:40:46 -060079template struct armnn::ElementwiseBinaryFunction<std::equal_to<float>>;
80template struct armnn::ElementwiseBinaryFunction<std::greater<float>>;
81template struct armnn::ElementwiseBinaryFunction<std::greater_equal<float>>;
82template struct armnn::ElementwiseBinaryFunction<std::less<float>>;
83template struct armnn::ElementwiseBinaryFunction<std::less_equal<float>>;
84template struct armnn::ElementwiseBinaryFunction<std::not_equal_to<float>>;
85
86// Unary
87template struct armnn::ElementwiseUnaryFunction<armnn::abs<float>>;
Teresa Charlin93f0ad02023-03-23 15:28:02 +000088template struct armnn::ElementwiseUnaryFunction<armnn::ceil<float>>;
josh minor4a3c6102020-01-06 16:40:46 -060089template struct armnn::ElementwiseUnaryFunction<armnn::exp<float>>;
Teresa Charlin50de4fa2021-05-31 18:47:33 +010090template struct armnn::ElementwiseUnaryFunction<armnn::log<float>>;
josh minor4a3c6102020-01-06 16:40:46 -060091template struct armnn::ElementwiseUnaryFunction<std::negate<float>>;
92template struct armnn::ElementwiseUnaryFunction<armnn::rsqrt<float>>;
Teresa Charlin50de4fa2021-05-31 18:47:33 +010093template struct armnn::ElementwiseUnaryFunction<armnn::sin<float>>;
josh minor4a3c6102020-01-06 16:40:46 -060094template struct armnn::ElementwiseUnaryFunction<armnn::sqrt<float>>;
James Conroyaba90cd2020-11-06 16:28:18 +000095
96// Logical Unary
97template struct armnn::LogicalUnaryFunction<std::logical_not<bool>>;
98template struct armnn::LogicalBinaryFunction<std::logical_and<bool>>;
99template struct armnn::LogicalBinaryFunction<std::logical_or<bool>>;