38 using Ptr = std::shared_ptr<Blob>;
43 using CPtr = std::shared_ptr<const Blob>;
79 virtual ~Blob() =
default;
132 if (
layout != Layout::ANY) {
159 if (
layout != Layout::ANY) {
209 virtual void allocate() noexcept = 0;
245 return std::accumulate(std::begin(
dims), std::end(
dims), (
size_t) 1, std::multiplies<size_t>());
252 virtual const std::shared_ptr<IAllocator> &
getAllocator()
const noexcept = 0;
258 virtual void *
getHandle()
const noexcept = 0;
260 template<
typename>
friend
267 using BlobMap = std::map<std::string, Blob::Ptr>;
273 typename = std::enable_if<std::is_pod<T>::value>>
275 template<
typename,
typename>
friend
283 using Ptr = std::shared_ptr<TBlob<T>>;
301 if (data_size == 0) {
305 if (data_size != 0 && ptr ==
nullptr) {
309 _allocator = details::make_pre_allocator(ptr, data_size);
322 :
Blob(tensorDesc), _allocator(alloc) {
354 if (data_size == 0) {
357 if (data_size != 0 && ptr ==
nullptr) {
360 _allocator = details::make_pre_allocator(ptr, data_size);
374 :
Blob(p, l, dims), _allocator(alloc) {
423 return std::move(lockme<T>());
431 return std::move(lockme<const T>());
439 void set(
const std::vector<T> &that) {
446 if (_handle ==
nullptr) {
449 auto memptr = data();
457 if (_handle !=
nullptr) {
475 return std::move(lockme<void>());
483 return std::move(lockme<const void>());
491 details::BlobIterator<T> begin() {
492 return details::BlobIterator<T>(data());
500 details::BlobIterator<T> end() {
501 return details::BlobIterator<T>(data(),
size());
509 details::BlobIterator<const T> begin()
const {
510 return details::BlobIterator<const T>(readOnly());
518 details::BlobIterator<const T> end()
const {
519 return details::BlobIterator<const T>(readOnly(),
size());
527 mutable std::shared_ptr<IAllocator> _allocator;
532 void *_handle =
nullptr;
538 void copyFrom(
const TBlob<T> &blob) {
541 auto memptr = data();
553 this->_allocator = std::move(blob.
_allocator);
554 std::swap(this->_handle, blob.
_handle);
560 virtual bool free() {
561 bool bCanRelease =
true;
562 if (_handle ==
nullptr)
return bCanRelease;
583 const std::shared_ptr<IAllocator> &
getAllocator() const noexcept
override {
595 void *
getHandle() const noexcept
override {
612 <<
"The blob type cannot be used to store objects of current precision";
613 return std::make_shared<TBlob<Type>>(p, l,
dims);
628 <<
"The blob type cannot be used to store objects of current precision";
640 template<
typename Type,
class TArg>
644 <<
"The blob type cannot be used to store objects of current precision";
645 return std::make_shared<InferenceEngine::TBlob<Type>>(p, l, arg);
656 template<
typename Type,
class TArg>
660 <<
"The blob type cannot be used to store objects of current precision";
670 template<
typename Type>
674 <<
"The blob type cannot be used to store objects of current precision";
675 return std::make_shared<InferenceEngine::TBlob<Type>>(
tensorDesc);
686 template<
typename Type>
690 <<
"The blob type cannot be used to store objects of current precision";
691 return std::make_shared<InferenceEngine::TBlob<Type>>(
tensorDesc, ptr,
size);
701 template<
typename Type>
705 <<
"The blob type cannot be used to store objects of current precision";
706 return std::make_shared<InferenceEngine::TBlob<Type>>(
tensorDesc, alloc);
717 template<
typename TypeTo>
719 return std::make_shared<InferenceEngine::TBlob<TypeTo>>(std::move(arg));
728 template<
typename TypeTo>
730 return std::make_shared<InferenceEngine::TBlob<TypeTo>>(arg);
740 template<
typename TypeTo>
744 <<
"The blob type cannot be used to store objects of current precision";
745 return std::make_shared<TBlob<TypeTo>>(p, l);
758 template<
typename TypeTo>
762 <<
"The blob type cannot be used to store objects of current precision";
763 auto blob = std::make_shared<TBlob<TypeTo>>(p, l,
dims);
777 template<
typename TypeTo>
781 <<
"The blob type cannot be used to store objects of current precision";
782 auto blob = std::make_shared<TBlob<TypeTo>>(p, l);
795 template<
typename TypeTo>
799 <<
"The blob type cannot be used to store objects of current precision";
813 template <
typename TypeTo>
817 <<
"The blob type cannot be used to store objects of current precision";
818 auto blob = std::make_shared<TBlob<TypeTo>>(p, l,
dims, ptr,
size);
831 template <
typename TypeTo>
835 <<
"The blob type cannot be used to store objects of current precision";
#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:85
std::shared_ptr< IAllocator > _allocator
Local instance of IAllocator to manipulate memory.
Definition: ie_blob.h:526
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:174
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:842
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:235
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:188
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:274
static size_t product(const SizeVector &dims) noexcept
Multiplies the dimension vector's values.
Definition: ie_blob.h:242
virtual LockedMemory< const T > readOnly() const noexcept
Creates a new empty rvalue read-only LockedMemory object.
Definition: ie_blob.h:429
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:181
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:153
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:282
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:609
size_t byteSize() const noexcept
Returns the size of the current Blob in bytes.
Definition: ie_blob.h:195
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:267
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:531
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: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:85