ONE - On-device Neural Engine
Loading...
Searching...
No Matches
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 82 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 85 of file ITensorRegistry.h.

86 {
87 static_assert(std::is_base_of<ITensor, T_Tensor>::value, "T_Tensor must derive from ITensor.");
88 auto _migrant_tensor = _migrant.find(ind);
89 if (_migrant_tensor != _migrant.end())
90 return _migrant_tensor->second;
91 return getNativeTensor(ind);
92 }
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 94 of file ITensorRegistry.h.

94{ 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 96 of file ITensorRegistry.h.

97 {
98 auto _migrant_tensor = _migrant.find(ind);
99 if (_migrant_tensor != _migrant.end())
100 {
101 if (_migrant_tensor->second)
102 return _migrant_tensor->second;
103 }
104 return getNativeTensor(ind);
105 }

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 136 of file ITensorRegistry.h.

136{ 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 134 of file ITensorRegistry.h.

134{ 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 115 of file ITensorRegistry.h.

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

◆ 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 125 of file ITensorRegistry.h.

126 {
127 assert(tensor != nullptr);
128 auto itr = _migrant.find(ind);
129 if (itr != _migrant.end())
130 throw std::runtime_error{"Tried to set a native tensor but a migrant tensor already exists."};
131 _native[ind] = std::move(tensor);
132 }

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