ArmNN
 25.11
Loading...
Searching...
No Matches
ICustomAllocator.hpp
Go to the documentation of this file.
1//
2// Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#pragma once
7
8#include <cstddef>
9#include <memory>
12
13namespace armnn
14{
15/** Custom Allocator interface */
17{
18public:
19 /** Default virtual destructor. */
20 virtual ~ICustomAllocator() = default;
21
22 /** Interface to be implemented by the child class to allocate bytes
23 *
24 * @param[in] size Size to allocate
25 * @param[in] alignment Alignment that the returned pointer should comply with
26 *
27 * @return A pointer to the allocated memory
28 * The returned pointer must be host write accessible
29 */
30 virtual void* allocate(size_t size, size_t alignment) = 0;
31
32 /** Interface to be implemented by the child class to free the allocated bytes */
33 virtual void free(void* ptr) = 0;
34
35 /** Used to specify what type of memory is being allocated by this allocator.
36 * Supported types are:
37 * MemorySource::Malloc
38 * MemorySource::DmaBuf
39 * MemorySource::DmaBufProtected
40 */
42
43 /** Interface that may be implemented to allow retrieval of Memory Region
44 * from allocated buffer at a certain offset
45 */
46 virtual void* GetMemoryRegionAtOffset(void* buffer, size_t offset, size_t alignment = 0)
47 {
48 IgnoreUnused(offset);
49 IgnoreUnused(alignment);
50 IgnoreUnused(buffer);
51 throw armnn::Exception(
52 "ICustomerAllocator::GetMemoryRegionAtOffset(): This function should be overridden in subclass.");
53 }
54
55};
56} // namespace armnn
Base class for all ArmNN exceptions so that users can filter to just those.
Custom Allocator interface.
virtual void * allocate(size_t size, size_t alignment)=0
Interface to be implemented by the child class to allocate bytes.
virtual ~ICustomAllocator()=default
Default virtual destructor.
virtual void free(void *ptr)=0
Interface to be implemented by the child class to free the allocated bytes.
virtual armnn::MemorySource GetMemorySourceType()=0
Used to specify what type of memory is being allocated by this allocator.
virtual void * GetMemoryRegionAtOffset(void *buffer, size_t offset, size_t alignment=0)
Interface that may be implemented to allow retrieval of Memory Region from allocated buffer at a cert...
Copyright (c) 2021 ARM Limited and Contributors.
MemorySource
Define the Memory Source to reduce copies.
Definition Types.hpp:246
void IgnoreUnused(Ts &&...)