HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
nanovdb::CudaDeviceBuffer Class Reference

Simple memory buffer using un-managed pinned host memory when compiled with NVCC. Obviously this class is making explicit used of CUDA so replace it with your own memory allocator if you are not using CUDA. More...

#include <CudaDeviceBuffer.h>

Public Member Functions

 CudaDeviceBuffer (uint64_t size=0, bool host=true, void *stream=nullptr)
 Constructor. More...
 
 CudaDeviceBuffer (const CudaDeviceBuffer &)=delete
 Disallow copy-construction. More...
 
 CudaDeviceBuffer (CudaDeviceBuffer &&other) noexcept
 Move copy-constructor. More...
 
CudaDeviceBufferoperator= (const CudaDeviceBuffer &)=delete
 Disallow copy assignment operation. More...
 
CudaDeviceBufferoperator= (CudaDeviceBuffer &&other) noexcept
 Move copy assignment operation. More...
 
 ~CudaDeviceBuffer ()
 Destructor frees memory on both the host and device. More...
 
void init (uint64_t size, bool host=true, void *stream=nullptr)
 Initialize buffer. More...
 
uint8_t * data () const
 Retuns a raw pointer to the host/CPU buffer managed by this allocator. More...
 
uint8_t * deviceData () const
 Retuns a raw pointer to the device/GPU buffer managed by this allocator. More...
 
void deviceUpload (void *stream=nullptr, bool sync=true) const
 Upload this buffer from the host to the device, i.e. CPU -> GPU. More...
 
void deviceDownload (void *stream=nullptr, bool sync=true) const
 Upload this buffer from the device to the host, i.e. GPU -> CPU. More...
 
uint64_t size () const
 Returns the size in bytes of the raw memory buffer managed by this allocator. More...
 
void clear (void *stream=nullptr)
 De-allocate all memory managed by this allocator and set all pointers to NULL. More...
 
bool empty () const
 Returns true if this allocator is empty, i.e. has no allocated memory. More...
 
bool isEmpty () const
 Returns true if this allocator is empty, i.e. has no allocated memory. More...
 

Static Public Member Functions

static CudaDeviceBuffer create (uint64_t size, const CudaDeviceBuffer *dummy=nullptr, bool host=true, void *stream=nullptr)
 Static factory method that return an instance of this buffer. More...
 

Detailed Description

Simple memory buffer using un-managed pinned host memory when compiled with NVCC. Obviously this class is making explicit used of CUDA so replace it with your own memory allocator if you are not using CUDA.

Note
While CUDA's pinned host memory allows for asynchronous memory copy between host and device it is significantly slower then cached (un-pinned) memory on the host.

Definition at line 32 of file CudaDeviceBuffer.h.

Constructor & Destructor Documentation

nanovdb::CudaDeviceBuffer::CudaDeviceBuffer ( uint64_t  size = 0,
bool  host = true,
void stream = nullptr 
)
inline

Constructor.

Parameters
sizebyte size of buffer to be initialized
hostIf true buffer is initialized only on the host/CPU, else on the device/GPU
streamoptional stream argument (defaults to stream NULL)

Definition at line 51 of file CudaDeviceBuffer.h.

nanovdb::CudaDeviceBuffer::CudaDeviceBuffer ( const CudaDeviceBuffer )
delete

Disallow copy-construction.

nanovdb::CudaDeviceBuffer::CudaDeviceBuffer ( CudaDeviceBuffer &&  other)
inlinenoexcept

Move copy-constructor.

Definition at line 63 of file CudaDeviceBuffer.h.

nanovdb::CudaDeviceBuffer::~CudaDeviceBuffer ( )
inline

Destructor frees memory on both the host and device.

Definition at line 90 of file CudaDeviceBuffer.h.

Member Function Documentation

void nanovdb::CudaDeviceBuffer::clear ( void stream = nullptr)
inline

De-allocate all memory managed by this allocator and set all pointers to NULL.

Definition at line 184 of file CudaDeviceBuffer.h.

CudaDeviceBuffer nanovdb::CudaDeviceBuffer::create ( uint64_t  size,
const CudaDeviceBuffer dummy = nullptr,
bool  host = true,
void stream = nullptr 
)
inlinestatic

Static factory method that return an instance of this buffer.

Parameters
sizebyte size of buffer to be initialized
dummythis argument is currently ignored but required to match the API of the HostBuffer
hostIf true buffer is initialized only on the host/CPU, else on the device/GPU
streamoptional stream argument (defaults to stream NULL)
Returns
An instance of this class using move semantics

Definition at line 143 of file CudaDeviceBuffer.h.

uint8_t* nanovdb::CudaDeviceBuffer::data ( ) const
inline

Retuns a raw pointer to the host/CPU buffer managed by this allocator.

Warning
Note that the pointer can be NULL!

Definition at line 101 of file CudaDeviceBuffer.h.

uint8_t* nanovdb::CudaDeviceBuffer::deviceData ( ) const
inline

Retuns a raw pointer to the device/GPU buffer managed by this allocator.

Warning
Note that the pointer can be NULL!

Definition at line 105 of file CudaDeviceBuffer.h.

void nanovdb::CudaDeviceBuffer::deviceDownload ( void stream = nullptr,
bool  sync = true 
) const
inline

Upload this buffer from the device to the host, i.e. GPU -> CPU.

Parameters
streamoptional CUDA stream (defaults to CUDA stream 0)
syncif false the memory copy is asynchronous
Note
If the host/CPU buffer does not exist it is first allocated
Warning
Assumes that the device/GPU buffer already exists

Definition at line 173 of file CudaDeviceBuffer.h.

void nanovdb::CudaDeviceBuffer::deviceUpload ( void stream = nullptr,
bool  sync = true 
) const
inline

Upload this buffer from the host to the device, i.e. CPU -> GPU.

Parameters
streamoptional CUDA stream (defaults to CUDA stream 0)
syncif false the memory copy is asynchronous
Note
If the device/GPU buffer does not exist it is first allocated
Warning
Assumes that the host/CPU buffer already exists

Definition at line 162 of file CudaDeviceBuffer.h.

bool nanovdb::CudaDeviceBuffer::empty ( void  ) const
inline

Returns true if this allocator is empty, i.e. has no allocated memory.

Definition at line 126 of file CudaDeviceBuffer.h.

void nanovdb::CudaDeviceBuffer::init ( uint64_t  size,
bool  host = true,
void stream = nullptr 
)
inline

Initialize buffer.

Parameters
sizebyte size of buffer to be initialized
hostIf true buffer is initialized only on the host/CPU, else on the device/GPU
Note
All existing buffers are first cleared
Warning
size is expected to be non-zero. Use clear() clear buffer!

Definition at line 148 of file CudaDeviceBuffer.h.

bool nanovdb::CudaDeviceBuffer::isEmpty ( ) const
inline

Returns true if this allocator is empty, i.e. has no allocated memory.

Definition at line 127 of file CudaDeviceBuffer.h.

CudaDeviceBuffer& nanovdb::CudaDeviceBuffer::operator= ( const CudaDeviceBuffer )
delete

Disallow copy assignment operation.

CudaDeviceBuffer& nanovdb::CudaDeviceBuffer::operator= ( CudaDeviceBuffer &&  other)
inlinenoexcept

Move copy assignment operation.

Definition at line 77 of file CudaDeviceBuffer.h.

uint64_t nanovdb::CudaDeviceBuffer::size ( void  ) const
inline

Returns the size in bytes of the raw memory buffer managed by this allocator.

Definition at line 122 of file CudaDeviceBuffer.h.


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