19 #include <type_traits>
40 using Ptr = std::shared_ptr<Blob>;
45 using CPtr = std::shared_ptr<const Blob>;
51 INFERENCE_ENGINE_DEPRECATED
60 INFERENCE_ENGINE_DEPRECATED
69 INFERENCE_ENGINE_DEPRECATED
84 virtual ~Blob() =
default;
92 typename std::enable_if<
93 !std::is_pointer<T>::value && !std::is_reference<T>::value,
int>
::type = 0,
94 typename std::enable_if<std::is_base_of<Blob, T>::value,
int>::type = 0>
96 return dynamic_cast<T*
>(
this) !=
nullptr;
105 typename std::enable_if<
106 !std::is_pointer<T>::value && !std::is_reference<T>::value,
int>::type = 0,
107 typename std::enable_if<std::is_base_of<Blob, T>::value,
int>::type = 0>
108 bool is() const noexcept {
109 return dynamic_cast<const T*
>(
this) !=
nullptr;
119 typename std::enable_if<
120 !std::is_pointer<T>::value && !std::is_reference<T>::value,
int>::type = 0,
121 typename std::enable_if<std::is_base_of<Blob, T>::value,
int>::type = 0>
123 return dynamic_cast<T*
>(
this);
133 typename std::enable_if<
134 !std::is_pointer<T>::value && !std::is_reference<T>::value,
int>::type = 0,
135 typename std::enable_if<std::is_base_of<Blob, T>::value,
int>::type = 0>
136 const T*
as() const noexcept {
137 return dynamic_cast<const T*
>(
this);
151 INFERENCE_ENGINE_DEPRECATED
160 INFERENCE_ENGINE_DEPRECATED
169 INFERENCE_ENGINE_DEPRECATED
180 INFERENCE_ENGINE_DEPRECATED
191 INFERENCE_ENGINE_DEPRECATED
196 if (
layout != Layout::ANY) {
217 INFERENCE_ENGINE_DEPRECATED
224 if (
layout != Layout::ANY) {
239 INFERENCE_ENGINE_DEPRECATED
263 virtual size_t size() const noexcept {
286 virtual void allocate() noexcept = 0;
322 return std::accumulate(std::begin(
dims), std::end(
dims), (
size_t) 1, std::multiplies<size_t>());
329 virtual const std::shared_ptr<IAllocator> &
getAllocator()
const noexcept = 0;
335 virtual void *
getHandle()
const noexcept = 0;
337 template<
typename>
friend
347 typename std::enable_if<
348 !std::is_pointer<T>::value && !std::is_reference<T>::value,
int>
::type = 0,
349 typename std::enable_if<std::is_base_of<Blob, T>::value,
int>::type = 0>
351 return std::dynamic_pointer_cast<T>(blob);
360 typename std::enable_if<
361 !std::is_pointer<T>::value && !std::is_reference<T>::value,
int>::type = 0,
362 typename std::enable_if<std::is_base_of<Blob, T>::value,
int>::type = 0>
364 return std::dynamic_pointer_cast<
const T>(blob);
378 using Ptr = std::shared_ptr<MemoryBlob>;
383 using CPtr = std::shared_ptr<const MemoryBlob>;
413 size_t size() const noexcept
override {
436 void allocate() noexcept
override = 0;
463 const std::shared_ptr<IAllocator> &
getAllocator()
const noexcept
override = 0;
469 void *
getHandle()
const noexcept
override = 0;
471 template<
typename>
friend
478 using BlobMap = std::map<std::string, Blob::Ptr>;
484 typename = std::enable_if<std::is_pod<T>::value>>
486 template<
typename,
typename>
friend
494 using Ptr = std::shared_ptr<TBlob<T>>;
512 if (data_size == 0) {
516 if (data_size != 0 && ptr ==
nullptr) {
520 _allocator = details::make_pre_allocator(ptr, data_size);
543 INFERENCE_ENGINE_DEPRECATED
553 INFERENCE_ENGINE_DEPRECATED
570 INFERENCE_ENGINE_DEPRECATED
573 if (data_size == 0) {
576 if (data_size != 0 && ptr ==
nullptr) {
579 _allocator = details::make_pre_allocator(ptr, data_size);
592 INFERENCE_ENGINE_DEPRECATED
643 return std::move(lockme<T>());
651 return std::move(lockme<const T>());
659 INFERENCE_ENGINE_DEPRECATED
660 void set(
const std::vector<T> &that) {
667 if (_handle ==
nullptr) {
670 auto memptr = data();
671 memcpy(memptr, that.data(),
byteSize());
678 if (_handle !=
nullptr) {
696 return std::move(lockme<void>());
704 return std::move(lockme<const void>());
712 details::BlobIterator<T> begin() {
713 return details::BlobIterator<T>(data());
721 details::BlobIterator<T> end() {
722 return details::BlobIterator<T>(data(),
size());
730 details::BlobIterator<const T> begin()
const {
731 return details::BlobIterator<const T>(readOnly());
739 details::BlobIterator<const T> end()
const {
740 return details::BlobIterator<const T>(readOnly(),
size());
748 mutable std::shared_ptr<IAllocator> _allocator;
753 void *_handle =
nullptr;
759 void copyFrom(
const TBlob<T> &blob) {
762 auto memptr = data();
774 this->_allocator = std::move(blob.
_allocator);
775 std::swap(this->_handle, blob.
_handle);
781 virtual bool free() {
782 bool bCanRelease =
true;
783 if (_handle ==
nullptr)
return bCanRelease;
804 const std::shared_ptr<IAllocator> &
getAllocator() const noexcept
override {
816 void *
getHandle() const noexcept
override {
830 INFERENCE_ENGINE_DEPRECATED
834 <<
"The blob type cannot be used to store objects of current precision";
847 INFERENCE_ENGINE_DEPRECATED
851 <<
"The blob type cannot be used to store objects of current precision";
863 template<
typename Type,
class TArg>
864 INFERENCE_ENGINE_DEPRECATED
868 <<
"The blob type cannot be used to store objects of current precision";
869 return std::make_shared<InferenceEngine::TBlob<Type>>(
TensorDesc(p,
SizeVector(arg.rbegin(), arg.rend()), l));
880 template<
typename Type,
class TArg>
881 INFERENCE_ENGINE_DEPRECATED
885 <<
"The blob type cannot be used to store objects of current precision";
895 template<
typename Type>
899 <<
"The blob type cannot be used to store objects of current precision";
900 return std::make_shared<InferenceEngine::TBlob<Type>>(
tensorDesc);
911 template<
typename Type>
915 <<
"The blob type cannot be used to store objects of current precision";
916 return std::make_shared<InferenceEngine::TBlob<Type>>(
tensorDesc, ptr,
size);
926 template<
typename Type>
930 <<
"The blob type cannot be used to store objects of current precision";
931 return std::make_shared<InferenceEngine::TBlob<Type>>(
tensorDesc, alloc);
942 template<
typename TypeTo>
943 INFERENCE_ENGINE_DEPRECATED
945 return std::make_shared<InferenceEngine::TBlob<TypeTo>>(std::move(arg));
954 template<
typename TypeTo>
956 return std::make_shared<InferenceEngine::TBlob<TypeTo>>(arg);
966 template<
typename TypeTo>
967 INFERENCE_ENGINE_DEPRECATED
971 <<
"The blob type cannot be used to store objects of current precision";
972 return std::make_shared<TBlob<TypeTo>>(
TensorDesc(p, l));
985 template<
typename TypeTo>
986 INFERENCE_ENGINE_DEPRECATED
990 <<
"The blob type cannot be used to store objects of current precision";
991 auto blob = std::make_shared<TBlob<TypeTo>>(
TensorDesc(p,
SizeVector(dims.rbegin(), dims.rend()), l));
1005 template<
typename TypeTo>
1006 INFERENCE_ENGINE_DEPRECATED
1010 <<
"The blob type cannot be used to store objects of current precision";
1011 auto blob = std::make_shared<TBlob<TypeTo>>(
TensorDesc(p, l));
1024 template<
typename TypeTo>
1025 INFERENCE_ENGINE_DEPRECATED
1029 <<
"The blob type cannot be used to store objects of current precision";
1043 template <
typename TypeTo>
1044 INFERENCE_ENGINE_DEPRECATED
1048 <<
"The blob type cannot be used to store objects of current precision";
1062 template <
typename TypeTo>
1063 INFERENCE_ENGINE_DEPRECATED
1067 <<
"The blob type cannot be used to store objects of current precision";
1076 template<
typename T,
typename ...Args,
1077 typename std::enable_if<std::is_base_of<Blob, T>::value,
int>::type = 0>
1079 return std::make_shared<T>(std::forward<Args>(args)...);
#define THROW_IE_EXCEPTION
A macro used to throw the exception with a notable description.
Definition: ie_exception.hpp:22
Blob(const TensorDesc &tensorDesc)
Constructor. Creates an empty Blob object with the specified precision.
Definition: ie_blob.h:144
std::shared_ptr< IAllocator > _allocator
Local instance of IAllocator to manipulate memory.
Definition: ie_blob.h:747
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:240
Precision type() const noexcept
Returns the tensor precision of the current Blob object.
Definition: ie_blob.h:52
virtual size_t size() const noexcept
By default, returns the total number of elements (a product of all the dims or 1 for scalar) ...
Definition: ie_blob.h:263
Layout getLayout() const
Returns the memory layout.
Definition: ie_layouts.h:211
This structure describes ROI data.
Definition: ie_blob.h:1085
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:312
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:192
Layout
Layouts that the inference engine supports.
Definition: ie_common.h:76
void setDims(const SizeVector &dims)
Sets dimensions.
MemoryBlob(const TensorDesc &tensorDesc)
Constructor. Creates an empty MemoryBlob object with the specified precision.
Definition: ie_blob.h:394
virtual bool deallocate() noexcept=0
Releases previously allocated data. Abstract method.
T * as() noexcept
Casts this Blob object to the type T*. Use InferenceEngine::as() to operate with shared Blob objects ...
Definition: ie_blob.h:122
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:181
Blob(Precision p, const SizeVector &dims)
The constructor creates an empty Blob object with the specified precision and dimensions.
Definition: ie_blob.h:170
Blob(Precision p)
Constructor. Creates an empty Blob object with the specified precision.
Definition: ie_blob.h:152
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
const T * as() const noexcept
Casts this Blob object to the type const T*. Use InferenceEngine::as() to operate with shared Blob ob...
Definition: ie_blob.h:136
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:485
virtual TensorDesc & getTensorDesc() noexcept
Returns the tensor description.
Definition: ie_blob.h:254
static size_t product(const SizeVector &dims) noexcept
Multiplies the dimension vector's values.
Definition: ie_blob.h:319
virtual LockedMemory< const T > readOnly() const noexcept
Creates a new empty rvalue read-only LockedMemory object.
Definition: ie_blob.h:649
InferenceEngine::IAllocator * CreateDefaultAllocator() noexcept
Creates the default implementation of the Inference Engine allocator per plugin.
size_t size() const noexcept override
Returns the total number of elements, which is a product of all the dimensions.
Definition: ie_blob.h:413
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:218
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:45
std::shared_ptr< TBlob< T >> Ptr
Smart Pointer to this TBlob object.
Definition: ie_blob.h:493
SizeVector & getDims()
Returns the vector of dimensions.
Definition: ie_layouts.h:191
A header file that provides class for describing precision of data.
size_t byteSize() const noexcept override
Returns the size of the current Blob in bytes.
Definition: ie_blob.h:422
std::shared_ptr< Blob > Ptr
A smart pointer containing Blob object.
Definition: ie_blob.h:40
virtual ~Blob()=default
Blob virtual destructor.
A header file for data layouts and conversion between them.
This class implements a container object that represents a tensor in memory (host and remote/accelera...
Definition: ie_blob.h:373
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:831
TensorDesc & getTensorDesc() noexcept override
Returns the tensor description.
Definition: ie_blob.h:406
const TensorDesc & getTensorDesc() const noexcept override
Returns the tensor description.
Definition: ie_blob.h:399
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:478
virtual LockedMemory< const void > cbuffer() const noexcept=0
Gets read-only access to the allocated memory. Abstract method.
This class represents a universal container in the Inference Engine.
Definition: ie_blob.h:35
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.
bool is() noexcept
Checks if the Blob object can be cast to the type T*.
Definition: ie_blob.h:95
Precision precision() const noexcept
Returns the tensor precision of the current Blob object.
Definition: ie_blob.h:61
virtual const TensorDesc & getTensorDesc() const noexcept
Returns the tensor description.
Definition: ie_blob.h:247
void * _handle
A handle for the stored memory returned from _allocator.alloc().
Definition: ie_blob.h:752
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 an 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:161
virtual size_t byteSize() const noexcept
Returns the size of the current Blob in bytes.
Definition: ie_blob.h:272
virtual void * getHandle() const noexcept=0
Gets a handle to allocated memory.
bool is() const noexcept
Checks if the Blob object can be cast to the type const T*.
Definition: ie_blob.h:108
Layout layout() const noexcept
Returns the tensor layout of the current Blob object.
Definition: ie_blob.h:70
const Precision & getPrecision() const
Returns the memory precision.
Definition: ie_layouts.h:260
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 to store objects of current precision ...
Definition: ie_precision.hpp:87