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

#include <BackendContext.h>

Collaboration diagram for onert::backend::xnnpack::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 35 of file BackendContext.h.

Constructor & Destructor Documentation

◆ BackendContext()

onert::backend::xnnpack::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 38 of file BackendContext.h.

43 tensor_builder{tensor_builder}, kernel_gen{kernel_gen}, _external_context(nullptr)
44 {
45 int num_threads = util::getConfigInt(util::config::NUM_THREADS);
46 if (num_threads < 1)
47 num_threads = kDefaultNumThreadpoolThreads; // default num of threads
48 _external_context.reset(new ExternalContext(static_cast<size_t>(num_threads)));
49 }
const int kDefaultNumThreadpoolThreads
std::shared_ptr< ITensorRegistry > tensor_registry
const ContextData & data() const
const Backend * backend() const
std::shared_ptr< TensorBuilder > tensor_builder
std::shared_ptr< KernelGenerator > kernel_gen
cpu::ExternalContext ExternalContext
int getConfigInt(const std::string &key)

References onert::util::getConfigInt(), and kDefaultNumThreadpoolThreads.

Member Function Documentation

◆ external_context()

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

Definition at line 54 of file BackendContext.h.

54{ return _external_context; }

◆ genKernels()

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

Implements onert::backend::BackendContext.

Definition at line 36 of file BackendContext.cc.

37{
38 FunctionMap ret;
39
40 for (auto &&op_ind : _data.op_order)
41 {
42 auto fn_seq = kernel_gen->generate(op_ind);
43 ret.emplace(op_ind, std::move(fn_seq));
44 }
45
46 basic::initConsts(*this);
47
48 // NOTE For memory optimization, we want to free some operand data
49 const_cast<ir::Graph &>(*_data.graph)
50 .operands()
51 .iterate([&](const ir::OperandIndex &, ir::Operand &obj) { obj.releaseData(); });
52
53 for (auto &&it : ret)
54 {
55 auto &fn_seq = it.second;
56 fn_seq->iterate([&](exec::IFunction &ifunc) { ifunc.prepare(); });
57 }
58
59 return ret;
60}
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::ContextData::graph, onert::backend::basic::initConsts(), kernel_gen, onert::backend::ContextData::op_order, and onert::exec::IFunction::prepare().

◆ genTensors()

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

Implements onert::backend::BackendContext.

Definition at line 34 of file BackendContext.cc.

34{ return basic::genTensors(*this); }
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::basic::genTensors().

Field Documentation

◆ kernel_gen

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

Definition at line 59 of file BackendContext.h.

Referenced by genKernels().

◆ tensor_builder

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

Definition at line 58 of file BackendContext.h.


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