blob: 4044f06ac47993dbef329e07f03e1a9f04761c01 [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"
John Mcloughlin0ec00872023-05-15 17:03:49 +010017#include "Power.hpp"
18#include "SquaredDifference.hpp"
josh minor4a3c6102020-01-06 16:40:46 -060019
saoste012df12b32018-11-28 16:57:20 +000020
David Beck591cdb72018-09-11 16:37:14 +010021namespace armnn
22{
23
Derek Lambertif30f7d32019-04-09 10:25:02 +010024template <typename Functor>
josh minor4a3c6102020-01-06 16:40:46 -060025ElementwiseBinaryFunction<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 Beck591cdb72018-09-11 16:37:14 +010031{
32 BroadcastLoop(inShape0, inShape1, outShape).Unroll(Functor(), 0, inData0, inData1, outData);
33}
34
josh minor4a3c6102020-01-06 16:40:46 -060035template <typename Functor>
36ElementwiseUnaryFunction<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 Conroyaba90cd2020-11-06 16:28:18 +000044template <typename Functor>
45LogicalBinaryFunction<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
55template <typename Functor>
56LogicalUnaryFunction<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 Beck591cdb72018-09-11 16:37:14 +010064} //namespace armnn
65
josh minor4a3c6102020-01-06 16:40:46 -060066template struct armnn::ElementwiseBinaryFunction<std::plus<float>>;
67template struct armnn::ElementwiseBinaryFunction<std::minus<float>>;
68template struct armnn::ElementwiseBinaryFunction<std::multiplies<float>>;
69template struct armnn::ElementwiseBinaryFunction<std::divides<float>>;
70template struct armnn::ElementwiseBinaryFunction<armnn::maximum<float>>;
71template struct armnn::ElementwiseBinaryFunction<armnn::minimum<float>>;
John Mcloughlin0ec00872023-05-15 17:03:49 +010072template struct armnn::ElementwiseBinaryFunction<armnn::power<float>>;
73template struct armnn::ElementwiseBinaryFunction<armnn::squaredDifference<float>>;
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +010074
Finn Williamscbd2c232020-06-22 15:58:32 +010075template struct armnn::ElementwiseBinaryFunction<std::plus<int32_t>>;
76template struct armnn::ElementwiseBinaryFunction<std::minus<int32_t>>;
77template struct armnn::ElementwiseBinaryFunction<std::multiplies<int32_t>>;
78template struct armnn::ElementwiseBinaryFunction<std::divides<int32_t>>;
79template struct armnn::ElementwiseBinaryFunction<armnn::maximum<int32_t>>;
80template struct armnn::ElementwiseBinaryFunction<armnn::minimum<int32_t>>;
John Mcloughlin0ec00872023-05-15 17:03:49 +010081template struct armnn::ElementwiseBinaryFunction<armnn::power<int32_t>>;
82template struct armnn::ElementwiseBinaryFunction<armnn::squaredDifference<int32_t>>;
Finn Williamscbd2c232020-06-22 15:58:32 +010083
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +010084// Comparison
josh minor4a3c6102020-01-06 16:40:46 -060085template struct armnn::ElementwiseBinaryFunction<std::equal_to<float>>;
86template struct armnn::ElementwiseBinaryFunction<std::greater<float>>;
87template struct armnn::ElementwiseBinaryFunction<std::greater_equal<float>>;
88template struct armnn::ElementwiseBinaryFunction<std::less<float>>;
89template struct armnn::ElementwiseBinaryFunction<std::less_equal<float>>;
90template struct armnn::ElementwiseBinaryFunction<std::not_equal_to<float>>;
91
92// Unary
93template struct armnn::ElementwiseUnaryFunction<armnn::abs<float>>;
Teresa Charlin93f0ad02023-03-23 15:28:02 +000094template struct armnn::ElementwiseUnaryFunction<armnn::ceil<float>>;
josh minor4a3c6102020-01-06 16:40:46 -060095template struct armnn::ElementwiseUnaryFunction<armnn::exp<float>>;
Teresa Charlin50de4fa2021-05-31 18:47:33 +010096template struct armnn::ElementwiseUnaryFunction<armnn::log<float>>;
josh minor4a3c6102020-01-06 16:40:46 -060097template struct armnn::ElementwiseUnaryFunction<std::negate<float>>;
98template struct armnn::ElementwiseUnaryFunction<armnn::rsqrt<float>>;
Teresa Charlin50de4fa2021-05-31 18:47:33 +010099template struct armnn::ElementwiseUnaryFunction<armnn::sin<float>>;
josh minor4a3c6102020-01-06 16:40:46 -0600100template struct armnn::ElementwiseUnaryFunction<armnn::sqrt<float>>;
James Conroyaba90cd2020-11-06 16:28:18 +0000101
102// Logical Unary
103template struct armnn::LogicalUnaryFunction<std::logical_not<bool>>;
104template struct armnn::LogicalBinaryFunction<std::logical_and<bool>>;
105template struct armnn::LogicalBinaryFunction<std::logical_or<bool>>;