Class InferenceEngine::TBlob

template<typename T, typename = std::enable_if<std::is_standard_layout<T>::value && std::is_trivial<T>::value>>
class TBlob : public InferenceEngine::MemoryBlob

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

Public Types

using Ptr = std::shared_ptr<TBlob<T>>

Smart Pointer to this TBlob object.

Public Functions

inline explicit TBlob(const TensorDesc &tensorDesc)

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

Use the allocate() method to allocate memory.

Parameters

tensorDesc – Tensor description

inline 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.

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.

inline 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.

Parameters
  • tensorDesc – Tensor description

  • alloc – An allocator

inline TBlob(const TBlob<T> &blob)

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

Parameters

blob – Source blob

inline TBlob(TBlob<T> &&blob)

A move constructor.

Parameters

blob – rvalue to make a move from

inline TBlob &operator=(const TBlob &blob)

Copy operator for the TBlob object.

Parameters

blob – object reference to copy from

Returns

Newly copied object

inline virtual ~TBlob()

Virtual destructor.

inline virtual LockedMemory<T> data() noexcept

Creates an new empty rvalue LockedMemory object.

Returns

rvalue for the empty locked object of type T

inline virtual LockedMemory<const T> readOnly() const noexcept

Creates a new empty rvalue read-only LockedMemory object.

Returns

rvalue for the empty locked const object of type T.

inline virtual void allocate() noexcept override

Allocates memory to store the data.

Abstract method.

inline virtual bool deallocate() noexcept override

Releases previously allocated data.

Abstract method.

Returns

True if deallocation happens successfully, false otherwise.

inline virtual 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.

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

inline virtual 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.

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

inline virtual 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.

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

inline virtual Blob::Ptr createROI(const ROI &roi) const override

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

Note: default implementation throws “not implemented” exception.

Parameters

roi – A ROI object inside of the current blob.

Returns

A shared pointer to the newly created ROI blob.

inline virtual Blob::Ptr createROI(const std::vector<std::size_t> &begin, const std::vector<std::size_t> &end) const override

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

Note: default implementation may throws “not implemented” exception.

Parameters
  • begin – A ROI start coordinate

  • end – A ROI end coordinate

Returns

A shared pointer to the newly created ROI blob.

inline details::BlobIterator<T> begin()

Gets BlobIterator for the data.

Enables a ranged loop support for the TBlob object.

Returns

BlobIterator object of type T

inline details::BlobIterator<T> end()

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

inline details::BlobIterator<const T> begin() const

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

inline 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.

Returns

BlobIterator object of type const T representing end of data