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