ONE - On-device Neural Engine
Loading...
Searching...
No Matches
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 33 of file SelectLayer.h.

Constructor & Destructor Documentation

◆ SelectLayer()

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

Definition at line 32 of file SelectLayer.cc.

33 : _cond(nullptr), _input_true(nullptr), _input_false(nullptr), _output(nullptr)
34{
35 // DO NOTHING
36}

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 38 of file SelectLayer.cc.

40{
41 _cond = cond;
42 _input_true = input_true;
43 _input_false = input_false;
44 _output = output;
45}

◆ run()

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

Implements onert::exec::IFunction.

Definition at line 47 of file SelectLayer.cc.

48{
49
50#define KERNEL_SELECT(type, op) \
51 nnfw::cker::op(getShape(_cond), getBuffer<uint8_t>(_cond), getShape(_input_true), \
52 getBuffer<type>(_input_true), getShape(_input_false), \
53 getBuffer<type>(_input_false), getShape(_output), getBuffer<type>(_output));
54
55#define KERNEL_SWITCH(type, op) \
56 switch (type) \
57 { \
58 break; \
59 case OperandType::FLOAT32: \
60 KERNEL_SELECT(float, op); \
61 break; \
62 default: \
63 throw std::runtime_error{"Select: unsupported data type"}; \
64 }
65
66 auto input_type = _input_true->data_type();
67 bool require_broadcast =
68 !HaveSameShapes(_input_true, _cond) || !HaveSameShapes(_input_false, _cond);
69 bool rank_one_select = ((_input_true->getShape().rank() == 1) && !require_broadcast);
70
71 if (rank_one_select)
72 {
73 KERNEL_SWITCH(input_type, RankOneSelect);
74 }
75 else if (require_broadcast)
76 {
77 KERNEL_SWITCH(input_type, BroadcastSelect4DSlow);
78 }
79 else
80 {
81 KERNEL_SWITCH(input_type, Select);
82 }
83}
#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.

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


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