22 class LockedMemoryBase {
23 IAllocator* _allocator =
nullptr;
24 void* _handle =
nullptr;
25 mutable T* _locked =
nullptr;
26 LockOp _lockFlag = LOCK_FOR_WRITE;
43 LockedMemoryBase(IAllocator* ptr,
void* handle,
LockOp lockFlag,
size_t offsetInBytes)
44 : _allocator(ptr), _handle(handle), _lockFlag(lockFlag), _offset(offsetInBytes) {}
50 LockedMemoryBase(LockedMemoryBase&& that)
51 : _allocator(that._allocator), _handle(that._handle), _lockFlag(that._lockFlag), _offset(that._offset) {
52 that._locked =
nullptr;
58 virtual ~LockedMemoryBase() {
59 if (_locked !=
nullptr) {
60 _allocator->unlock(_handle);
70 bool isEqualTo(
const T* pointer)
const {
71 if (pointer ==
nullptr && (_allocator ==
nullptr || _handle ==
nullptr)) {
74 return dereference() == pointer;
82 virtual T* dereference()
const {
83 if (_locked !=
nullptr)
return _locked;
85 if (_allocator ==
nullptr) {
89 if (_handle ==
nullptr) {
93 uint8_t* pBytes =
reinterpret_cast<uint8_t*
>(_allocator->lock(_handle, _lockFlag));
95 return _locked =
reinterpret_cast<T*
>(pBytes + _offset);
105 using base = details::LockedMemoryBase<T>;
115 : base(ptr, handle, LOCK_FOR_WRITE, offsetInBytes) {}
129 base::_offset = offset;
143 return base::dereference();
151 operator const T*()
const {
152 return base::dereference();
161 return base::isEqualTo(pointer);
169 return lm.operator==(pointer);
178 template <class S, typename = std::enable_if<std::is_pointer<S>::value>>
180 return reinterpret_cast<S
>(base::dereference());
189 template <class S, typename = std::enable_if<std::is_pointer<S>::value>>
191 return reinterpret_cast<S
>(base::dereference());
200 using base = details::LockedMemoryBase<void>;
210 : base(ptr, handle, LOCK_FOR_WRITE, offsetInBytes) {}
224 base::_offset = offset;
240 return reinterpret_cast<S*
>(base::dereference());
249 return base::isEqualTo(pointer);
257 return lm.operator==(pointer);
266 template <class S, typename = std::enable_if<std::is_pointer<S>::value>>
268 return reinterpret_cast<S
>(dereference());
277 template <class S, typename = std::enable_if<std::is_pointer<S>::value>>
279 return reinterpret_cast<S
>(dereference());
288 using base = details::LockedMemoryBase<T>;
311 base::_offset = offset;
324 operator const T*()
const {
325 return base::dereference();
334 return base::isEqualTo(pointer);
342 return lm.operator==(pointer);
351 template <class S, typename = std::enable_if<std::is_pointer<S>::value && std::is_const<S>::value>>
353 return reinterpret_cast<S
>(base::dereference());
LockedMemory(IAllocator *ptr, void *handle, size_t offsetInBytes=0)
A constructor.
Definition: ie_locked_memory.hpp:114
This class represents locked memory for read/write memory.
Definition: ie_locked_memory.hpp:104
LockOp
Allocator handle mapping type.
Definition: ie_allocator.hpp:20
Inference Engine API.
Definition: ie_argmax_layer.hpp:11
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:341
bool operator==(const T *pointer) const
Compares stored object with the given one.
Definition: ie_locked_memory.hpp:332
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:168
bool operator==(const void *pointer) const
Compares stored object with the given one.
Definition: ie_locked_memory.hpp:247
S as()
Casts stored object to any provided type. Uses reinterpret_cast.
Definition: ie_locked_memory.hpp:179
LockedMemory(LockedMemory< void > &&that, size_t offset)
A default copy constructor that accepts rvalue Also sets the offset value for the new memory object...
Definition: ie_locked_memory.hpp:223
This class is for <void*> data and allows casting to any pointers.
Definition: ie_locked_memory.hpp:199
S as() const
Casts stored object to any given type. Uses reinterpret_cast.
Definition: ie_locked_memory.hpp:352
This class is for read-only segments.
Definition: ie_locked_memory.hpp:287
LockedMemory(IAllocator *ptr, void *handle, size_t offset)
A constructor.
Definition: ie_locked_memory.hpp:297
const S as() const
Casts stored object to any given type. Uses reinterpret_cast.
Definition: ie_locked_memory.hpp:278
A header file that provides Allocator interface.
S as()
Casts stored object to any given type. Uses reinterpret_cast.
Definition: ie_locked_memory.hpp:267
LockedMemory(IAllocator *ptr, void *handle, size_t offsetInBytes)
A constructor.
Definition: ie_locked_memory.hpp:209
bool operator==(const T *pointer) const
Compares stored object with the given one.
Definition: ie_locked_memory.hpp:159
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:256
Allocator concept to be used for memory management and is used as part of the Blob.
Definition: ie_allocator.hpp:25
LockedMemory(LockedMemory< T > &&that, size_t offset)
A default copy constructor that accepts rvalue Also sets the offset value for the new memory object...
Definition: ie_locked_memory.hpp:128
const S as() const
Casts stored object to any provided type. Uses reinterpret_cast.
Definition: ie_locked_memory.hpp:190
LockedMemory(LockedMemory< const T > &&that, size_t offset)
A default copy constructor that accepts rvalue. Also sets the offset value for the new memory object...
Definition: ie_locked_memory.hpp:310