ArmNN
 25.11
Loading...
Searching...
No Matches
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
26namespace armnn
27{
28
33
35{
36 Execute(m_Data.m_Inputs, m_Data.m_Outputs);
37}
38
39void 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
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()
#define ARMNN_SCOPED_PROFILING_EVENT_REF_NAME_GUID(label)
Creates a profiling event that uses GetGuid() and GetName() from the calling class.
RefBaseWorkload(const ElementwiseUnaryQueueDescriptor &descriptor, const WorkloadInfo &info)
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)
std::unique_ptr< Decoder< T > > MakeDecoder(const TensorInfo &info, const void *data=nullptr)
std::unique_ptr< Encoder< T > > MakeEncoder(const TensorInfo &info, void *data=nullptr)
armnn::TensorInfo GetTensorInfo(unsigned int numberOfBatches, unsigned int numberOfChannels, unsigned int height, unsigned int width, const armnn::DataLayout dataLayout, const armnn::DataType dataType)
UnaryOperation m_Operation
Specifies the elementwiseUnary operation to execute.
Contains information about TensorInfos of a layer.