Class InferenceEngine::MemoryBlob

class MemoryBlob : public InferenceEngine::Blob

This class implements a container object that represents a tensor in memory (host and remote/accelerated)

Note

Any Blob implementation that represents a concept of a tensor in memory (for example, TBlob) must be a subclass of MemoryBlob instead of Blob

Subclassed by InferenceEngine::RemoteBlob, InferenceEngine::TBlob< T, typename >

Public Types

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 Functions

virtual ~MemoryBlob()

MemoryBlob virtual destructor.

inline explicit MemoryBlob(const TensorDesc &tensorDesc)

Constructor. Creates an empty MemoryBlob object with the specified precision.

Parameters

tensorDesc – Defines the layout and dims of the blob

inline virtual const TensorDesc &getTensorDesc() const noexcept override

Returns the tensor description.

Returns

A tensor description

inline virtual TensorDesc &getTensorDesc() noexcept override

Returns the tensor description.

Returns

A tensor description

inline virtual size_t size() const noexcept override

Returns the total number of elements, which is a product of all the dimensions.

Returns

The total number of elements

inline virtual size_t byteSize() const override

Returns the size of the current Blob in bytes calculated as size() * element_size().

Returns

Blob’s size in bytes

inline virtual size_t element_size() const override

Provides the number of bytes per element.

Deprecated:

Cast to MemoryBlob and use its API instead. Blob class can represent compound blob, which do not refer to the only solid memory.

The overall Blob capacity is size() * element_size(). Abstract method.

Returns

Returns the number of bytes per element

virtual void allocate() noexcept override = 0

Allocates memory to store the data.

Abstract method.

virtual bool deallocate() noexcept override = 0

Releases previously allocated data.

Abstract method.

Returns

True if deallocation happens successfully, false otherwise.

virtual LockedMemory<void> rwmap() noexcept = 0

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

virtual LockedMemory<const void> rmap() const noexcept = 0

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

virtual LockedMemory<void> wmap() noexcept = 0

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