Publishing 2020.1 content
[platform/upstream/dldt.git] / inference-engine / include / ie_allocator.hpp
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 { LOCK_FOR_READ = 0, LOCK_FOR_WRITE };
22
23 /**
24  * @brief Allocator concept to be used for memory management and is used as part of the Blob.
25  */
26 class IAllocator : public details::IRelease {
27 public:
28     /**
29      * @brief Maps handle to heap memory accessible by any memory manipulation routines.
30      *
31      * @param handle Handle to the allocated memory to be locked
32      * @param LockOp Operation to lock memory for
33      * @return Generic pointer to memory
34      */
35     virtual void* lock(void* handle, LockOp = LOCK_FOR_WRITE) noexcept = 0;
36     /**
37      * @brief Unmaps memory by handle with multiple sequential mappings of the same handle.
38      *
39      * The multiple sequential mappings of the same handle are suppose to get the same
40      * result while there isn't a ref counter supported.
41      *
42      * @param handle Handle to the locked memory to unlock
43      */
44     virtual void unlock(void* handle) noexcept = 0;
45     /**
46      * @brief Allocates memory
47      *
48      * @param size The size in bytes to allocate
49      * @return Handle to the allocated resource
50      */
51     virtual void* alloc(size_t size) noexcept = 0;
52     /**
53      * @brief Releases handle and all associated memory resources which invalidates the handle.
54      *
55      * @return false if handle cannot be released, otherwise - true.
56      */
57     virtual bool free(void* handle) noexcept = 0;
58
59 protected:
60     /**
61      * @brief Disables the ability of deleting the object without release.
62      */
63     ~IAllocator() override = default;
64 };
65
66 /**
67  * @brief Creates the default implementation of the Inference Engine allocator per plugin.
68  *
69  * @return The Inference Engine IAllocator* instance
70  */
71 INFERENCE_ENGINE_API(InferenceEngine::IAllocator*) CreateDefaultAllocator() noexcept;
72
73 }  // namespace InferenceEngine