ArmNN
 22.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 229 of file ClBackend.hpp.

Constructor & Destructor Documentation

◆ ClBackendCustomAllocatorMemoryRegion()

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

Definition at line 233 of file ClBackend.hpp.

234  : ICLMemoryRegion(buffer.getInfo<CL_MEM_SIZE>())
235  {
236  _mem = buffer;
237  m_HostMemPtr = hostMemPtr;
238  m_MemorySource = source;
239  }

Member Function Documentation

◆ map()

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

Definition at line 247 of file ClBackend.hpp.

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

248  {
249  armnn::IgnoreUnused(q, blocking);
250  if (m_HostMemPtr == nullptr)
251  {
252  throw armnn::Exception("ClBackend: Attempting to map memory with an invalid host ptr");
253  }
254  if (_mapping != nullptr)
255  {
256  throw armnn::Exception("ClBackend: Attempting to map memory which has not yet been unmapped");
257  }
258  switch (m_MemorySource)
259  {
261  _mapping = m_HostMemPtr;
262  return _mapping;
263  break;
266  // If the source is a Dmabuf then the memory ptr should be pointing to an integer value for the fd
267  _mapping = mmap(NULL, _size, PROT_WRITE, MAP_SHARED, *(reinterpret_cast<int*>(m_HostMemPtr)), 0);
268  return _mapping;
269  break;
270  default:
271  throw armnn::Exception("ClBackend: Attempting to map imported memory without a valid source");
272  break;
273  }
274  }
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 242 of file ClBackend.hpp.

243  {
244  return nullptr;
245  }

◆ unmap()

void unmap ( cl::CommandQueue &  q)
inlineoverride

Definition at line 276 of file ClBackend.hpp.

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

277  {
279  switch (m_MemorySource)
280  {
282  _mapping = nullptr;
283  break;
286  munmap(_mapping, _size);
287  _mapping = nullptr;
288  break;
289  default:
290  throw armnn::Exception("ClBackend: Attempting to unmap imported memory without a valid source");
291  break;
292  }
293  }
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: