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

#include <SelectLayer.h>

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

Public Member Functions

 SelectLayer ()
 
void configure (const IPortableTensor *cond, const IPortableTensor *input_true, const IPortableTensor *input_false, IPortableTensor *output)
 
void run () override
 
- Public Member Functions inherited from onert::exec::IFunction
virtual ~IFunction ()=default
 
virtual void prepare ()
 

Detailed Description

Definition at line 27 of file SelectLayer.h.

Constructor & Destructor Documentation

◆ SelectLayer()

onert::backend::cpu::ops::SelectLayer::SelectLayer ( )

Definition at line 26 of file SelectLayer.cc.

27 : _cond(nullptr), _input_true(nullptr), _input_false(nullptr), _output(nullptr)
28{
29 // DO NOTHING
30}

Member Function Documentation

◆ configure()

void onert::backend::cpu::ops::SelectLayer::configure ( const IPortableTensor cond,
const IPortableTensor input_true,
const IPortableTensor input_false,
IPortableTensor output 
)

Definition at line 32 of file SelectLayer.cc.

34{
35 _cond = cond;
36 _input_true = input_true;
37 _input_false = input_false;
38 _output = output;
39}

◆ run()

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

Implements onert::exec::IFunction.

Definition at line 41 of file SelectLayer.cc.

42{
43
44#define KERNEL_SELECT(type, op) \
45 nnfw::cker::op(getShape(_cond), getBuffer<uint8_t>(_cond), getShape(_input_true), \
46 getBuffer<type>(_input_true), getShape(_input_false), \
47 getBuffer<type>(_input_false), getShape(_output), getBuffer<type>(_output));
48
49#define KERNEL_SWITCH(type, op) \
50 switch (type) \
51 { \
52 break; \
53 case OperandType::FLOAT32: \
54 KERNEL_SELECT(float, op); \
55 break; \
56 default: \
57 throw std::runtime_error{"Select: unsupported data type"}; \
58 }
59
60 auto input_type = _input_true->data_type();
61 bool require_broadcast =
62 !HaveSameShapes(_input_true, _cond) || !HaveSameShapes(_input_false, _cond);
63 bool rank_one_select = ((_input_true->getShape().rank() == 1) && !require_broadcast);
64
65 if (rank_one_select)
66 {
67 KERNEL_SWITCH(input_type, RankOneSelect);
68 }
69 else if (require_broadcast)
70 {
71 KERNEL_SWITCH(input_type, BroadcastSelect4DSlow);
72 }
73 else
74 {
75 KERNEL_SWITCH(input_type, Select);
76 }
77}
#define KERNEL_SWITCH(type, op)
ir::DataType data_type() const override final
ir::Shape getShape() const override final
Get ir::Shape of tensor.
bool HaveSameShapes(const IPortableTensor *input1, const IPortableTensor *input2)

References onert::backend::IPortableTensor::data_type(), onert::backend::IPortableTensor::getShape(), onert::backend::cpu::ops::HaveSameShapes(), and KERNEL_SWITCH.


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