OpenVDB 13.1.0
Loading...
Searching...
No Matches
ManagedResource Class Reference

Managed (unified) memory resource. Allocations (cudaMallocManaged) are accessible from both the host and the device, with the driver migrating pages on demand, so a container over this resource serves grids that are read on both sides – the replacement for the legacy UnifiedBuffer. A GridHandle over this resource parses (and validates) its metadata through the device like any device buffer – a host-side parse could race still-running producer kernels – while the host accessors remain available afterwards; ordering host reads after device writes is the caller's responsibility, exactly as with UnifiedBuffer. More...

#include <nanovdb/cuda/ManagedResource.h>

Public Member Functions

void * allocate (size_t bytes, size_t alignment)
 Synchronous allocation of managed memory.
void deallocate (void *p, size_t bytes, size_t alignment)
 Synchronous deallocation.

Static Public Attributes

static constexpr size_t DEFAULT_ALIGNMENT = 256
static constexpr bool HOST_ACCESSIBLE = true
 Managed allocations are mapped into the host address space (detected by nanovdb::cuda::is_host_accessible_resource).
static constexpr bool DEVICE_ACCESSIBLE = true
 Managed allocations are also valid device addresses (detected by nanovdb::cuda::is_device_accessible_resource), so a handle over this resource exposes the device accessors as well as the host ones.

Detailed Description

Managed (unified) memory resource. Allocations (cudaMallocManaged) are accessible from both the host and the device, with the driver migrating pages on demand, so a container over this resource serves grids that are read on both sides – the replacement for the legacy UnifiedBuffer. A GridHandle over this resource parses (and validates) its metadata through the device like any device buffer – a host-side parse could race still-running producer kernels – while the host accessors remain available afterwards; ordering host reads after device writes is the caller's responsibility, exactly as with UnifiedBuffer.

Note
This resource is synchronous: cudaMallocManaged / cudaFree have no stream-ordered form, so it models the synchronous Resource concept (allocate / deallocate, no stream). The usual contract applies: the caller ensures device work touching an allocation has completed before it is freed.

Member Function Documentation

◆ allocate()

void * allocate ( size_t bytes,
size_t alignment )
inline

Synchronous allocation of managed memory.

Parameters
bytesnumber of bytes to allocate
alignmentrequested alignment (ignored; cudaMallocManaged satisfies at least DEFAULT_ALIGNMENT)

◆ deallocate()

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

Synchronous deallocation.

Parameters
ppointer previously returned by allocate
bytessize passed to the matching allocate (unused)
alignmentalignment passed to the matching allocate (unused)

Member Data Documentation

◆ DEFAULT_ALIGNMENT

size_t DEFAULT_ALIGNMENT = 256
staticconstexpr

◆ DEVICE_ACCESSIBLE

bool DEVICE_ACCESSIBLE = true
staticconstexpr

Managed allocations are also valid device addresses (detected by nanovdb::cuda::is_device_accessible_resource), so a handle over this resource exposes the device accessors as well as the host ones.

◆ HOST_ACCESSIBLE

bool HOST_ACCESSIBLE = true
staticconstexpr

Managed allocations are mapped into the host address space (detected by nanovdb::cuda::is_host_accessible_resource).