ArmNN
 24.08
GpuFsaBackendDefaultAllocator.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2023 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #pragma once
6 
7 #include <memory>
8 
11 
12 namespace armnn
13 {
14 
15 /**
16 * Default Memory Allocator class returned from IBackendInternal::GetDefaultAllocator(MemorySource)
17 */
19 {
20 public:
22 
23  void* allocate(size_t size, size_t alignment = 0) override
24  {
25  IgnoreUnused(alignment);
26  cl_mem buf{ clCreateBuffer(arm_compute::CLScheduler::get().context().get(),
27  CL_MEM_ALLOC_HOST_PTR | CL_MEM_READ_WRITE,
28  size,
29  nullptr,
30  nullptr)};
31  return static_cast<void *>(buf);
32  }
33 
34  void free(void* ptr) override
35  {
36  ARM_COMPUTE_ERROR_ON(ptr == nullptr);
37  clReleaseMemObject(static_cast<cl_mem>(ptr));
38  }
39 
41  {
42  return MemorySource::Gralloc;
43  }
44 
45  void* GetMemoryRegionAtOffset(void* buffer, size_t offset, size_t alignment = 0) override
46  {
47  IgnoreUnused(alignment);
48  return static_cast<char*>(buffer) + offset;
49  }
50 };
51 } // namespace armnn
armnn::GpuFsaBackendDefaultAllocator::GetMemorySourceType
MemorySource GetMemorySourceType() override
Used to specify what type of memory is being allocated by this allocator.
Definition: GpuFsaBackendDefaultAllocator.hpp:40
armnn::MemorySource::Gralloc
@ Gralloc
armnn::ICustomAllocator
Custom Allocator interface.
Definition: ICustomAllocator.hpp:16
armnn::GpuFsaBackendDefaultAllocator::free
void free(void *ptr) override
Interface to be implemented by the child class to free the allocated bytes.
Definition: GpuFsaBackendDefaultAllocator.hpp:34
IgnoreUnused.hpp
armnn::GpuFsaBackendDefaultAllocator::allocate
void * allocate(size_t size, size_t alignment=0) override
Interface to be implemented by the child class to allocate bytes.
Definition: GpuFsaBackendDefaultAllocator.hpp:23
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::GpuFsaBackendDefaultAllocator::GpuFsaBackendDefaultAllocator
GpuFsaBackendDefaultAllocator()=default
armnn::GpuFsaBackendDefaultAllocator
Default Memory Allocator class returned from IBackendInternal::GetDefaultAllocator(MemorySource)
Definition: GpuFsaBackendDefaultAllocator.hpp:18
MemorySources.hpp
armnn::GpuFsaBackendDefaultAllocator::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: GpuFsaBackendDefaultAllocator.hpp:45