ArmNN
 23.08
ClBackend::ClBackendCustomAllocatorMemoryRegion Class Reference

#include <ClBackend.hpp>

Inheritance diagram for ClBackend::ClBackendCustomAllocatorMemoryRegion:
[legend]
Collaboration diagram for ClBackend::ClBackendCustomAllocatorMemoryRegion:
[legend]

Public Member Functions

 ClBackendCustomAllocatorMemoryRegion (const cl::Buffer &buffer, void *hostMemPtr, armnn::MemorySource source)
 
void * ptr () override
 
void * map (cl::CommandQueue &q, bool blocking) override
 
void unmap (cl::CommandQueue &q) override
 

Detailed Description

Definition at line 213 of file ClBackend.hpp.

Constructor & Destructor Documentation

◆ ClBackendCustomAllocatorMemoryRegion()

ClBackendCustomAllocatorMemoryRegion ( const cl::Buffer &  buffer,
void *  hostMemPtr,
armnn::MemorySource  source 
)
inline

Definition at line 217 of file ClBackend.hpp.

218  : ICLMemoryRegion(buffer.getInfo<CL_MEM_SIZE>())
219  {
220  _mem = buffer;
221  m_HostMemPtr = hostMemPtr;
222  m_MemorySource = source;
223  }

Member Function Documentation

◆ map()

void* map ( cl::CommandQueue &  q,
bool  blocking 
)
inlineoverride

Definition at line 231 of file ClBackend.hpp.

232  {
233  armnn::IgnoreUnused(q, blocking);
234  if (m_HostMemPtr == nullptr)
235  {
236  throw armnn::Exception("ClBackend: Attempting to map memory with an invalid host ptr");
237  }
238  if (_mapping != nullptr)
239  {
240  throw armnn::Exception("ClBackend: Attempting to map memory which has not yet been unmapped");
241  }
242  switch (m_MemorySource)
243  {
245  _mapping = m_HostMemPtr;
246  return _mapping;
247  break;
250  // If the source is a Dmabuf then the memory ptr should be pointing to an integer value for the fd
251  _mapping = mmap(NULL, _size, PROT_WRITE, MAP_SHARED, *(reinterpret_cast<int*>(m_HostMemPtr)), 0);
252  return _mapping;
253  break;
254  default:
255  throw armnn::Exception("ClBackend: Attempting to map imported memory without a valid source");
256  break;
257  }
258  }

References armnn::DmaBuf, armnn::DmaBufProtected, armnn::IgnoreUnused(), and armnn::Malloc.

◆ ptr()

void* ptr ( )
inlineoverride

Definition at line 226 of file ClBackend.hpp.

227  {
228  return nullptr;
229  }

◆ unmap()

void unmap ( cl::CommandQueue &  q)
inlineoverride

Definition at line 260 of file ClBackend.hpp.

261  {
263  switch (m_MemorySource)
264  {
266  _mapping = nullptr;
267  break;
270  munmap(_mapping, _size);
271  _mapping = nullptr;
272  break;
273  default:
274  throw armnn::Exception("ClBackend: Attempting to unmap imported memory without a valid source");
275  break;
276  }
277  }

References armnn::DmaBuf, armnn::DmaBufProtected, armnn::IgnoreUnused(), and armnn::Malloc.


The documentation for this class was generated from the following file:
armnn::MemorySource::Malloc
@ Malloc
armnn::MemorySource::DmaBufProtected
@ DmaBufProtected
armnn::MemorySource::DmaBuf
@ DmaBuf
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