OpenVDB 13.1.0
Loading...
Searching...
No Matches
ResourceRef< R > Struct Template Reference

Non-owning reference to a memory resource that is itself a resource: copying the ref shares the underlying resource rather than copying it. More...

#include <nanovdb/cuda/DeviceResource.h>

Public Member Functions

 ResourceRef (R &resource)
 Constructs a ref borrowing resource.
void * allocate (size_t bytes, size_t alignment)
 Synchronous pair, forwarding to the referenced resource.
void deallocate (void *p, size_t bytes, size_t alignment)
template<class S = R, std::enable_if_t< is_async_resource< S >::value, int > = 0>
void * allocate_async (size_t bytes, size_t alignment, cudaStream_t stream)
 Stream-ordered pair, present only when R models AsyncResource, so a ref over a synchronous resource does not misreport its tier.
template<class S = R, std::enable_if_t< is_async_resource< S >::value, int > = 0>
void deallocate_async (void *p, size_t bytes, size_t alignment, cudaStream_t stream)
 Stream-ordered pair, present only when R models AsyncResource, so a ref over a synchronous resource does not misreport its tier.

Static Public Attributes

static constexpr size_t DEFAULT_ALIGNMENT = R::DEFAULT_ALIGNMENT
static constexpr bool HOST_ACCESSIBLE = is_host_accessible_resource<R>::value
 A reference is host-accessible iff the referenced resource is.
static constexpr bool DEVICE_ACCESSIBLE = is_device_accessible_resource<R>::value

Friends

bool operator== (ResourceRef lhs, ResourceRef rhs)
 Two refs compare equal iff they reference the same resource, i.e. memory allocated through one may be deallocated through the other.
bool operator!= (ResourceRef lhs, ResourceRef rhs)

Detailed Description

template<class R>
struct nanovdb::cuda::ResourceRef< R >

Non-owning reference to a memory resource that is itself a resource: copying the ref shares the underlying resource rather than copying it.

Template Parameters
Rthe referenced resource type

Types that hold their resource by value – cuda::Buffer, matching cuda::buffer – select their ownership semantics by what is placed in that slot: a concrete resource is owned as a copy, while a ResourceRef borrows. This is the same division cuda::mr draws between any_resource (owning) and resource_ref (borrowing), and the same shape as std::pmr::polymorphic_allocator over memory_resource*. Use it when a resource is stateful or long-lived and a container must allocate through that instance rather than a copy of it.

Warning
The referenced resource must outlive every use of this ref and of all copies of it, including any container holding one.

Constructor & Destructor Documentation

◆ ResourceRef()

template<class R>
ResourceRef ( R & resource)
inline

Constructs a ref borrowing resource.

Parameters
resourceresource to allocate from; must outlive this ref

Member Function Documentation

◆ allocate()

template<class R>
void * allocate ( size_t bytes,
size_t alignment )
inline

Synchronous pair, forwarding to the referenced resource.

◆ allocate_async()

template<class R>
template<class S = R, std::enable_if_t< is_async_resource< S >::value, int > = 0>
void * allocate_async ( size_t bytes,
size_t alignment,
cudaStream_t stream )
inline

Stream-ordered pair, present only when R models AsyncResource, so a ref over a synchronous resource does not misreport its tier.

◆ deallocate()

template<class R>
void deallocate ( void * p,
size_t bytes,
size_t alignment )
inline

◆ deallocate_async()

template<class R>
template<class S = R, std::enable_if_t< is_async_resource< S >::value, int > = 0>
void deallocate_async ( void * p,
size_t bytes,
size_t alignment,
cudaStream_t stream )
inline

Stream-ordered pair, present only when R models AsyncResource, so a ref over a synchronous resource does not misreport its tier.

◆ operator!=

template<class R>
bool operator!= ( ResourceRef< R > lhs,
ResourceRef< R > rhs )
friend

◆ operator==

template<class R>
bool operator== ( ResourceRef< R > lhs,
ResourceRef< R > rhs )
friend

Two refs compare equal iff they reference the same resource, i.e. memory allocated through one may be deallocated through the other.

Member Data Documentation

◆ DEFAULT_ALIGNMENT

template<class R>
size_t DEFAULT_ALIGNMENT = R::DEFAULT_ALIGNMENT
staticconstexpr

◆ DEVICE_ACCESSIBLE

template<class R>
bool DEVICE_ACCESSIBLE = is_device_accessible_resource<R>::value
staticconstexpr

◆ HOST_ACCESSIBLE

template<class R>
bool HOST_ACCESSIBLE = is_host_accessible_resource<R>::value
staticconstexpr

A reference is host-accessible iff the referenced resource is.