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  * @return Generic pointer to memory
32  */
33  virtual void * lock(void * handle, LockOp = LOCK_FOR_WRITE) noexcept = 0;
34  /**
35  * @brief Unmaps memory by handle with multiple sequential mappings of the same handle.
36  * The multiple sequential mappings of the same handle are suppose to get the same
37  * result while there isn't a ref counter supported.
38  */
39  virtual void unlock(void * handle) noexcept = 0;
40  /**
41  * @brief Allocates memory
42  * @param size The size in bytes to allocate
43  * @return Handle to the allocated resource
44  */
45  virtual void * alloc(size_t size) noexcept = 0;
46  /**
47  * @brief Releases handle and all associated memory resources which invalidates the handle.
48  * @return false if handle cannot be released, otherwise - true.
49  */
50  virtual bool free(void* handle) noexcept = 0;
51 
52  protected:
53  /**
54  * @brief Disables the ability of deleting the object without release.
55  */
56  ~IAllocator()override = default;
57 };
58 
59 /**
60  * @brief Creates the default implementation of the Inference Engine allocator per plugin.
61  * @return The Inference Engine IAllocator* instance
62  */
63 INFERENCE_ENGINE_API(InferenceEngine::IAllocator*)CreateDefaultAllocator() noexcept;
64 
65 } // namespace InferenceEngine
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.
LockOp
Allocator handle mapping type.
Definition: ie_allocator.hpp:19
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.