ONE - On-device Neural Engine
Loading...
Searching...
No Matches
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 168 of file ElementwiseBinaryLayer.cc.

170{
171 assert(lhs != nullptr);
172 assert(rhs != nullptr);
173 assert(output != nullptr);
174
175 _lhs = lhs;
176 _rhs = rhs;
177 _output = output;
178
179 switch (op_type)
180 {
182 if (_lhs->data_type() == OperandType::FLOAT32)
183 {
184 _kernel = FloorDivGeneric<float>;
185 }
186 else if (_lhs->data_type() == OperandType::INT32)
187 {
188 _kernel = FloorDivGeneric<int32_t>;
189 }
190 else
191 {
192 throw std::runtime_error{"Max: unsupported data type"};
193 }
194 break;
196 if (_lhs->data_type() == OperandType::FLOAT32)
197 {
198 _kernel = FloorModGeneric<float>;
199 }
200 else if (_lhs->data_type() == OperandType::INT64)
201 {
202 _kernel = FloorModGeneric<int64_t>;
203 }
204 else
205 {
206 throw std::runtime_error{"FloorMod: unsupported data type"};
207 }
208 break;
210 if ((_lhs->data_type() == OperandType::BOOL8) && (_rhs->data_type() == OperandType::BOOL8))
211 {
212 static_assert(sizeof(bool) == 1, "cpu backend supports bool type which is 1 byte");
213 _kernel = logicalAndGeneric<bool>;
214 }
215 else
216 {
217 throw std::runtime_error{"LogicalOr: Unsupported data type"};
218 }
219 break;
221 if ((_lhs->data_type() == OperandType::BOOL8) && (_rhs->data_type() == OperandType::BOOL8))
222 {
223 static_assert(sizeof(bool) == 1, "cpu backend supports bool type which is 1 byte");
224 _kernel = logicalOrGeneric<bool>;
225 }
226 else
227 {
228 throw std::runtime_error{"LogicalOr: Unsupported data type"};
229 }
230 break;
232 if (_lhs->data_type() == OperandType::QUANT_UINT8_ASYMM)
233 {
234 if (!haveSameQauntInfo(_lhs, _rhs, _output))
235 {
236 throw std::runtime_error("Max NYI for quantized");
237 }
238 _kernel = maximumGeneric<uint8_t>;
239 }
240 else if (_lhs->data_type() == OperandType::FLOAT32)
241 {
242 _kernel = maximumGeneric<float>;
243 }
244 else
245 {
246 throw std::runtime_error{"Max: unsupported data type"};
247 }
248 break;
250 if (_lhs->data_type() == OperandType::QUANT_UINT8_ASYMM)
251 {
252 if (!haveSameQauntInfo(_lhs, _rhs, _output))
253 {
254 throw std::runtime_error("Min NYI for quantized");
255 }
256 _kernel = minimumGeneric<uint8_t>;
257 }
258 else if (_lhs->data_type() == OperandType::INT32)
259 {
260 _kernel = minimumGeneric<int32_t>;
261 }
262 else if (_lhs->data_type() == OperandType::FLOAT32)
263 {
264 _kernel = minimumGeneric<float>;
265 }
266 else
267 {
268 throw std::runtime_error{"Min: unsupported data type"};
269 }
270 break;
271 default:
272 throw std::runtime_error{"ElementwiseBinary: Unsupported ElementwiseBinary type"};
273 }
274}
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 276 of file ElementwiseBinaryLayer.cc.

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

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