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