38 using Ptr = std::shared_ptr<Blob>;
43 using CPtr = std::shared_ptr<const Blob>;
79 virtual ~Blob() =
default;
131 if (
layout != Layout::ANY) {
154 if (
layout != Layout::ANY) {
201 virtual void allocate() noexcept = 0;
237 return std::accumulate(std::begin(
dims), std::end(
dims), (
size_t) 1, std::multiplies<size_t>());
244 virtual const std::shared_ptr<IAllocator> &
getAllocator()
const noexcept = 0;
250 virtual void *
getHandle()
const noexcept = 0;
252 template<
typename>
friend
259 using BlobMap = std::map<std::string, Blob::Ptr>;
265 typename = std::enable_if<std::is_pod<T>::value>>
267 template<
typename,
typename>
friend
275 using Ptr = std::shared_ptr<TBlob<T>>;
293 if (data_size == 0) {
297 if (data_size != 0 && ptr ==
nullptr) {
301 _allocator = details::make_pre_allocator(ptr, data_size);
335 if (data_size == 0) {
338 if (data_size != 0 && ptr ==
nullptr) {
341 _allocator = details::make_pre_allocator(ptr, data_size);
355 :
Blob(p, l, dims), _allocator(alloc) {
404 return std::move(lockme<T>());
412 return std::move(lockme<const T>());
420 void set(
const std::vector<T> &that) {
427 if (_handle ==
nullptr) {
430 auto memptr = data();
438 if (_handle !=
nullptr) {
456 return std::move(lockme<void>());
464 return std::move(lockme<const void>());
472 details::BlobIterator<T> begin() {
473 return details::BlobIterator<T>(data());
481 details::BlobIterator<T> end() {
482 return details::BlobIterator<T>(data(),
size());
490 details::BlobIterator<const T> begin()
const {
491 return details::BlobIterator<const T>(readOnly());
499 details::BlobIterator<const T> end()
const {
500 return details::BlobIterator<const T>(readOnly(),
size());
508 mutable std::shared_ptr<IAllocator> _allocator;
513 void *_handle =
nullptr;
519 void copyFrom(
const TBlob<T> &blob) {
522 auto memptr = data();
534 this->_allocator = std::move(blob.
_allocator);
535 std::swap(this->_handle, blob.
_handle);
541 virtual bool free() {
542 bool bCanRelease =
true;
543 if (_handle ==
nullptr)
return bCanRelease;
564 const std::shared_ptr<IAllocator> &
getAllocator() const noexcept
override {
576 void *
getHandle() const noexcept
override {
592 return std::make_shared<TBlob<Type>>(p, l,
dims);
617 template<
typename Type,
class TArg>
620 return std::make_shared<InferenceEngine::TBlob<Type>>(p, l, arg);
631 template<
typename Type,
class TArg>
643 template<
typename Type>
646 return std::make_shared<InferenceEngine::TBlob<Type>>(
tensorDesc);
657 template<
typename Type>
660 return std::make_shared<InferenceEngine::TBlob<Type>>(
tensorDesc, ptr,
size);
671 template<
typename TypeTo>
673 return std::make_shared<InferenceEngine::TBlob<TypeTo>>(std::move(arg));
682 template<
typename TypeTo>
684 return std::make_shared<InferenceEngine::TBlob<TypeTo>>(arg);
694 template<
typename TypeTo>
697 return std::make_shared<TBlob<TypeTo>>(p, l);
710 template<
typename TypeTo>
713 auto blob = std::make_shared<TBlob<TypeTo>>(p, l,
dims);
727 template<
typename TypeTo>
730 auto blob = std::make_shared<TBlob<TypeTo>>(p, l);
743 template<
typename TypeTo>
759 template <
typename TypeTo>
762 auto blob = std::make_shared<TBlob<TypeTo>>(p, l,
dims, ptr,
size);
775 template <
typename TypeTo>
#define THROW_IE_EXCEPTION
A macro used to throw the exception with a notable description.
Definition: ie_exception.hpp:22
std::shared_ptr< IAllocator > _allocator
Local instance of IAllocator to manipulate memory.
Definition: ie_blob.h:507
This class represents locked memory for read/write memory.
Definition: ie_locked_memory.hpp:107
const SizeVector dims() const noexcept
Returns the tensor dimensions vector with reversed order.
Definition: ie_blob.h:166
Precision type() const noexcept
Returns the tensor precision of the current Blob object.
Definition: ie_blob.h:49
Layout getLayout() const
Returns the memory layout.
Definition: ie_layouts.h:211
This structure describes ROI data.
Definition: ie_blob.h:784
#define IE_ASSERT(EXPRESSION)
Uses assert() function if NDEBUG is not defined, InferenceEngine exception otherwise.
Definition: ie_exception.hpp:34
std::vector< size_t > SizeVector
Represents tensor size. The order is opposite to the order in Caffe*: (w,h,n,b) where the most freque...
Definition: ie_common.h:26
TensorDesc tensorDesc
The tensor descriptor of the given blob.
Definition: ie_blob.h:227
Definition: ie_argmax_layer.hpp:11
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 deallocate...
Definition: ie_blob.h:128
Layout
Layouts that the inference engine supports.
Definition: ie_common.h:76
void setDims(const SizeVector &dims)
Sets dimensions.
virtual bool deallocate() noexcept=0
Releases previously allocated data. Abstract method.
Blob(Precision p, Layout l, const SizeVector &dims)
The constructor creates an empty Blob object with the specified precision, layout and dimensions...
Definition: ie_blob.h:118
Blob(Precision p, const SizeVector &dims)
The constructor creates an empty Blob object with the specified precision and dimensions.
Definition: ie_blob.h:108
Blob(Precision p)
Constructor. Creates an empty Blob object with the specified precision.
Definition: ie_blob.h:92
static Ptr CreateFromData(const DataPtr &data)
Creates a TBlob<> object from a Data node.
This class is for <void*> data and allows casting to any pointers.
Definition: ie_locked_memory.hpp:204
size_t size() const noexcept
Returns the total number of elements (a product of all the dims)
Definition: ie_blob.h:180
This class is for read-only segments.
Definition: ie_locked_memory.hpp:295
Represents real host memory allocated for a Tensor/Blob per C type.
Definition: ie_blob.h:266
Blob(TensorDesc tensorDesc)
Constructor. Creates an empty Blob object with the specified precision.
Definition: ie_blob.h:85
static size_t product(const SizeVector &dims) noexcept
Multiplies the dimension vector's values.
Definition: ie_blob.h:234
virtual LockedMemory< const T > readOnly() const noexcept
Creates a new empty rvalue read-only LockedMemory object.
Definition: ie_blob.h:410
InferenceEngine::IAllocator * CreateDefaultAllocator() noexcept
Creates the default implementation of the Inference Engine allocator per plugin.
const TensorDesc & getTensorDesc() const noexcept
Returns the tensor description.
Definition: ie_blob.h:173
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 uncha...
Definition: ie_blob.h:149
This class defines Tensor description.
Definition: ie_layouts.h:143
A header file that provides Allocator interface.
std::shared_ptr< const Blob > CPtr
A smart pointer to the const Blob object.
Definition: ie_blob.h:43
std::shared_ptr< TBlob< T >> Ptr
Smart Pointer to this TBlob object.
Definition: ie_blob.h:274
SizeVector & getDims()
Returns the vector of dimensions.
Definition: ie_layouts.h:191
A header file that provides class for describing precision of data.
std::shared_ptr< Blob > Ptr
A smart pointer containing Blob object.
Definition: ie_blob.h:38
virtual ~Blob()=default
Blob virtual destructor.
A header file for data layouts and conversion between them.
TBlob< Type >::Ptr make_shared_blob(Precision p, Layout l, const SizeVector &dims)
Creates a blob with given precision and dimensions.
Definition: ie_blob.h:590
size_t byteSize() const noexcept
Returns the size of the current Blob in bytes.
Definition: ie_blob.h:187
The header file defines utility PreAllocator class.
virtual void allocate() noexcept=0
Allocates memory to store the data. Abstract method.
A header file for generic LockedMemory<> and different variations of locks.
std::map< std::string, Blob::Ptr > BlobMap
This is a convenient type for working with a map containing pairs(string, pointer to a Blob instance)...
Definition: ie_blob.h:259
virtual LockedMemory< const void > cbuffer() const noexcept=0
Gets read-only access to the allocated memory. Abstract method.
This class implements a container object that represents a tensor in memory (host and remote/accelera...
Definition: ie_blob.h:33
virtual size_t element_size() const noexcept=0
Returns the number of bytes per element. The overall Blob capacity is size() * element_size(). Abstract method.
Precision precision() const noexcept
Returns the tensor precision of the current Blob object.
Definition: ie_blob.h:57
void * _handle
A handle for the stored memory returned from _allocator.alloc().
Definition: ie_blob.h:512
virtual LockedMemory< void > buffer() noexcept=0
Gets access to the allocated memory. Abstract method.
virtual const std::shared_ptr< IAllocator > & getAllocator() const noexcept=0
Gets the allocator for allocator-based blobs.
std::shared_ptr< Data > DataPtr
Smart pointer to Data.
Definition: ie_common.h:50
A header file for the BlobIterator class.
Blob(Precision p, Layout l)
The constructor creates an empty Blob object with the specified precision and layout.
Definition: ie_blob.h:100
virtual void * getHandle() const noexcept=0
Gets the handle to allocated memory.
Layout layout() const noexcept
Returns the tensor layout of the current Blob object.
Definition: ie_blob.h:65
const Precision & getPrecision() const
Returns the memory precision.
Definition: ie_layouts.h:257
static Layout getLayoutByDims(SizeVector dims)
Returns the standard layout for dimensions.
This is a header file with common inference engine definitions.
A header file for the main Inference Engine exception.
This class holds precision value and provides precision related operations.
Definition: ie_precision.hpp:19
bool hasStorageType(const char *typeName=nullptr) const noexcept
checks whether given storage class T can be used for store objects of current precision ...
Definition: ie_precision.hpp:84