OpenVDB 13.1.0
Loading...
Searching...
No Matches
SyncFromAsync< Derived > Struct Template Reference

CRTP base supplying the synchronous half of the resource concept in terms of the stream-ordered half, so a custom stream-ordered resource only has to write allocate_async and deallocate_async. More...

#include <nanovdb/cuda/DeviceResource.h>

Public Member Functions

void * allocate (size_t bytes, size_t alignment)
 Allocates bytes usable on any stream when this returns.
void deallocate (void *p, size_t bytes, size_t alignment)
 Frees p on the null stream.

Detailed Description

template<class Derived>
struct nanovdb::cuda::SyncFromAsync< Derived >

CRTP base supplying the synchronous half of the resource concept in terms of the stream-ordered half, so a custom stream-ordered resource only has to write allocate_async and deallocate_async.

Template Parameters
Derivedthe resource deriving from this base

A stream-ordered resource must also model the synchronous concept (is_async_resource implies is_resource), which means writing four methods where two would do. The synchronous pair is not a bare delegate: memory from allocate must be usable immediately on any stream, so the null-stream allocation has to be synchronized before it is returned. Omitting that synchronization yields memory that satisfies the concept but is not actually synchronous – a race rather than a compile error – so it lives here rather than being rewritten per resource.

struct MyResource : nanovdb::cuda::SyncFromAsync<MyResource> {
static constexpr size_t DEFAULT_ALIGNMENT = 256;
void* allocate_async(size_t bytes, size_t alignment, cudaStream_t stream);
void deallocate_async(void* p, size_t bytes, size_t alignment, cudaStream_t stream);
};
CRTP base supplying the synchronous half of the resource concept in terms of the stream-ordered half,...
Definition DeviceResource.h:195

Member Function Documentation

◆ allocate()

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

Allocates bytes usable on any stream when this returns.

Parameters
bytesnumber of bytes to allocate
alignmentrequested alignment
Note
Every call synchronizes the null stream; on hot paths prefer the stream-ordered pair.

◆ deallocate()

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

Frees p on the null stream.

Parameters
ppointer previously returned by allocate
bytessize passed to the matching allocate
alignmentalignment passed to the matching allocate
Note
No synchronization here: the synchronous concept's contract is that the memory is already quiescent when deallocate is called.