ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
onert::backend::PortableTensorRegistryTemplate< T_Tensor > Class Template Reference

TensorRegistry template class for the convenience of backend implementations. More...

#include <ITensorRegistry.h>

Collaboration diagram for onert::backend::PortableTensorRegistryTemplate< T_Tensor >:

Public Member Functions

ITensorgetITensor (const ir::OperandIndex &ind) override
 Returns pointer of ITensor among native and migrant tensors.
 
ITensorgetNativeITensor (const ir::OperandIndex &ind) override
 Returns pointer of ITensor among native tensors.
 
IPortableTensorgetPortableTensor (const ir::OperandIndex &ind)
 
T_Tensor * getNativeTensor (const ir::OperandIndex &ind)
 
bool setMigrantTensor (const ir::OperandIndex &ind, IPortableTensor *tensor) override
 Set the Migrant Tensor which are from other backends.
 
void setNativeTensor (const ir::OperandIndex &ind, std::unique_ptr< T_Tensor > &&tensor)
 
const ir::OperandIndexMap< std::unique_ptr< T_Tensor > > & native_tensors ()
 
const ir::OperandIndexMap< IPortableTensor * > & migrant_tensors ()
 
- Public Member Functions inherited from onert::backend::ITensorRegistry
virtual ~ITensorRegistry ()=default
 Deconstruct itself.
 

Detailed Description

template<typename T_Tensor>
class onert::backend::PortableTensorRegistryTemplate< T_Tensor >

TensorRegistry template class for the convenience of backend implementations.

If a backend uses IPortableTensor , and there is no special reason to implement ITensorRegistry on your own, you may just use this default implementation.

Template Parameters
T_TensorTensor type. Must be a subclass of onert::backend::IPortableTensor .

Definition at line 77 of file ITensorRegistry.h.

Member Function Documentation

◆ getITensor()

template<typename T_Tensor >
ITensor * onert::backend::PortableTensorRegistryTemplate< T_Tensor >::getITensor ( const ir::OperandIndex )
inlineoverridevirtual

Returns pointer of ITensor among native and migrant tensors.

Native Tensor is a tensor that is managed by this backend Migrant Tensor is a tensor that is imported from another backend

Note
Return tensor cannot be used longer than dynamic tensor manager

Implements onert::backend::ITensorRegistry.

Definition at line 80 of file ITensorRegistry.h.

81 {
82 static_assert(std::is_base_of<ITensor, T_Tensor>::value, "T_Tensor must derive from ITensor.");
83 auto _migrant_tensor = _migrant.find(ind);
84 if (_migrant_tensor != _migrant.end())
85 return _migrant_tensor->second;
86 return getNativeTensor(ind);
87 }
T_Tensor * getNativeTensor(const ir::OperandIndex &ind)

References onert::backend::PortableTensorRegistryTemplate< T_Tensor >::getNativeTensor().

◆ getNativeITensor()

template<typename T_Tensor >
ITensor * onert::backend::PortableTensorRegistryTemplate< T_Tensor >::getNativeITensor ( const ir::OperandIndex )
inlineoverridevirtual

Returns pointer of ITensor among native tensors.

Unlike getITensor , this function only searches from native tensors

Note
Returned tensor cannot be used longer than dynamic tensor manager

Implements onert::backend::ITensorRegistry.

Definition at line 89 of file ITensorRegistry.h.

89{ return getNativeTensor(ind); }

References onert::backend::PortableTensorRegistryTemplate< T_Tensor >::getNativeTensor().

◆ getNativeTensor()

template<typename T_Tensor >
T_Tensor * onert::backend::PortableTensorRegistryTemplate< T_Tensor >::getNativeTensor ( const ir::OperandIndex ind)
inline

◆ getPortableTensor()

template<typename T_Tensor >
IPortableTensor * onert::backend::PortableTensorRegistryTemplate< T_Tensor >::getPortableTensor ( const ir::OperandIndex ind)
inline

Definition at line 91 of file ITensorRegistry.h.

92 {
93 auto _migrant_tensor = _migrant.find(ind);
94 if (_migrant_tensor != _migrant.end())
95 {
96 if (_migrant_tensor->second)
97 return _migrant_tensor->second;
98 }
99 return getNativeTensor(ind);
100 }

References onert::backend::PortableTensorRegistryTemplate< T_Tensor >::getNativeTensor().

◆ migrant_tensors()

template<typename T_Tensor >
const ir::OperandIndexMap< IPortableTensor * > & onert::backend::PortableTensorRegistryTemplate< T_Tensor >::migrant_tensors ( )
inline

Definition at line 131 of file ITensorRegistry.h.

131{ return _migrant; }

◆ native_tensors()

template<typename T_Tensor >
const ir::OperandIndexMap< std::unique_ptr< T_Tensor > > & onert::backend::PortableTensorRegistryTemplate< T_Tensor >::native_tensors ( )
inline

Definition at line 129 of file ITensorRegistry.h.

129{ return _native; }

◆ setMigrantTensor()

template<typename T_Tensor >
bool onert::backend::PortableTensorRegistryTemplate< T_Tensor >::setMigrantTensor ( const ir::OperandIndex ,
IPortableTensor  
)
inlineoverridevirtual

Set the Migrant Tensor which are from other backends.

Returns
true if supported
false if not supported

Reimplemented from onert::backend::ITensorRegistry.

Definition at line 110 of file ITensorRegistry.h.

111 {
112 assert(tensor != nullptr);
113 auto itr = _native.find(ind);
114 if (itr != _native.end())
115 throw std::runtime_error{"Tried to set a migrant tensor but a native tensor already exists."};
116 _migrant[ind] = tensor;
117 return true;
118 }

◆ setNativeTensor()

template<typename T_Tensor >
void onert::backend::PortableTensorRegistryTemplate< T_Tensor >::setNativeTensor ( const ir::OperandIndex ind,
std::unique_ptr< T_Tensor > &&  tensor 
)
inline

Definition at line 120 of file ITensorRegistry.h.

121 {
122 assert(tensor != nullptr);
123 auto itr = _migrant.find(ind);
124 if (itr != _migrant.end())
125 throw std::runtime_error{"Tried to set a native tensor but a migrant tensor already exists."};
126 _native[ind] = std::move(tensor);
127 }

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