ArmNN
 24.08
RefElementwiseBinaryWorkload.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2023-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 "Maximum.hpp"
13 #include "Minimum.hpp"
14 #include "SquaredDifference.hpp"
15 #include "Power.hpp"
16 
17 #include <Profiling.hpp>
18 
19 #include <armnn/TypesUtils.hpp>
20 
21 #include <functional>
22 
23 namespace armnn
24 {
25 
26 template<typename DataType>
27 void ExecuteFunction(std::vector<ITensorHandle*> inputs,
28  std::vector<ITensorHandle*> outputs,
29  BinaryOperation operation,
30  const std::string& layerName = "")
31 {
32  const TensorInfo& inputInfo0 = GetTensorInfo(inputs[0]);
33  const TensorInfo& inputInfo1 = GetTensorInfo(inputs[1]);
34  const TensorInfo& outputInfo = GetTensorInfo(outputs[0]);
35 
36  const TensorShape& inShape0 = inputInfo0.GetShape();
37  const TensorShape& inShape1 = inputInfo1.GetShape();
38  const TensorShape& outShape = outputInfo.GetShape();
39 
40  std::unique_ptr<Decoder<DataType>> input0 = MakeDecoder<DataType>(inputInfo0, inputs[0]->Map());
41  std::unique_ptr<Decoder<DataType>> input1 = MakeDecoder<DataType>(inputInfo1, inputs[1]->Map());
42  std::unique_ptr<Encoder<DataType>> output = MakeEncoder<DataType>(outputInfo, outputs[0]->Map());
43 
53 
54 
55  switch (operation)
56  {
58  {
59  AddFunction(inShape0, inShape1, outShape, *input0, *input1, *output);
60  break;
61  }
63  {
64  if(!layerName.empty() && layerName.find("FloorDiv") != std::string::npos)
65  {
66  FloorDivFunction(inShape0, inShape1, outShape, *input0, *input1, *output);
67  }
68  else
69  {
70  DivFunction(inShape0, inShape1, outShape, *input0, *input1, *output);
71  }
72  break;
73  }
75  {
76  MaximumFunction(inShape0, inShape1, outShape, *input0, *input1, *output);
77  break;
78  }
80  {
81  MinimumFunction(inShape0, inShape1, outShape, *input0, *input1, *output);
82  break;
83  }
85  {
86  MulFunction(inShape0, inShape1, outShape, *input0, *input1, *output);
87  break;
88  }
90  {
91  SubFunction(inShape0, inShape1, outShape, *input0, *input1, *output);
92  break;
93  }
95  {
96  SqDiffFunction(inShape0, inShape1, outShape, *input0, *input1, *output);
97  break;
98  }
100  {
101  PowerFunction(inShape0, inShape1, outShape, *input0, *input1, *output);
102  break;
103  }
104  default:
105  {
106  throw InvalidArgumentException(std::string("Unsupported binary operation ") +
108  }
109  }
110 }
111 
113  const WorkloadInfo& info)
115 {}
116 
118 {
120 }
121 
123 {
124 
125  WorkingMemDescriptor* workingMemDescriptor = static_cast<WorkingMemDescriptor*>(executionData.m_Data);
126  Execute(workingMemDescriptor->m_Inputs, workingMemDescriptor->m_Outputs);
127 }
128 
129 void RefElementwiseBinaryWorkload::Execute(std::vector<ITensorHandle*> inputs,
130  std::vector<ITensorHandle*> outputs) const
131 {
132  ARMNN_SCOPED_PROFILING_EVENT_REF_NAME_GUID("RefElementwiseBinaryWorkload_Execute");
133 
134  if (GetTensorInfo(inputs[0]).GetDataType() == DataType::Signed32)
135  {
136  ExecuteFunction<int32_t>(inputs, outputs, m_Data.m_Parameters.m_Operation, m_Name);
137  }
138  else
139  {
140  ExecuteFunction<float>(inputs, outputs, m_Data.m_Parameters.m_Operation, m_Name);
141  }
142 }
143 
144 } // namespace armnn
armnn::GetBinaryOperationAsCString
constexpr char const * GetBinaryOperationAsCString(BinaryOperation operation)
Definition: TypesUtils.hpp:76
armnn::BinaryOperation::Mul
@ Mul
armnn::BinaryOperation::Add
@ Add
Minimum.hpp
armnn::experimental::ExecutionData::m_Data
void * m_Data
Definition: ExecutionData.hpp:16
TypesUtils.hpp
armnn::TensorInfo
Definition: Tensor.hpp:152
armnn::BinaryOperation::Sub
@ Sub
armnn::RefElementwiseBinaryWorkload::RefElementwiseBinaryWorkload
RefElementwiseBinaryWorkload(const ElementwiseBinaryQueueDescriptor &descriptor, const WorkloadInfo &info)
Definition: RefElementwiseBinaryWorkload.cpp:112
armnn::RefElementwiseBinaryWorkload::Execute
void Execute() const override
Definition: RefElementwiseBinaryWorkload.cpp:117
armnn::BaseWorkload< ElementwiseBinaryQueueDescriptor >::m_Name
const std::string m_Name
Definition: Workload.hpp:91
CHECK_LOCATION
#define CHECK_LOCATION()
Definition: Exceptions.hpp:203
Profiling.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::ElementwiseBinaryFunction
Definition: ElementwiseFunction.hpp:15
armnn::TensorShape
Definition: Tensor.hpp:20
armnn::BinaryOperation::Maximum
@ Maximum
armnn::ElementwiseBinaryQueueDescriptor
Definition: WorkloadData.hpp:671
armnn::BinaryOperation::SqDiff
@ SqDiff
armnn::QueueDescriptorWithParameters::m_Parameters
LayerDescriptor m_Parameters
Definition: WorkloadData.hpp:66
RefElementwiseBinaryWorkload.hpp
armnn::WorkloadInfo
Contains information about TensorInfos of a layer.
Definition: WorkloadInfo.hpp:16
armnn::InvalidArgumentException
Definition: Exceptions.hpp:80
armnn::GetTensorInfo
const TensorInfo & GetTensorInfo(const ITensorHandle *tensorHandle)
float32 helpers
Definition: RefWorkloadUtils.hpp:33
armnn::BoostLogSeverityMapping::info
@ info
armnn::BinaryOperation::Power
@ Power
armnn::QueueDescriptor::m_Outputs
std::vector< ITensorHandle * > m_Outputs
Definition: WorkloadData.hpp:27
armnn::RefElementwiseBinaryWorkload::ExecuteAsync
void ExecuteAsync(ExecutionData &executionData) override
Definition: RefElementwiseBinaryWorkload.cpp:122
armnn::DataType::Signed32
@ Signed32
SquaredDifference.hpp
RefWorkloadUtils.hpp
armnn::BinaryOperation
BinaryOperation
Definition: Types.hpp:138
armnn::BaseWorkload< ElementwiseBinaryQueueDescriptor >::m_Data
ElementwiseBinaryQueueDescriptor m_Data
Definition: Workload.hpp:89
armnn::ExecuteFunction
void ExecuteFunction(std::vector< ITensorHandle * > inputs, std::vector< ITensorHandle * > outputs, BinaryOperation operation, const std::string &layerName="")
Definition: RefElementwiseBinaryWorkload.cpp:27
armnn::TensorInfo::GetShape
const TensorShape & GetShape() const
Definition: Tensor.hpp:193
ElementwiseFunction.hpp
armnn::ElementwiseBinaryDescriptor::m_Operation
BinaryOperation m_Operation
Specifies the elementwiseBinary operation to execute.
Definition: Descriptors.hpp:125
Decoders.hpp
Maximum.hpp
armnn::BinaryOperation::Minimum
@ Minimum
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
Power.hpp
armnn::BinaryOperation::Div
@ Div
Encoders.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
armnn::experimental::ExecutionData
Definition: ExecutionData.hpp:14