forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathie_allocator.hpp
More file actions
74 lines (65 loc) · 2.15 KB
/
ie_allocator.hpp
File metadata and controls
74 lines (65 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
/**
* @brief A header file that provides Allocator interface
*
* @file ie_allocator.hpp
*/
#pragma once
#include <memory>
#include "ie_api.h"
namespace InferenceEngine {
/**
* @brief Allocator handle mapping type
*/
enum LockOp {
LOCK_FOR_READ = 0, //!< A flag to lock data for read
LOCK_FOR_WRITE //!< A flag to lock data for write
};
/**
* @interface IAllocator
* @brief Allocator concept to be used for memory management and is used as part of the Blob.
*/
class IAllocator : public std::enable_shared_from_this<IAllocator> {
public:
/**
* @brief Maps handle to heap memory accessible by any memory manipulation routines.
*
* @param handle Handle to the allocated memory to be locked
* @param op Operation to lock memory for
* @return Generic pointer to memory
*/
virtual void* lock(void* handle, LockOp op = LOCK_FOR_WRITE) noexcept = 0;
/**
* @brief Unmaps memory by handle with multiple sequential mappings of the same handle.
*
* The multiple sequential mappings of the same handle are suppose to get the same
* result while there isn't a ref counter supported.
*
* @param handle Handle to the locked memory to unlock
*/
virtual void unlock(void* handle) noexcept = 0;
/**
* @brief Allocates memory
*
* @param size The size in bytes to allocate
* @return Handle to the allocated resource
*/
virtual void* alloc(size_t size) noexcept = 0;
/**
* @brief Releases the handle and all associated memory resources which invalidates the handle.
* @param handle The handle to free
* @return `false` if handle cannot be released, otherwise - `true`.
*/
virtual bool free(void* handle) noexcept = 0;
protected:
virtual ~IAllocator() = default;
};
/**
* @brief Creates the default implementation of the Inference Engine allocator per plugin.
*
* @return The Inference Engine IAllocator* instance
*/
INFERENCE_ENGINE_API_CPP(std::shared_ptr<InferenceEngine::IAllocator>) CreateDefaultAllocator() noexcept;
} // namespace InferenceEngine