ArmNN
 25.02
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RefElementwiseUnaryWorkload.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2020-2024 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
7 
8 #include "Decoders.hpp"
10 #include "Encoders.hpp"
11 #include "RefWorkloadUtils.hpp"
12 #include "Abs.hpp"
13 #include "Ceil.hpp"
14 #include "Exp.hpp"
15 #include "Log.hpp"
16 #include "Rsqrt.hpp"
17 #include "Sin.hpp"
18 #include "Sqrt.hpp"
19 
20 #include <Profiling.hpp>
21 
22 #include <armnn/TypesUtils.hpp>
23 
24 #include <functional>
25 
26 namespace armnn
27 {
28 
30  const WorkloadInfo& info)
32 {}
33 
35 {
37 }
38 
39 void RefElementwiseUnaryWorkload::Execute(std::vector<ITensorHandle*> inputs, std::vector<ITensorHandle*> outputs) const
40 {
41  ARMNN_SCOPED_PROFILING_EVENT_REF_NAME_GUID("RefElementwiseUnaryWorkload_Execute");
42 
43  const TensorInfo& inputInfo = GetTensorInfo(inputs[0]);
44  const TensorInfo& outputInfo = GetTensorInfo(outputs[0]);
45 
46  const TensorShape& inShape = inputInfo.GetShape();
47  const TensorShape& outShape = outputInfo.GetShape();
48 
49  std::unique_ptr<Decoder<InType>> input = MakeDecoder<InType>(inputInfo, inputs[0]->Map());
50  std::unique_ptr<Encoder<OutType>> output= MakeEncoder<OutType>(outputInfo, outputs[0]->Map());
51 
52  using AbsFunction = ElementwiseUnaryFunction<abs<InType>>;
53  using CeilFunction = ElementwiseUnaryFunction<ceil<InType>>;
54  using ExpFunction = ElementwiseUnaryFunction<exp<InType>>;
55  using LogFunction = ElementwiseUnaryFunction<log<InType>>;
57  using RsqrtFunction = ElementwiseUnaryFunction<rsqrt<InType>>;
58  using SinFunction = ElementwiseUnaryFunction<sin<InType>>;
59  using SqrtFunction = ElementwiseUnaryFunction<sqrt<InType>>;
60 
61  switch (m_Data.m_Parameters.m_Operation)
62  {
64  {
65  AbsFunction(inShape, outShape, *input, *output);
66  break;
67  }
69  {
70  CeilFunction(inShape, outShape, *input, *output);
71  break;
72  }
74  {
75  ExpFunction(inShape, outShape, *input, *output);
76  break;
77  }
79  {
80  LogFunction(inShape, outShape, *input, *output);
81  break;
82  }
84  {
85  NegFunction(inShape, outShape, *input, *output);
86  break;
87  }
89  {
90  RsqrtFunction(inShape, outShape, *input, *output);
91  break;
92  }
94  {
95  SinFunction(inShape, outShape, *input, *output);
96  break;
97  }
99  {
100  SqrtFunction(inShape, outShape, *input, *output);
101  break;
102  }
103  default:
104  {
105  throw InvalidArgumentException(std::string("Unsupported unary operation ") +
106  GetUnaryOperationAsCString(m_Data.m_Parameters.m_Operation), CHECK_LOCATION());
107  }
108  }
109 }
110 
111 } // namespace armnn
#define CHECK_LOCATION()
Definition: Exceptions.hpp:203
#define ARMNN_SCOPED_PROFILING_EVENT_REF_NAME_GUID(label)
Creates a profiling event that uses GetGuid() and GetName() from the calling class.
QueueDescriptor m_Data
Definition: Workload.hpp:74
RefElementwiseUnaryWorkload(const ElementwiseUnaryQueueDescriptor &descriptor, const WorkloadInfo &info)
const TensorShape & GetShape() const
Definition: Tensor.hpp:193
Copyright (c) 2021 ARM Limited and Contributors.
constexpr char const * GetUnaryOperationAsCString(UnaryOperation operation)
Definition: TypesUtils.hpp:93
const TensorInfo & GetTensorInfo(const ITensorHandle *tensorHandle)
float32 helpers
std::vector< ITensorHandle * > m_Inputs
std::vector< ITensorHandle * > m_Outputs
Contains information about TensorInfos of a layer.