class InferenceEngine::TBlob

Overview

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

#include <ie_blob.h>

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

    typedef std::shared_ptr<TBlob<T>> Ptr;

    // construction

    TBlob(const TensorDesc& tensorDesc);
    TBlob(const TensorDesc& tensorDesc, T \* ptr, size_t data_size = 0);
    TBlob(const TensorDesc& tensorDesc, const std::shared_ptr<IAllocator>& alloc);
    TBlob(const TBlob<T>& blob);
    TBlob(TBlob<T>&& blob);

    // methods

    TBlob& operator = (const TBlob& blob);
    virtual LockedMemory<T> data();
    virtual LockedMemory<const T> readOnly() const;
    virtual void allocate();
    virtual bool deallocate();
    virtual LockedMemory<void> rwmap();
    virtual LockedMemory<const void> rmap() const;
    virtual LockedMemory<void> wmap();
    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;

    details::BlobIterator<T> begin();
    details::BlobIterator<T> end();
    details::BlobIterator<const T> begin() const;
    details::BlobIterator<const T> end() const;
};

Inherited Members

public:
    // typedefs

    typedef std::shared_ptr<Blob> Ptr;
    typedef std::shared_ptr<const Blob> CPtr;
    typedef std::shared_ptr<MemoryBlob> Ptr;
    typedef std::shared_ptr<const MemoryBlob> 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;

    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;

Detailed Documentation

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

Typedefs

typedef std::shared_ptr<TBlob<T>> Ptr

Smart Pointer to this TBlob object.

Construction

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

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.

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

TBlob(const TBlob<T>& blob)

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

Parameters:

blob

Source blob

TBlob(TBlob<T>&& blob)

A move constructor.

Parameters:

blob

rvalue to make a move from

Methods

TBlob& operator = (const TBlob& blob)

Copy operator for the TBlob object.

Parameters:

blob

object reference to copy from

Returns:

Newly copied object

virtual LockedMemory<T> data()

Creates an new empty rvalue LockedMemory object.

Returns:

rvalue for the empty locked object of type T

virtual LockedMemory<const T> readOnly() const

Creates a new empty rvalue read-only LockedMemory object.

Returns:

rvalue for the empty locked const object of type T.

virtual void allocate()

Allocates memory to store the data.

Abstract method.

virtual bool deallocate()

Releases previously allocated data.

Abstract method.

Returns:

True if deallocation happens successfully, false otherwise.

virtual LockedMemory<void> rwmap()

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

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()

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

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

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.

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

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.

details::BlobIterator<T> begin()

Gets BlobIterator for the data.

Enables a ranged loop support for the TBlob object.

Returns:

BlobIterator object of type T

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

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

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