23 class LockedMemoryBase {
24 IAllocator* _allocator =
nullptr;
25 void* _handle =
nullptr;
26 mutable T* _locked =
nullptr;
46 LockedMemoryBase(IAllocator* ptr,
void* handle,
LockOp lockFlag,
size_t offsetInBytes)
47 : _allocator(ptr), _handle(
handle), _lockFlag(lockFlag), _offset(offsetInBytes) {}
54 LockedMemoryBase(LockedMemoryBase&& that) noexcept
55 : _allocator(that._allocator), _handle(that._handle), _lockFlag(that._lockFlag), _offset(that._offset) {
56 that._locked =
nullptr;
62 virtual ~LockedMemoryBase() {
63 if (_locked !=
nullptr) {
64 _allocator->unlock(_handle);
75 bool isEqualTo(
const T* pointer)
const {
76 if (pointer ==
nullptr && (_allocator ==
nullptr || _handle ==
nullptr)) {
79 return dereference() == pointer;
89 virtual T* dereference()
const {
90 if (_locked !=
nullptr)
return _locked;
92 if (_allocator ==
nullptr) {
96 if (_handle ==
nullptr) {
100 uint8_t* pBytes =
reinterpret_cast<uint8_t*
>(_allocator->lock(_handle, _lockFlag));
102 return _locked =
reinterpret_cast<T*
>(pBytes + _offset);
112 using base = details::LockedMemoryBase<T>;
139 base::_offset = offset;
155 return base::dereference();
164 operator const T*()
const {
165 return base::dereference();
175 return base::isEqualTo(pointer);
185 return lm.operator==(pointer);
196 template <class S, typename = std::enable_if<std::is_pointer<S>::value>>
198 return reinterpret_cast<S
>(base::dereference());
209 template <class S, typename = std::enable_if<std::is_pointer<S>::value>>
211 return reinterpret_cast<S
>(base::dereference());
220 using base = details::LockedMemoryBase<void>;
247 base::_offset = offset;
265 return reinterpret_cast<S*
>(base::dereference());
275 return base::isEqualTo(pointer);
285 return lm.operator==(pointer);
296 template <class S, typename = std::enable_if<std::is_pointer<S>::value>>
298 return reinterpret_cast<S
>(dereference());
309 template <class S, typename = std::enable_if<std::is_pointer<S>::value>>
311 return reinterpret_cast<S
>(dereference());
320 using base = details::LockedMemoryBase<T>;
346 base::_offset = offset;
361 operator const T*()
const {
362 return base::dereference();
372 return base::isEqualTo(pointer);
382 return lm.operator==(pointer);
393 template <class S, typename = std::enable_if<std::is_pointer<S>::value && std::is_const<S>::value>>
395 return reinterpret_cast<S
>(base::dereference());
Allocator concept to be used for memory management and is used as part of the Blob.
Definition: ie_allocator.hpp:29
This class is for read-only segments.
Definition: ie_locked_memory.hpp:319
friend bool operator==(const T *pointer, const LockedMemory< const T > &lm)
Compares the object with the one stored in the memory.
Definition: ie_locked_memory.hpp:381
bool operator==(const T *pointer) const
Compares stored object with the given one.
Definition: ie_locked_memory.hpp:370
LockedMemory(IAllocator *ptr, void *handle, size_t offset)
A constructor.
Definition: ie_locked_memory.hpp:330
LockedMemory(const LockedMemory< const T > &)=delete
A disabled copy constructor for lvalue.
LockedMemory(LockedMemory< const T > &&that, size_t offset)
A default copy constructor that accepts rvalue.
Definition: ie_locked_memory.hpp:345
S as() const
Casts stored object to any given type.
Definition: ie_locked_memory.hpp:394
LockedMemory(LockedMemory< const T > &&)=default
A default copy constructor that accepts rvalue.
This class is for <void*> data and allows casting to any pointers.
Definition: ie_locked_memory.hpp:219
const S as() const
Casts stored object to any given type.
Definition: ie_locked_memory.hpp:310
bool operator==(const void *pointer) const
Compares stored object with the given one.
Definition: ie_locked_memory.hpp:273
LockedMemory(IAllocator *ptr, void *handle, size_t offsetInBytes)
A constructor.
Definition: ie_locked_memory.hpp:230
friend bool operator==(const void *pointer, const LockedMemory< void > &lm)
Compares the object with the one stored in the memory.
Definition: ie_locked_memory.hpp:284
LockedMemory(LockedMemory< void > &&)=default
A default copy constructor that accepts rvalue.
LockedMemory(const LockedMemory< void > &)=delete
A disabled copy constructor for lvalue.
S as()
Casts stored object to any given type.
Definition: ie_locked_memory.hpp:297
LockedMemory(LockedMemory< void > &&that, size_t offset)
A default copy constructor that accepts rvalue.
Definition: ie_locked_memory.hpp:246
This class represents locked memory for read/write memory.
Definition: ie_locked_memory.hpp:111
S as()
Casts stored object to any provided type.
Definition: ie_locked_memory.hpp:197
bool operator==(const T *pointer) const
Compares stored object with the given one.
Definition: ie_locked_memory.hpp:173
LockedMemory(const LockedMemory< T > &)=delete
A disabled copy constructor for lvalue.
friend bool operator==(const T *pointer, const LockedMemory< T > &lm)
Compares the object with the one stored in the memory.
Definition: ie_locked_memory.hpp:184
const S as() const
Casts stored object to any provided type.
Definition: ie_locked_memory.hpp:210
LockedMemory(LockedMemory< T > &&that, size_t offset)
A default copy constructor that accepts rvalue.
Definition: ie_locked_memory.hpp:138
LockedMemory(LockedMemory< T > &&)=default
A default copy constructor, accepting rvalue.
LockedMemory(IAllocator *ptr, void *handle, size_t offsetInBytes=0)
A constructor.
Definition: ie_locked_memory.hpp:122
A header file that provides Allocator interface.
handle_t handle(char const *name)
Create annotation handle with a given name.
Definition: itt.hpp:77
Inference Engine C++ API.
Definition: cldnn_config.hpp:15
LockOp
Allocator handle mapping type.
Definition: ie_allocator.hpp:20
@ LOCK_FOR_READ
A flag to lock data for read.
Definition: ie_allocator.hpp:21
@ LOCK_FOR_WRITE
A flag to lock data for write.
Definition: ie_allocator.hpp:22