class InferenceEngine::MemoryBlob¶
Overview¶
This class implements a container object that represents a tensor in memory (host and remote/accelerated) More…
#include <ie_blob.h>
class MemoryBlob: public InferenceEngine::Blob
{
public:
// typedefs
typedef std::shared_ptr<MemoryBlob> Ptr;
typedef std::shared_ptr<const MemoryBlob> CPtr;
// construction
MemoryBlob(const TensorDesc& tensorDesc);
// methods
virtual const TensorDesc& getTensorDesc() const;
virtual TensorDesc& getTensorDesc();
virtual size_t size() const;
virtual size_t byteSize() const;
virtual size_t element_size() const;
virtual void allocate() = 0;
virtual bool deallocate() = 0;
virtual LockedMemory<void> rwmap() = 0;
virtual LockedMemory<const void> rmap() const = 0;
virtual LockedMemory<void> wmap() = 0;
};
// direct descendants
class RemoteBlob;
template <
typename T,
typename = std::enable_if<std::is_standard_layout<T>::value&& std::is_trivial<T>::value>
>
class TBlob;
Inherited Members¶
public:
// typedefs
typedef std::shared_ptr<Blob> Ptr;
typedef std::shared_ptr<const Blob> CPtr;
// methods
static Ptr CreateFromData(const DataPtr& data);
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();
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;
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();
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;
virtual const TensorDesc& getTensorDesc() const;
virtual TensorDesc& getTensorDesc();
virtual size_t size() const;
virtual size_t byteSize() const;
virtual size_t element_size() const = 0;
virtual void allocate() = 0;
virtual bool deallocate() = 0;
void setShape(const SizeVector& dims);
virtual Blob::Ptr createROI(const ROI& roi) const;
virtual Blob::Ptr createROI(
const std::vector<std::size_t>& begin,
const std::vector<std::size_t>& end
) const;
Detailed Documentation¶
This class implements a container object that represents a tensor in memory (host and remote/accelerated)
Any Blob implementation that represents a concept of a tensor in memory (for example, TBlob) must be a subclass of MemoryBlob instead of Blob
Typedefs¶
typedef std::shared_ptr<MemoryBlob> Ptr
A smart pointer to the MemoryBlob object.
typedef std::shared_ptr<const MemoryBlob> CPtr
A smart pointer to the const MemoryBlob object.
Construction¶
MemoryBlob(const TensorDesc& tensorDesc)
Constructor. Creates an empty MemoryBlob object with the specified precision.
Parameters:
tensorDesc |
Defines the layout and dims of the blob |
Methods¶
virtual const TensorDesc& getTensorDesc() const
Returns the tensor description.
Returns:
A tensor description
virtual TensorDesc& getTensorDesc()
Returns the tensor description.
Returns:
A tensor description
virtual size_t size() const
Returns the total number of elements, which is a product of all the dimensions.
Returns:
The total number of elements
virtual size_t byteSize() const
Returns the size of the current Blob in bytes calculated as size() \* element_size()
.
Returns:
Blob ‘s size in bytes
virtual size_t element_size() const
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() = 0
Allocates memory to store the data.
Abstract method.
virtual bool deallocate() = 0
Releases previously allocated data.
Abstract method.
Returns:
True
if deallocation happens successfully, false
otherwise.
virtual LockedMemory<void> rwmap() = 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 = 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() = 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