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 <ie_api.h>
12 
13 #include <details/ie_irelease.hpp>
14 
15 namespace InferenceEngine {
16 
17 /**
18  * @brief Allocator handle mapping type
19  */
20 enum LockOp { LOCK_FOR_READ = 0, LOCK_FOR_WRITE };
21 
22 /**
23  * @brief Allocator concept to be used for memory management and is used as part of the Blob.
24  */
25 class IAllocator : public details::IRelease {
26 public:
27  /**
28  * @brief Maps handle to heap memory accessible by any memory manipulation routines.
29  * @param handle Handle to the allocated memory to be locked
30  * @param LockOp Operation to lock memory for
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  * @param handle Handle to the locked memory to unlock
39  */
40  virtual void unlock(void* handle) noexcept = 0;
41  /**
42  * @brief Allocates memory
43  * @param size The size in bytes to allocate
44  * @return Handle to the allocated resource
45  */
46  virtual void* alloc(size_t size) noexcept = 0;
47  /**
48  * @brief Releases handle and all associated memory resources which invalidates the handle.
49  * @return false if handle cannot be released, otherwise - true.
50  */
51  virtual bool free(void* handle) noexcept = 0;
52 
53 protected:
54  /**
55  * @brief Disables the ability of deleting the object without release.
56  */
57  ~IAllocator() override = default;
58 };
59 
60 /**
61  * @brief Creates the default implementation of the Inference Engine allocator per plugin.
62  * @return The Inference Engine IAllocator* instance
63  */
64 INFERENCE_ENGINE_API(InferenceEngine::IAllocator*) CreateDefaultAllocator() noexcept;
65 
66 } // namespace InferenceEngine
LockOp
Allocator handle mapping type.
Definition: ie_allocator.hpp:20
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:25
virtual void * lock(void *handle, LockOp=LOCK_FOR_WRITE) noexcept=0
Maps handle to heap memory accessible by any memory manipulation routines.