1 // Copyright (C) 2018-2020 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
6 * @brief A header file that provides Allocator interface
8 * @file ie_allocator.hpp
14 #include <details/ie_irelease.hpp>
16 namespace InferenceEngine {
19 * @brief Allocator handle mapping type
21 enum LockOp { LOCK_FOR_READ = 0, LOCK_FOR_WRITE };
24 * @brief Allocator concept to be used for memory management and is used as part of the Blob.
26 class IAllocator : public details::IRelease {
29 * @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
35 virtual void* lock(void* handle, LockOp = LOCK_FOR_WRITE) noexcept = 0;
37 * @brief Unmaps memory by handle with multiple sequential mappings of the same handle.
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.
42 * @param handle Handle to the locked memory to unlock
44 virtual void unlock(void* handle) noexcept = 0;
46 * @brief Allocates memory
48 * @param size The size in bytes to allocate
49 * @return Handle to the allocated resource
51 virtual void* alloc(size_t size) noexcept = 0;
53 * @brief Releases handle and all associated memory resources which invalidates the handle.
55 * @return false if handle cannot be released, otherwise - true.
57 virtual bool free(void* handle) noexcept = 0;
61 * @brief Disables the ability of deleting the object without release.
63 ~IAllocator() override = default;
67 * @brief Creates the default implementation of the Inference Engine allocator per plugin.
69 * @return The Inference Engine IAllocator* instance
71 INFERENCE_ENGINE_API(InferenceEngine::IAllocator*) CreateDefaultAllocator() noexcept;
73 } // namespace InferenceEngine