ArmNN
 24.02
RefElementwiseUnaryWorkload.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2020-2023 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 
40 {
41 
42  WorkingMemDescriptor* workingMemDescriptor = static_cast<WorkingMemDescriptor*>(executionData.m_Data);
43  Execute(workingMemDescriptor->m_Inputs, workingMemDescriptor->m_Outputs);
44 }
45 
46 void RefElementwiseUnaryWorkload::Execute(std::vector<ITensorHandle*> inputs, std::vector<ITensorHandle*> outputs) const
47 {
48  ARMNN_SCOPED_PROFILING_EVENT_REF_NAME_GUID("RefElementwiseUnaryWorkload_Execute");
49 
50  const TensorInfo& inputInfo = GetTensorInfo(inputs[0]);
51  const TensorInfo& outputInfo = GetTensorInfo(outputs[0]);
52 
53  const TensorShape& inShape = inputInfo.GetShape();
54  const TensorShape& outShape = outputInfo.GetShape();
55 
56  std::unique_ptr<Decoder<InType>> input = MakeDecoder<InType>(inputInfo, inputs[0]->Map());
57  std::unique_ptr<Encoder<OutType>> output= MakeEncoder<OutType>(outputInfo, outputs[0]->Map());
58 
59  using AbsFunction = ElementwiseUnaryFunction<abs<InType>>;
60  using CeilFunction = ElementwiseUnaryFunction<ceil<InType>>;
61  using ExpFunction = ElementwiseUnaryFunction<exp<InType>>;
62  using LogFunction = ElementwiseUnaryFunction<log<InType>>;
64  using RsqrtFunction = ElementwiseUnaryFunction<rsqrt<InType>>;
65  using SinFunction = ElementwiseUnaryFunction<sin<InType>>;
66  using SqrtFunction = ElementwiseUnaryFunction<sqrt<InType>>;
67 
69  {
71  {
72  AbsFunction(inShape, outShape, *input, *output);
73  break;
74  }
76  {
77  CeilFunction(inShape, outShape, *input, *output);
78  break;
79  }
81  {
82  ExpFunction(inShape, outShape, *input, *output);
83  break;
84  }
86  {
87  LogFunction(inShape, outShape, *input, *output);
88  break;
89  }
91  {
92  NegFunction(inShape, outShape, *input, *output);
93  break;
94  }
96  {
97  RsqrtFunction(inShape, outShape, *input, *output);
98  break;
99  }
100  case UnaryOperation::Sin:
101  {
102  SinFunction(inShape, outShape, *input, *output);
103  break;
104  }
106  {
107  SqrtFunction(inShape, outShape, *input, *output);
108  break;
109  }
110  default:
111  {
112  throw InvalidArgumentException(std::string("Unsupported unary operation ") +
114  }
115  }
116 }
117 
118 } // namespace armnn
Sin.hpp
Ceil.hpp
armnn::experimental::ExecutionData::m_Data
void * m_Data
Definition: ExecutionData.hpp:16
TypesUtils.hpp
armnn::TensorInfo
Definition: Tensor.hpp:152
RefElementwiseUnaryWorkload.hpp
CHECK_LOCATION
#define CHECK_LOCATION()
Definition: Exceptions.hpp:203
Profiling.hpp
Rsqrt.hpp
ARMNN_SCOPED_PROFILING_EVENT_REF_NAME_GUID
#define ARMNN_SCOPED_PROFILING_EVENT_REF_NAME_GUID(label)
Creates a profiling event that uses GetGuid() and GetName() from the calling class.
Definition: RefWorkloadUtils.hpp:22
armnn::UnaryOperation::Neg
@ Neg
armnn::TensorShape
Definition: Tensor.hpp:20
Abs.hpp
armnn::QueueDescriptorWithParameters::m_Parameters
LayerDescriptor m_Parameters
Definition: WorkloadData.hpp:66
armnn::UnaryOperation::Rsqrt
@ Rsqrt
armnn::UnaryOperation::Sqrt
@ Sqrt
armnn::RefElementwiseUnaryWorkload::RefElementwiseUnaryWorkload
RefElementwiseUnaryWorkload(const ElementwiseUnaryQueueDescriptor &descriptor, const WorkloadInfo &info)
Definition: RefElementwiseUnaryWorkload.cpp:29
armnn::ElementwiseUnaryQueueDescriptor
Definition: WorkloadData.hpp:676
armnn::UnaryOperation::Exp
@ Exp
armnn::WorkloadInfo
Contains information about TensorInfos of a layer.
Definition: WorkloadInfo.hpp:16
armnn::UnaryOperation::Sin
@ Sin
armnn::GetTensorInfo
const TensorInfo & GetTensorInfo(const ITensorHandle *tensorHandle)
float32 helpers
Definition: RefWorkloadUtils.hpp:33
armnn::ElementwiseUnaryFunction
Definition: ElementwiseFunction.hpp:29
armnn::BoostLogSeverityMapping::info
@ info
armnn::QueueDescriptor::m_Outputs
std::vector< ITensorHandle * > m_Outputs
Definition: WorkloadData.hpp:27
armnn::RefElementwiseUnaryWorkload::Execute
void Execute() const override
Definition: RefElementwiseUnaryWorkload.cpp:34
armnn::UnaryOperation::Ceil
@ Ceil
armnn::ElementwiseUnaryDescriptor::m_Operation
UnaryOperation m_Operation
Specifies the elementwiseUnary operation to execute.
Definition: Descriptors.hpp:145
armnn::UnaryOperation::Log
@ Log
RefWorkloadUtils.hpp
armnn::BaseWorkload< ElementwiseUnaryQueueDescriptor >::m_Data
ElementwiseUnaryQueueDescriptor m_Data
Definition: Workload.hpp:89
armnn::GetUnaryOperationAsCString
constexpr char const * GetUnaryOperationAsCString(UnaryOperation operation)
Definition: TypesUtils.hpp:92
armnn::TensorInfo::GetShape
const TensorShape & GetShape() const
Definition: Tensor.hpp:193
ElementwiseFunction.hpp
Decoders.hpp
armnn::LayerType::Map
@ Map
armnn::experimental::WorkingMemDescriptor::m_Inputs
std::vector< ITensorHandle * > m_Inputs
Definition: WorkingMemDescriptor.hpp:20
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
armnn::experimental::WorkingMemDescriptor
Definition: WorkingMemDescriptor.hpp:18
armnn::RefElementwiseUnaryWorkload::ExecuteAsync
void ExecuteAsync(ExecutionData &executionData) override
Definition: RefElementwiseUnaryWorkload.cpp:39
armnn::UnaryOperation::Abs
@ Abs
Encoders.hpp
Exp.hpp
Sqrt.hpp
armnn::RefBaseWorkload
Definition: RefBaseWorkload.hpp:13
armnn::experimental::WorkingMemDescriptor::m_Outputs
std::vector< ITensorHandle * > m_Outputs
Definition: WorkingMemDescriptor.hpp:21
armnn::QueueDescriptor::m_Inputs
std::vector< ITensorHandle * > m_Inputs
Definition: WorkloadData.hpp:26
Log.hpp
armnn::experimental::ExecutionData
Definition: ExecutionData.hpp:14