ie_allocator.hpp
Go to the documentation of this file.
1 // Copyright (C) 2018-2020 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 /**
6  * @brief A header file that provides Allocator interface
7  *
8  * @file ie_allocator.hpp
9  */
10 #pragma once
11 
12 #include "ie_api.h"
13 #include "details/ie_irelease.hpp"
14 
15 namespace InferenceEngine {
16 
17 /**
18  * @brief Allocator handle mapping type
19  */
20 enum LockOp {
21  LOCK_FOR_READ = 0, //!< A flag to lock data for read
22  LOCK_FOR_WRITE //!< A flag to lock data for write
23 };
24 
25 /**
26  * @interface IAllocator
27  * @brief Allocator concept to be used for memory management and is used as part of the Blob.
28  */
29 class IAllocator : public details::IRelease {
30 public:
31  /**
32  * @brief Maps handle to heap memory accessible by any memory manipulation routines.
33  *
34  * @param handle Handle to the allocated memory to be locked
35  * @param op Operation to lock memory for
36  * @return Generic pointer to memory
37  */
38  virtual void* lock(void* handle, LockOp op = LOCK_FOR_WRITE) noexcept = 0;
39  /**
40  * @brief Unmaps memory by handle with multiple sequential mappings of the same handle.
41  *
42  * The multiple sequential mappings of the same handle are suppose to get the same
43  * result while there isn't a ref counter supported.
44  *
45  * @param handle Handle to the locked memory to unlock
46  */
47  virtual void unlock(void* handle) noexcept = 0;
48  /**
49  * @brief Allocates memory
50  *
51  * @param size The size in bytes to allocate
52  * @return Handle to the allocated resource
53  */
54  virtual void* alloc(size_t size) noexcept = 0;
55  /**
56  * @brief Releases the handle and all associated memory resources which invalidates the handle.
57  * @param handle The handle to free
58  * @return `false` if handle cannot be released, otherwise - `true`.
59  */
60  virtual bool free(void* handle) noexcept = 0;
61 
62 protected:
63  /**
64  * @brief Disables the ability of deleting the object without release.
65  */
66  ~IAllocator() override = default;
67 };
68 
69 /**
70  * @brief Creates the default implementation of the Inference Engine allocator per plugin.
71  *
72  * @return The Inference Engine IAllocator* instance
73  */
74 INFERENCE_ENGINE_API(InferenceEngine::IAllocator*) CreateDefaultAllocator() noexcept;
75 
76 } // namespace InferenceEngine
Allocator concept to be used for memory management and is used as part of the Blob.
Definition: ie_allocator.hpp:29
~IAllocator() override=default
Disables the ability of deleting the object without release.
virtual void * lock(void *handle, LockOp op=LOCK_FOR_WRITE) noexcept=0
Maps handle to heap memory accessible by any memory manipulation routines.
virtual bool free(void *handle) noexcept=0
Releases the handle and all associated memory resources which invalidates the handle.
virtual void * alloc(size_t size) noexcept=0
Allocates memory.
virtual void unlock(void *handle) noexcept=0
Unmaps memory by handle with multiple sequential mappings of the same handle.
InferenceEngine::IAllocator * CreateDefaultAllocator() noexcept
Creates the default implementation of the Inference Engine allocator per plugin.
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
The macro defines a symbol import/export mechanism essential for Microsoft Windows(R) OS.
A header file for the Inference Engine plugins destruction mechanism.