ArmNN
 21.08
ClBackend::ClBackendCustomAllocatorMemoryRegion Class Reference

#include <ClBackend.hpp>

Inheritance diagram for ClBackend::ClBackendCustomAllocatorMemoryRegion:

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 221 of file ClBackend.hpp.

Constructor & Destructor Documentation

◆ ClBackendCustomAllocatorMemoryRegion()

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

Definition at line 225 of file ClBackend.hpp.

226  : ICLMemoryRegion(buffer.getInfo<CL_MEM_SIZE>())
227  {
228  _mem = buffer;
229  m_HostMemPtr = hostMemPtr;
230  m_MemorySource = source;
231  }

Member Function Documentation

◆ map()

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

Definition at line 239 of file ClBackend.hpp.

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

240  {
241  armnn::IgnoreUnused(q, blocking);
242  if (m_HostMemPtr == nullptr)
243  {
244  throw armnn::Exception("ClBackend: Attempting to map memory with an invalid host ptr");
245  }
246  if (_mapping != nullptr)
247  {
248  throw armnn::Exception("ClBackend: Attempting to map memory which has not yet been unmapped");
249  }
250  switch (m_MemorySource)
251  {
253  _mapping = m_HostMemPtr;
254  return _mapping;
255  break;
258  // If the source is a Dmabuf then the memory ptr should be pointing to an integer value for the fd
259  _mapping = mmap(NULL, _size, PROT_WRITE, MAP_SHARED, *(reinterpret_cast<int*>(m_HostMemPtr)), 0);
260  return _mapping;
261  break;
262  default:
263  throw armnn::Exception("ClBackend: Attempting to map imported memory without a valid source");
264  break;
265  }
266  }
void IgnoreUnused(Ts &&...)
Base class for all ArmNN exceptions so that users can filter to just those.
Definition: Exceptions.hpp:46

◆ ptr()

void* ptr ( )
inlineoverride

Definition at line 234 of file ClBackend.hpp.

235  {
236  return nullptr;
237  }

◆ unmap()

void unmap ( cl::CommandQueue &  q)
inlineoverride

Definition at line 268 of file ClBackend.hpp.

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

269  {
271  switch (m_MemorySource)
272  {
274  _mapping = nullptr;
275  break;
278  munmap(_mapping, _size);
279  _mapping = nullptr;
280  break;
281  default:
282  throw armnn::Exception("ClBackend: Attempting to unmap imported memory without a valid source");
283  break;
284  }
285  }
void IgnoreUnused(Ts &&...)
Base class for all ArmNN exceptions so that users can filter to just those.
Definition: Exceptions.hpp:46

The documentation for this class was generated from the following file: