OpenVDB 14.0.0
Loading...
Searching...
No Matches
DeviceResource Class Reference

Default stream-ordered device memory resource. Allocations are made with cudaMallocAsync and freed with cudaFreeAsync via the util::cuda wrappers. More...

#include <nanovdb/cuda/DeviceResource.h>

Public Member Functions

void * allocate_async (size_t bytes, size_t, cudaStream_t stream)
 Stream-ordered allocation.
void deallocate_async (void *p, size_t, size_t, cudaStream_t stream)
 Stream-ordered deallocation.
void * allocate (size_t bytes, size_t alignment)
 Synchronous allocation; the returned memory is immediately valid on every stream.
void deallocate (void *p, size_t bytes, size_t alignment)
 Synchronous deallocation; the caller guarantees that device work touching the memory has completed.

Static Public Attributes

static constexpr size_t DEFAULT_ALIGNMENT = 256

Friends

bool operator== (const DeviceResource &, const DeviceResource &)
 Stateless: memory allocated through one instance may be deallocated through any other, so every two instances compare equal (the equality cuda::mr's resource concepts require).
bool operator!= (const DeviceResource &, const DeviceResource &)

Detailed Description

Default stream-ordered device memory resource. Allocations are made with cudaMallocAsync and freed with cudaFreeAsync via the util::cuda wrappers.

Note
Models the AsyncResource concept, which refines the synchronous Resource concept (as in CCCL's cuda::mr): the instance methods provide both the stream-ordered allocate_async / deallocate_async and the synchronous allocate / deallocate. The type is stateless, so a default-constructed instance adds no overhead.

Member Function Documentation

◆ allocate()

void * allocate ( size_t bytes,
size_t alignment )
inline

Synchronous allocation; the returned memory is immediately valid on every stream.

Parameters
bytesnumber of bytes to allocate
alignmentrequested alignment

◆ allocate_async()

void * allocate_async ( size_t bytes,
size_t ,
cudaStream_t stream )
inline

Stream-ordered allocation.

Parameters
bytesnumber of bytes to allocate
streamcuda stream the allocation is ordered on
Note
the alignment parameter is unnamed: cudaMallocAsync always 256B-aligns

◆ deallocate()

void deallocate ( void * p,
size_t bytes,
size_t alignment )
inline

Synchronous deallocation; the caller guarantees that device work touching the memory has completed.

Parameters
ppointer previously returned by allocate or allocate_async
bytessize of the allocation in bytes
alignmentalignment of the allocation in bytes

◆ deallocate_async()

void deallocate_async ( void * p,
size_t ,
size_t ,
cudaStream_t stream )
inline

Stream-ordered deallocation.

Parameters
ppointer previously returned by allocate_async
streamcuda stream the deallocation is ordered on

◆ operator!=

bool operator!= ( const DeviceResource & ,
const DeviceResource &  )
friend

◆ operator==

bool operator== ( const DeviceResource & ,
const DeviceResource &  )
friend

Stateless: memory allocated through one instance may be deallocated through any other, so every two instances compare equal (the equality cuda::mr's resource concepts require).

Member Data Documentation

◆ DEFAULT_ALIGNMENT

size_t DEFAULT_ALIGNMENT = 256
staticconstexpr