ONE - On-device Neural Engine
Loading...
Searching...
No Matches
onert::exec::ExecutorBase Class Referenceabstract

#include <ExecutorBase.h>

Collaboration diagram for onert::exec::ExecutorBase:

Public Member Functions

 ExecutorBase (std::unique_ptr< compiler::LoweredGraph > &&lowered_graph, backend::BackendContexts &&backend_contexts, const compiler::TensorRegistries &tensor_regs, const util::TracingCtx *tracing_ctx)
 Construct a new ExecutorBase object.
 
virtual ~ExecutorBase ()=default
 
const ir::Graphgraph () const final
 Returns graph object.
 
void execute (const std::vector< backend::IPortableTensor * > &inputs, const std::vector< backend::IPortableTensor * > &outputs, const ExecutionOptions &options) override
 Execute with given input/output tensors.
 
uint32_t inputSize () const override
 Get input size.
 
uint32_t outputSize () const override
 Get output size.
 
const ir::OperandInfoinputInfo (uint32_t index) const override
 Get input info at index.
 
const ir::OperandInfooutputInfo (uint32_t index) const override
 Get output info at index.
 
ir::Layout inputLayout (uint32_t index) const override
 Get input layout at index.
 
ir::Layout outputLayout (uint32_t index) const override
 Get output layout at index.
 
void setIndexedRanks (std::shared_ptr< ir::OperationIndexMap< int64_t > > ranks) final
 Set an ordering on operations.
 
virtual void executeImpl (const ExecutionObservee &subject)=0
 
void addObserver (std::unique_ptr< IExecutionObserver > ref)
 
backend::BackendContextsgetBackendContexts ()
 
const ExecutionOptionscurrentOptions () const override
 Return current execution configuration.
 
- Public Member Functions inherited from onert::exec::IExecutor
 IExecutor ()=default
 Construct a new IExecutor object.
 
virtual ~IExecutor ()=default
 Destroy the IExecutor object.
 

Protected Member Functions

bool hasDynamicInput ()
 Returns true if any input tensor is dynamic; false if all are static tensors.
 

Protected Attributes

ExecObservers _observers
 
std::shared_ptr< ir::OperationIndexMap< int64_t > > _indexed_ranks
 
std::unique_ptr< compiler::LoweredGraph_lowered_graph
 
backend::BackendContexts _backend_contexts
 
const ir::Graph_graph
 
std::vector< backend::builtin::IOTensor * > _input_tensors
 
std::vector< backend::builtin::IOTensor * > _output_tensors
 
std::mutex _mutex
 
const util::TracingCtx_tracing_ctx
 
ExecutionOptions _current_options
 

Detailed Description

Definition at line 40 of file ExecutorBase.h.

Constructor & Destructor Documentation

◆ ExecutorBase()

onert::exec::ExecutorBase::ExecutorBase ( std::unique_ptr< compiler::LoweredGraph > &&  lowered_graph,
backend::BackendContexts &&  backend_contexts,
const compiler::TensorRegistries tensor_regs,
const util::TracingCtx tracing_ctx 
)

Construct a new ExecutorBase object.

Parameters
graphGraph object
tensor_buildersTensor builders that are currently used

Definition at line 27 of file ExecutorBase.cc.

31 : _lowered_graph{std::move(lowered_graph)}, _backend_contexts{std::move(backend_contexts)},
32 _graph{_lowered_graph->graph()}, _mutex(), _tracing_ctx(tracing_ctx)
33{
34 auto build_tensor_list = [&](const auto &ind_seq, auto &tensors) {
35 assert(tensors.empty());
36 for (auto &&ind : ind_seq)
37 {
38 backend::ITensor *tensor = tensor_regs.getITensor(ind);
39 assert(tensor != nullptr);
40 auto io_tensor = nnfw::misc::polymorphic_downcast<backend::builtin::IOTensor *>(tensor);
41 tensors.push_back(io_tensor);
42 }
43 };
44 build_tensor_list(_graph.getInputs(), _input_tensors);
45 build_tensor_list(_graph.getOutputs(), _output_tensors);
46}
std::unique_ptr< compiler::LoweredGraph > _lowered_graph
std::vector< backend::builtin::IOTensor * > _output_tensors
const util::TracingCtx * _tracing_ctx
backend::BackendContexts _backend_contexts
const ir::Graph & _graph
std::vector< backend::builtin::IOTensor * > _input_tensors
const OperandIndexSequence & getInputs() const override
Definition Graph.h:106
const OperandIndexSequence & getOutputs() const override
Definition Graph.h:108

References _graph, _input_tensors, _output_tensors, onert::ir::Graph::getInputs(), onert::compiler::TensorRegistries::getITensor(), and onert::ir::Graph::getOutputs().

◆ ~ExecutorBase()

virtual onert::exec::ExecutorBase::~ExecutorBase ( )
virtualdefault

Member Function Documentation

◆ addObserver()

void onert::exec::ExecutorBase::addObserver ( std::unique_ptr< IExecutionObserver ref)
inline

Definition at line 89 of file ExecutorBase.h.

89{ _observers.add(std::move(ref)); };
void add(std::unique_ptr< IExecutionObserver > &&observer)

References _observers, and onert::exec::ExecObservers::add().

◆ currentOptions()

const ExecutionOptions & onert::exec::ExecutorBase::currentOptions ( ) const
inlineoverridevirtual

Return current execution configuration.

Returns
Current execution configuration

Implements onert::exec::IExecutor.

Definition at line 93 of file ExecutorBase.h.

93{ return _current_options; }
ExecutionOptions _current_options

References _current_options.

◆ execute()

void onert::exec::ExecutorBase::execute ( const std::vector< backend::IPortableTensor * > &  inputs,
const std::vector< backend::IPortableTensor * > &  outputs,
const ExecutionOptions options 
)
overridevirtual

Execute with given input/output tensors.

Input and output tensors must be given.

Parameters
[in]inputsTensors that are passed as inputs
[in]outputsTensors that are passed as outputs
[in]optionsExecution options

Implements onert::exec::IExecutor.

Definition at line 48 of file ExecutorBase.cc.

51{
52 // For thread-safe, use mutex
53 // TODO: if all used backends on this executor are thread-safe,
54 // do not need to use mutex (otherwise, use mutex)
55 // Deadlock occurs when an Executor is called recursively.
56 std::lock_guard<std::mutex> lock(_mutex);
58
59 assert(inputs.size() == _graph.getInputs().size());
60 assert(inputs.size() == _input_tensors.size());
61 for (uint32_t n = 0; n < inputs.size(); ++n)
62 {
63 const auto input = inputs[n];
64 assert(input->buffer() != nullptr || input->get_info().total_size() == 0);
65 auto input_tensor = _input_tensors[n];
66 assert(input_tensor != nullptr);
67 input_tensor->setTensor(input);
68 }
69
70 assert(outputs.size() == _graph.getOutputs().size());
71 assert(outputs.size() == _output_tensors.size());
72 for (uint32_t n = 0; n < outputs.size(); ++n)
73 {
74 const auto output = outputs[n];
75 assert(output->buffer() != nullptr || output->get_info().total_size() == 0);
77 assert(output_tensor != nullptr);
78 output_tensor->setTensor(output);
79 }
80
81 // Create observee
82 ExecutionObservee subject(_observers, options);
83
84 executeImpl(subject);
85}
virtual void executeImpl(const ExecutionObservee &subject)=0

References _current_options, _graph, _input_tensors, _mutex, _observers, _output_tensors, executeImpl(), onert::ir::Graph::getInputs(), onert::ir::Graph::getOutputs(), and onert::ir::OperandIndexSequence::size().

◆ executeImpl()

virtual void onert::exec::ExecutorBase::executeImpl ( const ExecutionObservee subject)
pure virtual

◆ getBackendContexts()

backend::BackendContexts & onert::exec::ExecutorBase::getBackendContexts ( )
inline

Definition at line 91 of file ExecutorBase.h.

91{ return _backend_contexts; }

References _backend_contexts.

◆ graph()

const ir::Graph & onert::exec::ExecutorBase::graph ( ) const
inlinefinalvirtual

Returns graph object.

Returns
Graph object

Implements onert::exec::IExecutor.

Definition at line 54 of file ExecutorBase.h.

54{ return _graph; }

References _graph.

Referenced by TopologicalSortHelper.TopologicalSortHelper::add_edge(), and TopologicalSortHelper.TopologicalSortHelper::sort_util().

◆ hasDynamicInput()

bool onert::exec::ExecutorBase::hasDynamicInput ( )
protected

Returns true if any input tensor is dynamic; false if all are static tensors.

Definition at line 87 of file ExecutorBase.cc.

88{
89 for (auto &&tensor : _input_tensors)
90 {
91 if (tensor->is_dynamic())
92 return true;
93 }
94 return false;
95}

References _input_tensors.

Referenced by onert::exec::DataflowExecutor::executeImpl(), onert::exec::LinearExecutor::executeImpl(), and onert::exec::ParallelExecutor::executeImpl().

◆ inputInfo()

const ir::OperandInfo & onert::exec::ExecutorBase::inputInfo ( uint32_t  index) const
inlineoverridevirtual

Get input info at index.

Parameters
[in]indexIndex of input
Returns
Input operand info

Implements onert::exec::IExecutor.

Definition at line 64 of file ExecutorBase.h.

65 {
66 return _input_tensors[index]->get_info();
67 }
loco::GraphInputIndex index(const TFPlaceholder *node)
Definition TFNode.cpp:54

References _input_tensors.

◆ inputLayout()

ir::Layout onert::exec::ExecutorBase::inputLayout ( uint32_t  index) const
inlineoverridevirtual

Get input layout at index.

Parameters
[in]indexIndex of input
Returns
Input operand layout

Implements onert::exec::IExecutor.

Definition at line 74 of file ExecutorBase.h.

74{ return _input_tensors[index]->layout(); }

References _input_tensors.

◆ inputSize()

uint32_t onert::exec::ExecutorBase::inputSize ( ) const
inlineoverridevirtual

Get input size.

Returns
Input size

Implements onert::exec::IExecutor.

Definition at line 60 of file ExecutorBase.h.

60{ return _input_tensors.size(); }

References _input_tensors.

◆ outputInfo()

const ir::OperandInfo & onert::exec::ExecutorBase::outputInfo ( uint32_t  index) const
inlineoverridevirtual

Get output info at index.

Parameters
[in]indexIndex of output
Returns
Output operand info

Implements onert::exec::IExecutor.

Definition at line 69 of file ExecutorBase.h.

70 {
71 return _output_tensors[index]->get_info();
72 }

References _output_tensors.

◆ outputLayout()

ir::Layout onert::exec::ExecutorBase::outputLayout ( uint32_t  index) const
inlineoverridevirtual

Get output layout at index.

Parameters
[in]indexIndex of output
Returns
Output operand layout

Implements onert::exec::IExecutor.

Definition at line 76 of file ExecutorBase.h.

77 {
78 return _output_tensors[index]->layout();
79 }

References _output_tensors.

◆ outputSize()

uint32_t onert::exec::ExecutorBase::outputSize ( ) const
inlineoverridevirtual

Get output size.

Returns
Output size

Implements onert::exec::IExecutor.

Definition at line 62 of file ExecutorBase.h.

62{ return _output_tensors.size(); }

References _output_tensors.

◆ setIndexedRanks()

void onert::exec::ExecutorBase::setIndexedRanks ( std::shared_ptr< ir::OperationIndexMap< int64_t > >  )
inlinefinalvirtual

Set an ordering on operations.

Parameters
[in]ranksThe table encoding the ordering

Implements onert::exec::IExecutor.

Definition at line 82 of file ExecutorBase.h.

83 {
84 _indexed_ranks = std::move(ranks);
85 };
std::shared_ptr< ir::OperationIndexMap< int64_t > > _indexed_ranks

References _indexed_ranks.

Field Documentation

◆ _backend_contexts

backend::BackendContexts onert::exec::ExecutorBase::_backend_contexts
protected

Definition at line 105 of file ExecutorBase.h.

Referenced by getBackendContexts().

◆ _current_options

ExecutionOptions onert::exec::ExecutorBase::_current_options
protected

It is set by execute() method only in thread-safe environment. It is used for non-primary executor call on builtin backend and accessed by entryExecutor's currentOptions() method.

TODO: Find better way to pass config to non-primary executor

Definition at line 118 of file ExecutorBase.h.

Referenced by currentOptions(), and execute().

◆ _graph

◆ _indexed_ranks

std::shared_ptr<ir::OperationIndexMap<int64_t> > onert::exec::ExecutorBase::_indexed_ranks
protected

◆ _input_tensors

std::vector<backend::builtin::IOTensor *> onert::exec::ExecutorBase::_input_tensors
protected

◆ _lowered_graph

◆ _mutex

std::mutex onert::exec::ExecutorBase::_mutex
protected

Definition at line 109 of file ExecutorBase.h.

Referenced by execute().

◆ _observers

ExecObservers onert::exec::ExecutorBase::_observers
protected

Definition at line 102 of file ExecutorBase.h.

Referenced by addObserver(), and execute().

◆ _output_tensors

std::vector<backend::builtin::IOTensor *> onert::exec::ExecutorBase::_output_tensors
protected

Definition at line 108 of file ExecutorBase.h.

Referenced by execute(), ExecutorBase(), outputInfo(), outputLayout(), and outputSize().

◆ _tracing_ctx

const util::TracingCtx* onert::exec::ExecutorBase::_tracing_ctx
protected

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