ONE - On-device Neural Engine
Loading...
Searching...
No Matches
onert::backend::cpu::ops::ElementwiseUnaryLayer Class Reference

#include <ElementwiseUnaryLayer.h>

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

Public Member Functions

 ElementwiseUnaryLayer ()
 
void configure (const IPortableTensor *input, IPortableTensor *output, const ElementwiseUnaryType op_type)
 
void run () override
 
- Public Member Functions inherited from onert::exec::IFunction
virtual ~IFunction ()=default
 
virtual void prepare ()
 

Detailed Description

Definition at line 54 of file ElementwiseUnaryLayer.h.

Constructor & Destructor Documentation

◆ ElementwiseUnaryLayer()

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

Definition at line 57 of file ElementwiseUnaryLayer.h.

57 : _input(nullptr), _output(nullptr), _kernel()
58 {
59 // DO NOTHING
60 }

Member Function Documentation

◆ configure()

void onert::backend::cpu::ops::ElementwiseUnaryLayer::configure ( const IPortableTensor input,
IPortableTensor output,
const ElementwiseUnaryType  op_type 
)

Definition at line 210 of file ElementwiseUnaryLayer.cc.

212{
213 assert(input != nullptr);
214 assert(output != nullptr);
215
216 _input = input;
217 _output = output;
218
219 switch (op_type)
220 {
222 if ((input->data_type() == OperandType::FLOAT32))
223 {
224 _kernel = absFloat32;
225 }
226 else
227 {
228 throw std::runtime_error{"Abs: Unsupported data type"};
229 }
230 break;
232 _kernel = cast;
233 break;
235 if ((input->data_type() == OperandType::FLOAT32))
236 {
237 _kernel = cosFloat32;
238 }
239 else
240 {
241 throw std::runtime_error{"Cos: Unsupported data type"};
242 }
243 break;
245 if ((input->data_type() == OperandType::QUANT_UINT8_ASYMM))
246 {
247 _kernel = dequantizeUint8;
248 }
249 else if ((input->data_type() == OperandType::QUANT_INT8_ASYMM) ||
250 (input->data_type() == OperandType::QUANT_INT8_SYMM))
251 {
252 _kernel = dequantizeInt8;
253 }
254 else
255 {
256 throw std::runtime_error{"Dequantize: Unsupported data type"};
257 }
258 break;
260 if ((input->data_type() == OperandType::FLOAT32))
261 {
262 _kernel = expFloat32;
263 }
264 else
265 {
266 throw std::runtime_error{"Exp: Unsupported data type"};
267 }
268 break;
270 if ((input->data_type() == OperandType::FLOAT32))
271 {
272 _kernel = erfFloat32;
273 }
274 else
275 {
276 throw std::runtime_error{"Exp: Unsupported data type"};
277 }
278 break;
280 if ((input->data_type() == OperandType::FLOAT32))
281 {
282 _kernel = floorFloat32;
283 }
284 else
285 {
286 throw std::runtime_error{"Floor: Unsupported data type"};
287 }
288 break;
290 if ((input->data_type() == OperandType::FLOAT32))
291 {
292 _kernel = logFloat32;
293 }
294 else
295 {
296 throw std::runtime_error{"Log: Unsupported data type"};
297 }
298 break;
300 if ((input->data_type() == OperandType::BOOL8))
301 {
302 static_assert(sizeof(bool) == 1, "cpu backend supports bool type which is 1 byte");
303 _kernel = logicalNot;
304 }
305 else
306 {
307 throw std::runtime_error{"LogicalNot: Unsupported data type"};
308 }
309 break;
311 if ((input->data_type() == OperandType::FLOAT32))
312 {
313 _kernel = neg<float>;
314 }
315 else if ((input->data_type() == OperandType::INT64))
316 {
317 _kernel = neg<int64_t>;
318 }
319 else if ((input->data_type() == OperandType::INT32))
320 {
321 _kernel = neg<int32_t>;
322 }
323 else
324 {
325 throw std::runtime_error{"Neg: Unsupported data type"};
326 }
327 break;
329 if ((input->data_type() == OperandType::FLOAT32))
330 {
331 _kernel = roundFloat32;
332 }
333 else
334 {
335 throw std::runtime_error{"Round: Unsupported data type"};
336 }
337 break;
339 if ((input->data_type() == OperandType::FLOAT32))
340 {
341 _kernel = rsqrtFloat32;
342 }
343 else
344 {
345 throw std::runtime_error{"RSqrt: Unsupported data type"};
346 }
347 break;
349 if ((input->data_type() == OperandType::FLOAT32))
350 {
351 _kernel = sinFloat32;
352 }
353 else
354 {
355 throw std::runtime_error{"Sin: Unsupported data type"};
356 }
357 break;
359 if ((input->data_type() == OperandType::FLOAT32))
360 {
361 _kernel = sqrtFloat32;
362 }
363 else
364 {
365 throw std::runtime_error{"Sqrt: Unsupported data type"};
366 }
367 break;
369 if ((input->data_type() == OperandType::FLOAT32))
370 {
371 _kernel = squareFloat32;
372 }
373 else
374 {
375 throw std::runtime_error{"Square: Unsupported data type"};
376 }
377 break;
379 if (input->data_type() == OperandType::FLOAT32)
380 {
381 _kernel = zerosLikeFloat32<float>;
382 }
383 else if (input->data_type() == OperandType::INT32)
384 {
385 _kernel = zerosLikeFloat32<int32_t>;
386 }
387 else
388 {
389 throw std::runtime_error{"ZerosLike: Unsupported data type"};
390 }
391 break;
392 default:
393 throw std::runtime_error{"ElementwiseUnary: Unsupported ElementwiseUnary type"};
394 }
395}
T * cast(Object *)
Cast a generic object as a specific one.

References onert::backend::cpu::ops::kAbs, onert::backend::cpu::ops::kCast, onert::backend::cpu::ops::kCos, onert::backend::cpu::ops::kDequantize, onert::backend::cpu::ops::kErf, onert::backend::cpu::ops::kExp, onert::backend::cpu::ops::kFloor, onert::backend::cpu::ops::kLog, onert::backend::cpu::ops::kLogicalNot, onert::backend::cpu::ops::kNeg, onert::backend::cpu::ops::kRound, onert::backend::cpu::ops::kRSqrt, onert::backend::cpu::ops::kSin, onert::backend::cpu::ops::kSqrt, onert::backend::cpu::ops::kSquare, and onert::backend::cpu::ops::kZerosLike.

◆ run()

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

Implements onert::exec::IFunction.

Definition at line 397 of file ElementwiseUnaryLayer.cc.

397{ _kernel(_input, _output); }

Referenced by package.infer.session::inference().


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