ArmNN
 24.02
ClBackendDefaultAllocator Class Reference

Default Memory Allocator class returned from IBackendInternal::GetDefaultAllocator(MemorySource) More...

#include <ClBackendDefaultAllocator.hpp>

Inheritance diagram for ClBackendDefaultAllocator:
[legend]
Collaboration diagram for ClBackendDefaultAllocator:
[legend]

Public Member Functions

 ClBackendDefaultAllocator ()=default
 
void * allocate (size_t size, size_t alignment=0) override
 Interface to be implemented by the child class to allocate bytes. More...
 
void free (void *ptr) override
 Interface to be implemented by the child class to free the allocated bytes. More...
 
armnn::MemorySource GetMemorySourceType () override
 Used to specify what type of memory is being allocated by this allocator. More...
 
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 certain offset. More...
 
- Public Member Functions inherited from ICustomAllocator
virtual ~ICustomAllocator ()=default
 Default virtual destructor. More...
 

Detailed Description

Default Memory Allocator class returned from IBackendInternal::GetDefaultAllocator(MemorySource)

Definition at line 14 of file ClBackendDefaultAllocator.hpp.

Constructor & Destructor Documentation

◆ ClBackendDefaultAllocator()

Member Function Documentation

◆ allocate()

void* allocate ( size_t  size,
size_t  alignment = 0 
)
inlineoverridevirtual

Interface to be implemented by the child class to allocate bytes.

Parameters
[in]sizeSize to allocate
[in]alignmentAlignment that the returned pointer should comply with
Returns
A pointer to the allocated memory The returned pointer must be host write accessible

Implements ICustomAllocator.

Definition at line 19 of file ClBackendDefaultAllocator.hpp.

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  }

References armnn::IgnoreUnused().

◆ free()

void free ( void *  ptr)
inlineoverridevirtual

Interface to be implemented by the child class to free the allocated bytes.

Implements ICustomAllocator.

Definition at line 30 of file ClBackendDefaultAllocator.hpp.

31  {
32  ARM_COMPUTE_ERROR_ON(ptr == nullptr);
33  clReleaseMemObject(static_cast<cl_mem>(ptr));
34  }

◆ GetMemoryRegionAtOffset()

void* GetMemoryRegionAtOffset ( void *  buffer,
size_t  offset,
size_t  alignment = 0 
)
inlineoverridevirtual

Interface that may be implemented to allow retrieval of Memory Region from allocated buffer at a certain offset.

Reimplemented from ICustomAllocator.

Definition at line 41 of file ClBackendDefaultAllocator.hpp.

42  {
43  IgnoreUnused(alignment);
44  return static_cast<char*>(buffer) + offset;
45  }

References armnn::IgnoreUnused().

◆ GetMemorySourceType()

armnn::MemorySource GetMemorySourceType ( )
inlineoverridevirtual

Used to specify what type of memory is being allocated by this allocator.

Supported types are: MemorySource::Malloc MemorySource::DmaBuf MemorySource::DmaBufProtected

Implements ICustomAllocator.

Definition at line 36 of file ClBackendDefaultAllocator.hpp.

37  {
39  }

References armnn::Gralloc.


The documentation for this class was generated from the following file:
armnn::MemorySource::Gralloc
@ Gralloc
armnn::IgnoreUnused
void IgnoreUnused(Ts &&...)
Definition: IgnoreUnused.hpp:14