ArmNN
 21.05
RefElementwiseUnaryWorkload.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2019 Arm Ltd. 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 "Exp.hpp"
14 #include "Rsqrt.hpp"
15 #include "Sqrt.hpp"
16 
17 #include <Profiling.hpp>
18 
19 #include <armnn/TypesUtils.hpp>
20 
21 #include <functional>
22 
23 namespace armnn
24 {
25 
27  const WorkloadInfo& info)
29 {}
30 
32 {
34 }
35 
37 {
38 
39  Execute(workingMemDescriptor.m_Inputs, workingMemDescriptor.m_Outputs);
40 }
41 
42 void RefElementwiseUnaryWorkload::Execute(std::vector<ITensorHandle*> inputs, std::vector<ITensorHandle*> outputs) const
43 {
44  ARMNN_SCOPED_PROFILING_EVENT(Compute::CpuRef, "RefElementwiseUnaryWorkload_Execute");
45 
46  const TensorInfo& inputInfo = GetTensorInfo(inputs[0]);
47  const TensorInfo& outputInfo = GetTensorInfo(outputs[0]);
48 
49  const TensorShape& inShape = inputInfo.GetShape();
50  const TensorShape& outShape = outputInfo.GetShape();
51 
52  std::unique_ptr<Decoder<InType>> input = MakeDecoder<InType>(inputInfo, inputs[0]->Map());
53  std::unique_ptr<Encoder<OutType>> output= MakeEncoder<OutType>(outputInfo, outputs[0]->Map());
54 
55  using AbsFunction = ElementwiseUnaryFunction<abs<InType>>;
56  using ExpFunction = ElementwiseUnaryFunction<exp<InType>>;
58  using RsqrtFunction = ElementwiseUnaryFunction<rsqrt<InType>>;
59  using SqrtFunction = ElementwiseUnaryFunction<sqrt<InType>>;
60 
62  {
64  {
65  AbsFunction(inShape, outShape, *input, *output);
66  break;
67  }
69  {
70  ExpFunction(inShape, outShape, *input, *output);
71  break;
72  }
74  {
75  NegFunction(inShape, outShape, *input, *output);
76  break;
77  }
79  {
80  RsqrtFunction(inShape, outShape, *input, *output);
81  break;
82  }
84  {
85  SqrtFunction(inShape, outShape, *input, *output);
86  break;
87  }
88  default:
89  {
90  throw InvalidArgumentException(std::string("Unsupported unary operation ") +
92  }
93  }
94 }
95 
96 } // namespace armnn
UnaryOperation m_Operation
Specifies the elementwiseUnary operation to execute.
const TensorShape & GetShape() const
Definition: Tensor.hpp:187
CPU Execution: Reference C++ kernels.
Copyright (c) 2021 ARM Limited and Contributors.
#define ARMNN_SCOPED_PROFILING_EVENT(backendId, name)
Definition: Profiling.hpp:173
constexpr char const * GetUnaryOperationAsCString(UnaryOperation operation)
Definition: TypesUtils.hpp:71
#define CHECK_LOCATION()
Definition: Exceptions.hpp:197
void ExecuteAsync(WorkingMemDescriptor &workingMemDescriptor) override
RefElementwiseUnaryWorkload(const ElementwiseUnaryQueueDescriptor &descriptor, const WorkloadInfo &info)
std::vector< ITensorHandle * > m_Outputs
Contains information about inputs and outputs to a layer.
std::vector< ITensorHandle * > m_Inputs
const TensorInfo & GetTensorInfo(const ITensorHandle *tensorHandle)
float32 helpers