Public Types | Public Member Functions | Protected Member Functions | Protected Attributes
InferenceEngine::TBlob< T, typename > Class Template Reference

Represents real host memory allocated for a Tensor/Blob per C type. More...

#include <ie_blob.h>

Inheritance diagram for InferenceEngine::TBlob< T, typename >:
Inheritance graph
[legend]
Collaboration diagram for InferenceEngine::TBlob< T, typename >:
Collaboration graph
[legend]

Public Types

using Ptr = std::shared_ptr< TBlob< T > >
 Smart Pointer to this TBlob object.
 
- Public Types inherited from InferenceEngine::MemoryBlob
using Ptr = std::shared_ptr< MemoryBlob >
 A smart pointer to the MemoryBlob object.
 
using CPtr = std::shared_ptr< const MemoryBlob >
 A smart pointer to the const MemoryBlob object.
 
- Public Types inherited from InferenceEngine::Blob
using Ptr = std::shared_ptr< Blob >
 A smart pointer containing Blob object.
 
using CPtr = std::shared_ptr< const Blob >
 A smart pointer to the const Blob object.
 

Public Member Functions

 TBlob (const TensorDesc &tensorDesc)
 Creates a TBlob object with the specified dimensions and layout but does not allocate the memory. More...
 
 TBlob (const TensorDesc &tensorDesc, T *ptr, size_t data_size=0)
 The constructor creates a TBlob object with the specified dimensions and layout on the pre-allocated memory. More...
 
 TBlob (const TensorDesc &tensorDesc, const std::shared_ptr< IAllocator > &alloc)
 Creates a TBlob object with the specified dimensions, layout and custom memory allocator but does not allocate the memory. More...
 
 TBlob (const TBlob< T > &blob)
 The copy constructor data is reallocated and copied from the source to the target blob. More...
 
 TBlob (TBlob< T > &&blob)
 A move constructor. More...
 
TBloboperator= (const TBlob &blob)
 Copy operator for the TBlob object. More...
 
virtual ~TBlob ()
 Virtual destructor.
 
size_t element_size () const noexcept override
 Gets the size of the given type. More...
 
virtual LockedMemory< T > data () noexcept
 Creates an new empty rvalue LockedMemory object. More...
 
virtual LockedMemory< const T > readOnly () const noexcept
 Creates a new empty rvalue read-only LockedMemory object. More...
 
void allocate () noexcept override
 Allocates or reallocates memory.
 
bool deallocate () noexcept override
 Frees all allocated data.
 
LockedMemory< void > buffer () noexcept override
 Creates a new LockedMemory instance holding void pointer. More...
 
LockedMemory< const void > cbuffer () const noexcept override
 Creates a new LockedMemory instance holding constant void pointer. More...
 
LockedMemory< void > rwmap () noexcept override
 Gets read/write access to the memory in virtual space of the process. The function returns object which retains mapped memory. The memory been addressed in the MemoryBlob in general case can be allocated on remote device. This function maps remote memory to the memory in the virtual process space and after destruction of the LockedMemory will upload changed content to the accelerator. More...
 
LockedMemory< const void > rmap () const noexcept override
 Gets read only access to the memory in virtual space of the process. The function returns object which retains mapped memory. More...
 
LockedMemory< void > wmap () noexcept override
 Gets "write only direction" access to the memory in virtual space of the process. The function returns object which retains memory to be uploaded on device. More...
 
Blob::Ptr createROI (const ROI &roi) const override
 Creates a blob describing given ROI object based on the current blob with memory sharing. More...
 
details::BlobIterator< T > begin ()
 Gets BlobIterator for the data. More...
 
details::BlobIterator< T > end ()
 Gets BlobIterator for the end of data. More...
 
details::BlobIterator< const T > begin () const
 Gets a const BlobIterator for the read-only data. More...
 
details::BlobIterator< const T > end () const
 Gets a const BlobIterator for the end of read-only data. More...
 
- Public Member Functions inherited from InferenceEngine::MemoryBlob
virtual ~MemoryBlob ()
 MemoryBlob virtual destructor.
 
 MemoryBlob (const TensorDesc &tensorDesc)
 Constructor. Creates an empty MemoryBlob object with the specified precision. More...
 
const TensorDescgetTensorDesc () const noexcept override
 Returns the tensor description.
 
TensorDescgetTensorDesc () noexcept override
 Returns the tensor description.
 
size_t size () const noexcept override
 Returns the total number of elements, which is a product of all the dimensions. More...
 
size_t byteSize () const noexcept override
 Returns the size of the current Blob in bytes calculated as size() * element_size(). More...
 
- Public Member Functions inherited from InferenceEngine::Blob
virtual ~Blob ()
 Blob virtual destructor.
 
template<typename T , typename std::enable_if<!std::is_pointer< T >::value &&!std::is_reference< T >::value, int >::type = 0, typename std::enable_if< std::is_base_of< Blob, T >::value, int >::type = 0>
bool is () noexcept
 Checks if the Blob object can be cast to the type T*. More...
 
template<typename T , typename std::enable_if<!std::is_pointer< T >::value &&!std::is_reference< T >::value, int >::type = 0, typename std::enable_if< std::is_base_of< Blob, T >::value, int >::type = 0>
bool is () const noexcept
 Checks if the Blob object can be cast to the type const T*. More...
 
template<typename T , typename std::enable_if<!std::is_pointer< T >::value &&!std::is_reference< T >::value, int >::type = 0, typename std::enable_if< std::is_base_of< Blob, T >::value, int >::type = 0>
T * as () noexcept
 Casts this Blob object to the type T*. More...
 
template<typename T , typename std::enable_if<!std::is_pointer< T >::value &&!std::is_reference< T >::value, int >::type = 0, typename std::enable_if< std::is_base_of< Blob, T >::value, int >::type = 0>
const T * as () const noexcept
 Casts this Blob object to the type const T*. More...
 
 Blob (const TensorDesc &tensorDesc)
 Constructor. Creates an empty Blob object with the specified precision. More...
 

Protected Member Functions

void copyFrom (const TBlob< T > &blob)
 Copies dimensions and data from the TBlob object. More...
 
template<class U >
void moveFrom (TBlob< U > &blob)
 Swaps memory handlers between the current blob and the given one. More...
 
virtual bool free ()
 Frees handler and cleans up the stored data.
 
template<class S >
LockedMemory< S > lockme () const
 Creates a LockedMemory instance. More...
 
const std::shared_ptr< IAllocator > & getAllocator () const noexcept override
 Gets an allocator or creates a default one. More...
 
void * getHandle () const noexcept override
 Returns handle to the stored data.
 
 TBlob (const TBlob &origBlob, const ROI &roi)
 Creates a blob from the existing blob with a given ROI. More...
 

Protected Attributes

std::shared_ptr< IAllocator_allocator
 Local instance of IAllocator to manipulate memory.
 
std::shared_ptr< void > _handle
 A handle for the stored memory returned from _allocator.alloc().
 
- Protected Attributes inherited from InferenceEngine::Blob
TensorDesc tensorDesc
 The tensor descriptor of the given blob.
 

Additional Inherited Members

- Static Public Member Functions inherited from InferenceEngine::Blob
static Ptr CreateFromData (const DataPtr &data)
 Creates a TBlob<> object from a Data node. More...
 
- Static Protected Member Functions inherited from InferenceEngine::Blob
static size_t product (const SizeVector &dims) noexcept
 Multiplies the dimension vector values. More...
 

Detailed Description

template<typename T, typename = std::enable_if<std::is_pod<T>::value>>
class InferenceEngine::TBlob< T, typename >

Represents real host memory allocated for a Tensor/Blob per C type.

Constructor & Destructor Documentation

◆ TBlob() [1/6]

template<typename T , typename = std::enable_if<std::is_pod<T>::value>>
InferenceEngine::TBlob< T, typename >::TBlob ( const TensorDesc tensorDesc)
inlineexplicit

Creates a TBlob object with the specified dimensions and layout but does not allocate the memory.

Use the allocate() method to allocate memory.

Parameters
tensorDescTensor description

◆ TBlob() [2/6]

template<typename T , typename = std::enable_if<std::is_pod<T>::value>>
InferenceEngine::TBlob< T, typename >::TBlob ( const TensorDesc tensorDesc,
T *  ptr,
size_t  data_size = 0 
)
inline

The constructor creates a TBlob object with the specified dimensions and layout on the pre-allocated memory.

The allocate() call is not required.

Parameters
tensorDescTensor description
ptrPointer to the pre-allocated memory
data_sizeLength of the pre-allocated array. If not set, size is assumed equal to the dot product of dims.

◆ TBlob() [3/6]

template<typename T , typename = std::enable_if<std::is_pod<T>::value>>
InferenceEngine::TBlob< T, typename >::TBlob ( const TensorDesc tensorDesc,
const std::shared_ptr< IAllocator > &  alloc 
)
inline

Creates a TBlob object with the specified dimensions, layout and custom memory allocator but does not allocate the memory.

Parameters
tensorDescTensor description
allocAn allocator

◆ TBlob() [4/6]

template<typename T , typename = std::enable_if<std::is_pod<T>::value>>
InferenceEngine::TBlob< T, typename >::TBlob ( const TBlob< T > &  blob)
inline

The copy constructor data is reallocated and copied from the source to the target blob.

Parameters
blobSource blob

◆ TBlob() [5/6]

template<typename T , typename = std::enable_if<std::is_pod<T>::value>>
InferenceEngine::TBlob< T, typename >::TBlob ( TBlob< T > &&  blob)
inline

A move constructor.

Parameters
blobrvalue to make a move from

◆ TBlob() [6/6]

template<typename T , typename = std::enable_if<std::is_pod<T>::value>>
InferenceEngine::TBlob< T, typename >::TBlob ( const TBlob< T, typename > &  origBlob,
const ROI roi 
)
inlineprotected

Creates a blob from the existing blob with a given ROI.

Parameters
origBlobAn original blob
roiA ROI object

Member Function Documentation

◆ begin() [1/2]

template<typename T , typename = std::enable_if<std::is_pod<T>::value>>
details::BlobIterator<T> InferenceEngine::TBlob< T, typename >::begin ( )
inline

Gets BlobIterator for the data.

Enables a ranged loop support for the TBlob object.

Returns
BlobIterator object of type T

◆ begin() [2/2]

template<typename T , typename = std::enable_if<std::is_pod<T>::value>>
details::BlobIterator<const T> InferenceEngine::TBlob< T, typename >::begin ( ) const
inline

Gets a const BlobIterator for the read-only data.

Enables a ranged loop support for the TBlob object.

Returns
BlobIterator object of type const T

◆ buffer()

template<typename T , typename = std::enable_if<std::is_pod<T>::value>>
LockedMemory<void> InferenceEngine::TBlob< T, typename >::buffer ( )
inlineoverridevirtualnoexcept

Creates a new LockedMemory instance holding void pointer.

Returns
LockedMemory instance holding void pointer

Implements InferenceEngine::MemoryBlob.

◆ cbuffer()

template<typename T , typename = std::enable_if<std::is_pod<T>::value>>
LockedMemory<const void> InferenceEngine::TBlob< T, typename >::cbuffer ( ) const
inlineoverridevirtualnoexcept

Creates a new LockedMemory instance holding constant void pointer.

Returns
LockedMemory instance holding constant void pointer

Implements InferenceEngine::MemoryBlob.

◆ copyFrom()

template<typename T , typename = std::enable_if<std::is_pod<T>::value>>
void InferenceEngine::TBlob< T, typename >::copyFrom ( const TBlob< T > &  blob)
inlineprotected

Copies dimensions and data from the TBlob object.

Parameters
blobobject reference to copy from

◆ createROI()

template<typename T , typename = std::enable_if<std::is_pod<T>::value>>
Blob::Ptr InferenceEngine::TBlob< T, typename >::createROI ( const ROI roi) const
inlineoverridevirtual

Creates a blob describing given ROI object based on the current blob with memory sharing.

Note: default implementation throws "not implemented" exception.

Parameters
roiA ROI object inside of the current blob.
Returns
A shared pointer to the newly created ROI blob.

Reimplemented from InferenceEngine::Blob.

◆ data()

template<typename T , typename = std::enable_if<std::is_pod<T>::value>>
virtual LockedMemory<T> InferenceEngine::TBlob< T, typename >::data ( )
inlinevirtualnoexcept

Creates an new empty rvalue LockedMemory object.

Returns
rvalue for the empty locked object of type T

◆ element_size()

template<typename T , typename = std::enable_if<std::is_pod<T>::value>>
size_t InferenceEngine::TBlob< T, typename >::element_size ( ) const
inlineoverridevirtualnoexcept

Gets the size of the given type.

Returns
Size of the type

Implements InferenceEngine::MemoryBlob.

◆ end() [1/2]

template<typename T , typename = std::enable_if<std::is_pod<T>::value>>
details::BlobIterator<T> InferenceEngine::TBlob< T, typename >::end ( )
inline

Gets BlobIterator for the end of data.

Enables a ranged loop support for the TBlob object.

Returns
BlobIterator object of type T representing end of the data

◆ end() [2/2]

template<typename T , typename = std::enable_if<std::is_pod<T>::value>>
details::BlobIterator<const T> InferenceEngine::TBlob< T, typename >::end ( ) const
inline

Gets a const BlobIterator for the end of read-only data.

Enables a ranged loop support for the TBlob object.

Returns
BlobIterator object of type const T representing end of data

◆ getAllocator()

template<typename T , typename = std::enable_if<std::is_pod<T>::value>>
const std::shared_ptr<IAllocator>& InferenceEngine::TBlob< T, typename >::getAllocator ( ) const
inlineoverrideprotectedvirtualnoexcept

Gets an allocator or creates a default one.

Returns
IAllocator instance

Implements InferenceEngine::MemoryBlob.

◆ lockme()

template<typename T , typename = std::enable_if<std::is_pod<T>::value>>
template<class S >
LockedMemory<S> InferenceEngine::TBlob< T, typename >::lockme ( ) const
inlineprotected

Creates a LockedMemory instance.

Template Parameters
SType of the LockedMemory to be created
Returns
A created instance of LockedMemory

◆ moveFrom()

template<typename T , typename = std::enable_if<std::is_pod<T>::value>>
template<class U >
void InferenceEngine::TBlob< T, typename >::moveFrom ( TBlob< U > &  blob)
inlineprotected

Swaps memory handlers between the current blob and the given one.

Template Parameters
UType of the blob to move from
Parameters
blobTBlob instance to move from

◆ operator=()

template<typename T , typename = std::enable_if<std::is_pod<T>::value>>
TBlob& InferenceEngine::TBlob< T, typename >::operator= ( const TBlob< T, typename > &  blob)
inline

Copy operator for the TBlob object.

Parameters
blobobject reference to copy from
Returns
Newly copied object

◆ readOnly()

template<typename T , typename = std::enable_if<std::is_pod<T>::value>>
virtual LockedMemory<const T> InferenceEngine::TBlob< T, typename >::readOnly ( ) const
inlinevirtualnoexcept

Creates a new empty rvalue read-only LockedMemory object.

Returns
rvalue for the empty locked const object of type T.

◆ rmap()

template<typename T , typename = std::enable_if<std::is_pod<T>::value>>
LockedMemory<const void> InferenceEngine::TBlob< T, typename >::rmap ( ) const
inlineoverridevirtualnoexcept

Gets read only access to the memory in virtual space of the process. The function returns object which retains mapped memory.

The memory been addressed in the MemoryBlob in general case can be allocated on remote device. This function copies remote memory to the memory in the virtual process space and after destruction of the LockedMemory it will not upload host memory back, because it is expected that content is not changed.

To have an ability change content, you can use rwmap() and wmap() functions.

In case of memory originally allocated on the host, this function returns LockedMemory which will transparently refer to original memory address. No extra copy will happen

In general case, pointer received from that LockedMemory becomes invalid just after destruction of LockedMemory instance. Keep Locked memory alive while you need to address memory in the process on the host.

Abstract method.

Returns
A LockedMemory object

Implements InferenceEngine::MemoryBlob.

◆ rwmap()

template<typename T , typename = std::enable_if<std::is_pod<T>::value>>
LockedMemory<void> InferenceEngine::TBlob< T, typename >::rwmap ( )
inlineoverridevirtualnoexcept

Gets read/write access to the memory in virtual space of the process. The function returns object which retains mapped memory. The memory been addressed in the MemoryBlob in general case can be allocated on remote device. This function maps remote memory to the memory in the virtual process space and after destruction of the LockedMemory will upload changed content to the accelerator.

To avoid extra copy of data, you can use rmap() and wmap() functions.

In case of memory originally allocated on the host, this function returns LockedMemory which will transparently refer to original memory address. No extra copy will happen

In general case, pointer received from that LockedMemory becomes invalid just after destruction of LockedMemory instance. Keep Locked memory alive while you need to address memory in the process on the host.

Abstract method.

Returns
A LockedMemory object

Implements InferenceEngine::MemoryBlob.

◆ wmap()

template<typename T , typename = std::enable_if<std::is_pod<T>::value>>
LockedMemory<void> InferenceEngine::TBlob< T, typename >::wmap ( )
inlineoverridevirtualnoexcept

Gets "write only direction" access to the memory in virtual space of the process. The function returns object which retains memory to be uploaded on device.

The memory been addressed in the MemoryBlob in general case can be allocated on remote device. This function does not copy of the content from the device to the memory in the virtual process space, the content of the memory just after calling of this function is not specified. After destruction of the LockedMemory, content will be upload host memory. In the same time there is no abilities to restrict reading from the memory, you need to care of reading from memory got by wmap(), it might have sense in some cases like filling of content and before uploading to device

To access data stored in the blob, you can use rwmap() and rmap() functions.

In case of memory originally allocated on the host, this function returns LockedMemory which will transparently refer to original memory address. No extra copy will happen

In general case, pointer received from that LockedMemory becomes invalid just after destruction of LockedMemory instance. Keep Locked memory alive while you need to address memory in the process on the host.

Abstract method.

Returns
A LockedMemory object

Implements InferenceEngine::MemoryBlob.


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