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

#include <IfLayer.h>

Collaboration diagram for onert::backend::builtin::kernel::IfLayer:

Public Member Functions

 IfLayer (backend::IPortableTensor *cond_tensor, const std::vector< backend::IPortableTensor * > input_tensors, const std::vector< backend::IPortableTensor * > output_tensors, const ir::SubgraphIndex &then_subg_index, const ir::SubgraphIndex &else_subg_index, exec::IExecutors *executors, const ir::ModelIndex &model_index, const std::shared_ptr< ExternalContext > &external_context)
 
void run () override
 
- Public Member Functions inherited from onert::exec::IFunction
virtual ~IFunction ()=default
 
virtual void prepare ()
 

Detailed Description

Definition at line 28 of file IfLayer.h.

Constructor & Destructor Documentation

◆ IfLayer()

onert::backend::builtin::kernel::IfLayer::IfLayer ( backend::IPortableTensor cond_tensor,
const std::vector< backend::IPortableTensor * >  input_tensors,
const std::vector< backend::IPortableTensor * >  output_tensors,
const ir::SubgraphIndex then_subg_index,
const ir::SubgraphIndex else_subg_index,
exec::IExecutors executors,
const ir::ModelIndex model_index,
const std::shared_ptr< ExternalContext > &  external_context 
)

Definition at line 22 of file IfLayer.cc.

28 : _cond_tensor{cond_tensor}, _input_tensors{input_tensors}, _output_tensors{output_tensors},
29 _then_subg_index{then_subg_index}, _else_subg_index{else_subg_index}, _executors{executors},
30 _model_index{model_index}, _external_context{external_context}
31{
32 // At this point, executors may not have executors of then subg and else subg
33}

Member Function Documentation

◆ run()

void onert::backend::builtin::kernel::IfLayer::run ( )
overridevirtual

Implements onert::exec::IFunction.

Definition at line 35 of file IfLayer.cc.

36{
37 // Check condition
38 // // If true
39 // // // Set _input_tensors -> then-subg's inputs
40 // // // Set outputs of then-subg -> _output_tensors
41 // // // Run then-subg
42 // // Else
43 // // // Set _input_tensors -> else-subg's inputs
44 // // // Set outputs of else-subg -> _output_tensors
45 // // // Run else-subg
46
47 auto getResultCond = [](backend::IPortableTensor *tensor) -> bool {
48 bool ret = false;
49 tensor->access([&](ITensor &tensor) { ret = *reinterpret_cast<bool *>(tensor.buffer()); });
50 return ret;
51 };
52
53 exec::IExecutor *subg_exec = nullptr;
54 bool cond_result = getResultCond(_cond_tensor);
55 if (cond_result)
56 {
57 VERBOSE(If) << "Call to $" << _then_subg_index << " (then)" << std::endl;
58 subg_exec = _executors->at(_model_index, _then_subg_index);
59 }
60 else
61 {
62 VERBOSE(If) << "Call to $" << _else_subg_index << " (else)" << std::endl;
63 subg_exec = _executors->at(_model_index, _else_subg_index);
64 }
65
66 subg_exec->execute(_input_tensors, _output_tensors,
67 _executors->entryExecutor()->currentOptions());
68 VERBOSE(If) << "Return from $" << (cond_result ? _then_subg_index : _else_subg_index)
69 << std::endl;
70}
IExecutor * entryExecutor() const
Definition IExecutors.h:58
virtual IExecutor * at(const ir::ModelIndex &model_index, const ir::SubgraphIndex &subg_index) const =0
Return executor of index.
#define VERBOSE(name, lv)
Definition Log.h:71
virtual void execute(const std::vector< backend::IPortableTensor * > &inputs, const std::vector< backend::IPortableTensor * > &outputs, const ExecutionOptions &options)=0
Execute with given input/output tensors.
virtual const ExecutionOptions & currentOptions() const =0
Return current execution configuration.

References onert::exec::IExecutors::at(), onert::exec::IExecutor::currentOptions(), onert::exec::IExecutors::entryExecutor(), onert::exec::IExecutor::execute(), and VERBOSE.


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