ArmNN
 24.08
ClBackendDefaultAllocator.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 #pragma once
6 #include <cstddef>
7 #include <memory>
10 
11 namespace armnn
12 {
13 /** Default Memory Allocator class returned from IBackendInternal::GetDefaultAllocator(MemorySource) */
15 {
16 public:
17  ClBackendDefaultAllocator() = default;
18 
19  void* allocate(size_t size, size_t alignment = 0) override
20  {
21  IgnoreUnused(alignment);
22  cl_mem buf{ clCreateBuffer(arm_compute::CLScheduler::get().context().get(),
23  CL_MEM_ALLOC_HOST_PTR | CL_MEM_READ_WRITE,
24  size,
25  nullptr,
26  nullptr)};
27  return static_cast<void *>(buf);
28  }
29 
30  void free(void* ptr) override
31  {
32  ARM_COMPUTE_ERROR_ON(ptr == nullptr);
33  clReleaseMemObject(static_cast<cl_mem>(ptr));
34  }
35 
37  {
39  }
40 
41  void* GetMemoryRegionAtOffset(void* buffer, size_t offset, size_t alignment = 0) override
42  {
43  IgnoreUnused(alignment);
44  return static_cast<char*>(buffer) + offset;
45  }
46 };
47 } // namespace armnn
armnn::ClBackendDefaultAllocator::GetMemoryRegionAtOffset
void * GetMemoryRegionAtOffset(void *buffer, size_t offset, size_t alignment=0) override
Interface that may be implemented to allow retrieval of Memory Region from allocated buffer at a cert...
Definition: ClBackendDefaultAllocator.hpp:41
armnn::MemorySource::Gralloc
@ Gralloc
armnn::ClBackendDefaultAllocator::free
void free(void *ptr) override
Interface to be implemented by the child class to free the allocated bytes.
Definition: ClBackendDefaultAllocator.hpp:30
armnn::ICustomAllocator
Custom Allocator interface.
Definition: ICustomAllocator.hpp:16
IgnoreUnused.hpp
armnn::ClBackendDefaultAllocator
Default Memory Allocator class returned from IBackendInternal::GetDefaultAllocator(MemorySource)
Definition: ClBackendDefaultAllocator.hpp:14
armnn::ClBackendDefaultAllocator::GetMemorySourceType
armnn::MemorySource GetMemorySourceType() override
Used to specify what type of memory is being allocated by this allocator.
Definition: ClBackendDefaultAllocator.hpp:36
armnn::ClBackendDefaultAllocator::allocate
void * allocate(size_t size, size_t alignment=0) override
Interface to be implemented by the child class to allocate bytes.
Definition: ClBackendDefaultAllocator.hpp:19
armnn::ClBackendDefaultAllocator::ClBackendDefaultAllocator
ClBackendDefaultAllocator()=default
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
MemorySources.hpp