Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends
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::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. Please use the allocate() method to allocate 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. The allocate() call is not required. More...
 
  TBlob (Precision p, Layout l)
 
  TBlob (Precision p, Layout l, const SizeVector &dims)
  Creates a TBlob object with the specified dimensions but does not allocate the memory. Please use the allocate() method to allocate memory. More...
 
  TBlob (Precision p, Layout l, const SizeVector &dims, T *ptr, size_t data_size=0)
  The constructor creates a TBlob object with the specified dimensions on the pre-allocated memory. Therefore, the allocate() call is not required. More...
 
  TBlob (Precision p, Layout l, const SizeVector &dims, std::shared_ptr< IAllocator > alloc)
  Constructor. Creates a TBlob object with the specified precision, layout, dimensions and custom memory allocator. 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...
 
TBlob operator= (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  set (const std::vector< T > &that)
  Copies data from the given vector to the blob. 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...
 
details::BlobIterator< T >  begin ()
  Gets BlobIterator for the data. Enables a ranged loop support for the TBlob object. More...
 
details::BlobIterator< T >  end ()
  Gets BlobIterator for the end of data. Enables a ranged loop support for the TBlob object. More...
 
details::BlobIterator< const T >  begin () const
  Gets a const BlobIterator for the read-only data. Enables a ranged loop support for the TBlob object. More...
 
details::BlobIterator< const T >  end () const
  Gets a const BlobIterator for the end of read-only data. Enables a ranged loop support for the TBlob object. More...
 
- Public Member Functions inherited from InferenceEngine::Blob
Precision  type () const noexcept
  Returns the tensor precision of the current Blob object. More...
 
Precision  precision () const noexcept
  Returns the tensor precision of the current Blob object. More...
 
Layout  layout () const noexcept
  Returns the tensor layout of the current Blob object. More...
 
virtual  ~Blob ()=default
  Blob virtual destructor.
 
  Blob (TensorDesc tensorDesc)
  Constructor. Creates an empty Blob object with the specified precision. More...
 
  Blob (Precision p)
  Constructor. Creates an empty Blob object with the specified precision. More...
 
  Blob (Precision p, Layout l)
  The constructor creates an empty Blob object with the specified precision and layout. More...
 
  Blob (Precision p, const SizeVector &dims)
  The constructor creates an empty Blob object with the specified precision and dimensions. More...
 
  Blob (Precision p, Layout l, const SizeVector &dims)
  The constructor creates an empty Blob object with the specified precision, layout and dimensions. More...
 
size_t  Resize (const SizeVector &dims, Layout layout=Layout::ANY) noexcept
  Changes Tensor size to the specified dimensions. If it was allocated, the previous data is deallocated and lost. More...
 
size_t  Reshape (const SizeVector &dims, Layout layout=Layout::ANY) noexcept
  Changes tensor size to the specified dimensions without changing memory. The total size remains unchanged as well as the memory layout. More...
 
const SizeVector  dims () const noexcept
  Returns the tensor dimensions vector with reversed order. More...
 
const TensorDesc getTensorDesc () const noexcept
  Returns the tensor description.
 
size_t  size () const noexcept
  Returns the total number of elements (a product of all the dims)
 
size_t  byteSize () const noexcept
  Returns the size of the current Blob in bytes.
 

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.
 

Protected Attributes

std::shared_ptr< IAllocator _allocator
  Local instance of IAllocator to manipulate memory.
 
void *  _handle = nullptr
  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.
 

Friends

template<typename , typename >
class  TBlob
 

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's 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/8]

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. Please use the allocate() method to allocate memory.

Parameters
tensorDesc Tensor description

§ TBlob() [2/8]

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
tensorDesc Tensor description
ptr Pointer to the pre-allocated memory
data_size Length of the pre-allocated array. If not set, size is assumed equal to the dot product of dims.

§ TBlob() [3/8]

template<typename T, typename = std::enable_if<std::is_pod<T>::value>>
InferenceEngine::TBlob< T, typename >::TBlob ( Precision  p,
Layout  l 
)
inlineexplicit
Deprecated:
Please use TensorDesc for Blob initialization.

§ TBlob() [4/8]

template<typename T, typename = std::enable_if<std::is_pod<T>::value>>
InferenceEngine::TBlob< T, typename >::TBlob ( Precision  p,
Layout  l,
const SizeVector dims 
)
inline

Creates a TBlob object with the specified dimensions but does not allocate the memory. Please use the allocate() method to allocate memory.

Deprecated:
Please use TensorDesc for Blob initialization.
Parameters
p Precision
l Layout
dims Tensor dimensions

§ TBlob() [5/8]

template<typename T, typename = std::enable_if<std::is_pod<T>::value>>
InferenceEngine::TBlob< T, typename >::TBlob ( Precision  p,
Layout  l,
const SizeVector dims,
T *  ptr,
size_t  data_size = 0 
)
inline

The constructor creates a TBlob object with the specified dimensions on the pre-allocated memory. Therefore, the allocate() call is not required.

Deprecated:
Please use TensorDesc for Blob initialization.

The TBlob object doesn't own memory that is pointed to by the ptr. Therefore, it doesn't free the memory after the TBlob object is destroyed. Also certain operations might fail: After the blob is constructed with this pointer its size is stored in the TBlob instance. If the resize() operation happens which requires more memory, then the call to allocate() fails.

Parameters
p Precision
dims Tensor dimensions
ptr Pointer to the pre-allocated memory
data_size Length of the pre-allocated array. If not set, size is assumed equal to dot product of dims.

§ TBlob() [6/8]

template<typename T, typename = std::enable_if<std::is_pod<T>::value>>
InferenceEngine::TBlob< T, typename >::TBlob ( Precision  p,
Layout  l,
const SizeVector dims,
std::shared_ptr< IAllocator alloc 
)
inline

Constructor. Creates a TBlob object with the specified precision, layout, dimensions and custom memory allocator.

Deprecated:
Please use TensorDesc for Blob initialization.
Parameters
p Precision
l Layout
dims Tensor dimensions
alloc Allocator to be used

§ TBlob() [7/8]

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
blob Source blob

§ TBlob() [8/8]

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
blob rvalue to make a move from

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::Blob.

§ 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::Blob.

§ 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
blob object reference to copy from

§ 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::Blob.

§ 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::Blob.

§ 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
S Type 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
U Type of the blob to move from
Parameters
blob TBlob 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
blob object 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.

§ set()

template<typename T, typename = std::enable_if<std::is_pod<T>::value>>
void InferenceEngine::TBlob< T, typename >::set ( const std::vector< T > &  that )
inline

Copies data from the given vector to the blob.

Deprecated:
Deprecated to avoid memcpy() calls.
Parameters
that Vector of values to copy to the blob

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