ArmNN
 24.08
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>
10 #include <armnn/MemorySources.hpp>
12 
13 namespace armnn
14 {
15 /** Custom Allocator interface */
17 {
18 public:
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
armnn::ICustomAllocator::GetMemoryRegionAtOffset
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...
Definition: ICustomAllocator.hpp:46
armnn::ICustomAllocator::free
virtual void free(void *ptr)=0
Interface to be implemented by the child class to free the allocated bytes.
armnn::ICustomAllocator
Custom Allocator interface.
Definition: ICustomAllocator.hpp:16
armnn::ICustomAllocator::allocate
virtual void * allocate(size_t size, size_t alignment)=0
Interface to be implemented by the child class to allocate bytes.
IgnoreUnused.hpp
armnn::ICustomAllocator::~ICustomAllocator
virtual ~ICustomAllocator()=default
Default virtual destructor.
armnn::Exception
Base class for all ArmNN exceptions so that users can filter to just those.
Definition: Exceptions.hpp:46
armnn::IgnoreUnused
void IgnoreUnused(Ts &&...)
Definition: IgnoreUnused.hpp:14
armnn::MemorySource
MemorySource
Define the Memory Source to reduce copies.
Definition: Types.hpp:244
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
armnn::ICustomAllocator::GetMemorySourceType
virtual armnn::MemorySource GetMemorySourceType()=0
Used to specify what type of memory is being allocated by this allocator.
MemorySources.hpp