ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
onert::backend::cpu::ops::ElementwiseBinaryLayer Class Reference

#include <ElementwiseBinaryLayer.h>

Collaboration diagram for onert::backend::cpu::ops::ElementwiseBinaryLayer:

Public Member Functions

 ElementwiseBinaryLayer ()
 
void configure (const IPortableTensor *lhs, const IPortableTensor *rhs, IPortableTensor *output, const ElementwiseBinaryType op_type)
 
void run () override
 
- Public Member Functions inherited from onert::exec::IFunction
virtual ~IFunction ()=default
 
virtual void prepare ()
 

Detailed Description

Definition at line 37 of file ElementwiseBinaryLayer.h.

Constructor & Destructor Documentation

◆ ElementwiseBinaryLayer()

onert::backend::cpu::ops::ElementwiseBinaryLayer::ElementwiseBinaryLayer ( )
inline

Definition at line 40 of file ElementwiseBinaryLayer.h.

40 : _lhs(nullptr), _rhs(nullptr), _output(nullptr)
41 {
42 // DO NOTHING
43 }

Member Function Documentation

◆ configure()

void onert::backend::cpu::ops::ElementwiseBinaryLayer::configure ( const IPortableTensor lhs,
const IPortableTensor rhs,
IPortableTensor output,
const ElementwiseBinaryType  op_type 
)

Definition at line 119 of file ElementwiseBinaryLayer.cc.

121{
122 assert(lhs != nullptr);
123 assert(rhs != nullptr);
124 assert(output != nullptr);
125
126 _lhs = lhs;
127 _rhs = rhs;
128 _output = output;
129
130 switch (op_type)
131 {
133 if (_lhs->data_type() == OperandType::FLOAT32)
134 {
135 _kernel = FloorDivGeneric<float>;
136 }
137 else if (_lhs->data_type() == OperandType::INT32)
138 {
139 _kernel = FloorDivGeneric<int32_t>;
140 }
141 else
142 {
143 throw std::runtime_error{"Max: unsupported data type"};
144 }
145 break;
147 if (_lhs->data_type() == OperandType::FLOAT32)
148 {
149 _kernel = FloorModGeneric<float>;
150 }
151 else if (_lhs->data_type() == OperandType::INT64)
152 {
153 _kernel = FloorModGeneric<int64_t>;
154 }
155 else
156 {
157 throw std::runtime_error{"FloorMod: unsupported data type"};
158 }
159 break;
161 if ((_lhs->data_type() == OperandType::BOOL8) && (_rhs->data_type() == OperandType::BOOL8))
162 {
163 static_assert(sizeof(bool) == 1, "cpu backend supports bool type which is 1 byte");
164 _kernel = logicalAndGeneric<bool>;
165 }
166 else
167 {
168 throw std::runtime_error{"LogicalOr: Unsupported data type"};
169 }
170 break;
172 if ((_lhs->data_type() == OperandType::BOOL8) && (_rhs->data_type() == OperandType::BOOL8))
173 {
174 static_assert(sizeof(bool) == 1, "cpu backend supports bool type which is 1 byte");
175 _kernel = logicalOrGeneric<bool>;
176 }
177 else
178 {
179 throw std::runtime_error{"LogicalOr: Unsupported data type"};
180 }
181 break;
183 if (_lhs->data_type() == OperandType::QUANT_UINT8_ASYMM)
184 {
185 if (!haveSameQauntInfo(_lhs, _rhs, _output))
186 {
187 throw std::runtime_error("Max NYI for quantized");
188 }
189 _kernel = maximumGeneric<uint8_t>;
190 }
191 else if (_lhs->data_type() == OperandType::FLOAT32)
192 {
193 _kernel = maximumGeneric<float>;
194 }
195 else
196 {
197 throw std::runtime_error{"Max: unsupported data type"};
198 }
199 break;
201 if (_lhs->data_type() == OperandType::QUANT_UINT8_ASYMM)
202 {
203 if (!haveSameQauntInfo(_lhs, _rhs, _output))
204 {
205 throw std::runtime_error("Min NYI for quantized");
206 }
207 _kernel = minimumGeneric<uint8_t>;
208 }
209 else if (_lhs->data_type() == OperandType::INT32)
210 {
211 _kernel = minimumGeneric<int32_t>;
212 }
213 else if (_lhs->data_type() == OperandType::FLOAT32)
214 {
215 _kernel = minimumGeneric<float>;
216 }
217 else
218 {
219 throw std::runtime_error{"Min: unsupported data type"};
220 }
221 break;
222 default:
223 throw std::runtime_error{"ElementwiseBinary: Unsupported ElementwiseBinary type"};
224 }
225}
ir::DataType data_type() const override final

References onert::backend::IPortableTensor::data_type(), onert::backend::cpu::ops::kFloorDiv, onert::backend::cpu::ops::kFloorMod, onert::backend::cpu::ops::kLogicalAnd, onert::backend::cpu::ops::kLogicalOr, onert::backend::cpu::ops::kMax, and onert::backend::cpu::ops::kMin.

◆ run()

void onert::backend::cpu::ops::ElementwiseBinaryLayer::run ( )
overridevirtual

Implements onert::exec::IFunction.

Definition at line 227 of file ElementwiseBinaryLayer.cc.

227{ _kernel(_lhs, _rhs, _output); }

The documentation for this class was generated from the following files: