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

#include <BackendContext.h>

Collaboration diagram for onert::backend::cpu::BackendContext:

Public Member Functions

 BackendContext (const Backend *backend, ContextData &&data, std::shared_ptr< ITensorRegistry > tensor_registry=nullptr, std::shared_ptr< TensorBuilder > tensor_builder=nullptr, std::shared_ptr< KernelGenerator > kernel_gen=nullptr)
 
ITensorRegistrygenTensors () override
 
FunctionMap genKernels () override
 
std::shared_ptr< ExternalContextexternal_context ()
 
- Public Member Functions inherited from onert::backend::BackendContext
 BackendContext (const Backend *backend, ContextData &&data, std::shared_ptr< ITensorRegistry > tensor_registry=nullptr)
 
virtual ~BackendContext ()=default
 
const Backendbackend () const
 
const ir::Graphgraph () const
 
const util::Set< ir::OperandIndex > & external_operands () const
 
const ContextDatadata () const
 

Data Fields

std::shared_ptr< TensorBuildertensor_builder
 
std::shared_ptr< KernelGeneratorkernel_gen
 
- Data Fields inherited from onert::backend::BackendContext
std::shared_ptr< ITensorRegistrytensor_registry
 

Additional Inherited Members

- Protected Attributes inherited from onert::backend::BackendContext
const Backend_backend {nullptr}
 
ContextData _data
 

Detailed Description

Definition at line 32 of file BackendContext.h.

Constructor & Destructor Documentation

◆ BackendContext()

onert::backend::cpu::BackendContext::BackendContext ( const Backend backend,
ContextData &&  data,
std::shared_ptr< ITensorRegistry tensor_registry = nullptr,
std::shared_ptr< TensorBuilder tensor_builder = nullptr,
std::shared_ptr< KernelGenerator kernel_gen = nullptr 
)
inline

Definition at line 35 of file BackendContext.h.

40 tensor_builder{tensor_builder}, kernel_gen{kernel_gen}, _external_context(new ExternalContext)
41 {
42 }
std::shared_ptr< ITensorRegistry > tensor_registry
const ContextData & data() const
const Backend * backend() const
std::shared_ptr< KernelGenerator > kernel_gen
std::shared_ptr< TensorBuilder > tensor_builder

Member Function Documentation

◆ external_context()

std::shared_ptr< ExternalContext > onert::backend::cpu::BackendContext::external_context ( )
inline

Definition at line 47 of file BackendContext.h.

47{ return _external_context; }

◆ genKernels()

FunctionMap onert::backend::cpu::BackendContext::genKernels ( )
overridevirtual

Implements onert::backend::BackendContext.

Definition at line 43 of file BackendContext.cc.

44{
45 FunctionMap ret;
46
48 tensor_builder->getSharedMemoryOperandIndexes());
49
50 // TODO: Change type of tensor_registry field to TensorRegistry
51 auto tensor_registry_concreted =
52 nnfw::misc::polymorphic_downcast<basic::TensorRegistry *>(tensor_registry.get());
53 basic::initSharedMemoryConsts(graph()->operands(), external_operands(), tensor_registry_concreted,
54 tensor_builder->getSharedMemoryOperandIndexes());
55
56 for (auto &&op_ind : _data.op_order)
57 {
58 auto fn_seq = kernel_gen->generate(op_ind);
59 ret.emplace(op_ind, std::move(fn_seq));
60 }
61
62 // NOTE For memory optimization, we want to free some operand data
63 const_cast<ir::Graph &>(*_data.graph)
64 .operands()
65 .iterate([&](const ir::OperandIndex &, ir::Operand &obj) { obj.releaseData(); });
66
67 for (auto &&it : ret)
68 {
69 auto &fn_seq = it.second;
70 fn_seq->iterate([&](exec::IFunction &ifunc) { ifunc.prepare(); });
71 }
72
73 return ret;
74}
const ir::Graph * graph() const
const util::Set< ir::OperandIndex > & external_operands() const
void initSharedMemoryConsts(const ir::Operands &operands, const util::Set< ir::OperandIndex > &external_operands, TensorRegistry *tensor_registry, const ir::OperandIndexMap< ir::OperandIndex > &shared_memory_operands_map)
void initConsts(const ir::Operands &operands, const util::Set< ir::OperandIndex > &external_operands, ITensorRegistry *tensor_registry, const ir::OperandIndexMap< ir::OperandIndex > &shared_memory_operands_map)
std::unordered_map< ir::OperationIndex, std::unique_ptr< exec::FunctionSequence > > FunctionMap
::onert::util::Index< uint32_t, OperandIndexTag > OperandIndex
Definition Index.h:35
std::unique_ptr< ir::Graph > graph

References onert::backend::BackendContext::_data, onert::backend::BackendContext::external_operands(), onert::backend::ContextData::graph, onert::backend::BackendContext::graph(), onert::backend::basic::initConsts(), onert::backend::basic::initSharedMemoryConsts(), kernel_gen, onert::backend::ContextData::op_order, onert::exec::IFunction::prepare(), tensor_builder, and onert::backend::BackendContext::tensor_registry.

◆ genTensors()

ITensorRegistry * onert::backend::cpu::BackendContext::genTensors ( )
overridevirtual

Implements onert::backend::BackendContext.

Definition at line 37 of file BackendContext.cc.

38{
40 data().op_order, tensor_builder->getSharedMemoryOperandIndexes());
41}
ITensorRegistry * genTensors(const std::shared_ptr< T_TensorBuilder > &tensor_builder, const ir::Graph &graph, const util::Set< ir::OperandIndex > &external_operands, const std::shared_ptr< ITensorRegistry > &tensor_registry, const std::vector< onert::ir::OperationIndex > &op_order, const ir::OperandIndexMap< ir::OperandIndex > &shared_memory_operand_idx)

References onert::backend::BackendContext::data(), onert::backend::BackendContext::external_operands(), onert::backend::basic::genTensors(), onert::backend::BackendContext::graph(), tensor_builder, and onert::backend::BackendContext::tensor_registry.

Field Documentation

◆ kernel_gen

std::shared_ptr<KernelGenerator> onert::backend::cpu::BackendContext::kernel_gen

Definition at line 52 of file BackendContext.h.

Referenced by genKernels().

◆ tensor_builder

std::shared_ptr<TensorBuilder> onert::backend::cpu::BackendContext::tensor_builder

Definition at line 51 of file BackendContext.h.

Referenced by genKernels(), and genTensors().


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