17#ifndef NANOVDB_CUDA_HANDLESTORAGE_H_HAS_BEEN_INCLUDED
18#define NANOVDB_CUDA_HANDLESTORAGE_H_HAS_BEEN_INCLUDED
19#define NANOVDB_CUDA_HANDLESTORAGE_DEFERS_GRIDHANDLE_CUH
45template<
typename BufferT>
49 "device grid storage requires a single-space device buffer, e.g. cuda::Buffer<std::byte>");
50 using ResourceT =
typename BufferT::ResourceType;
52 if constexpr (std::is_default_constructible<ResourceT>::value) {
54 else return BufferT(bytes,
noInit);
56 throw std::runtime_error(
"createDeviceStorage: a buffer over a non-default-constructible "
57 "resource requires a prototype buffer to take the resource from");
61 return BufferT(stream, proto->resource(), bytes,
noInit);
64 return BufferT(proto->resource(), bytes,
noInit);
70template<
typename BufferT>
79template<
typename BufferT>
82 static constexpr bool value = std::is_convertible<BufferT, cudaStream_t>::value && !std::is_null_pointer<BufferT>::value
95template<
typename BufferT,
typename T>
104template<
typename BufferT>
109 cudaCheck(cudaStreamSynchronize(stream));
119template<
typename DstBufferT>
123 using ResourceT =
typename DstBufferT::ResourceType;
128 if constexpr (std::is_default_constructible<ResourceT>::value) {
130 else return DstBufferT(bytes,
noInit);
132 throw std::runtime_error(
"cuda::copyTo: a destination buffer over a non-default-constructible "
133 "resource requires a prototype buffer");
137 return DstBufferT(stream, proto->resource(), bytes,
noInit);
140 return DstBufferT(proto->resource(), bytes,
noInit);
143 return DstBufferT::create(bytes, proto);
189template<
typename DstBufferT,
typename SrcBufferT>
194 static_assert(srcDev || dstDev,
195 "cuda::copyTo is for cross-space transfers involving a device buffer: use GridHandle::copy for host-to-host");
201 if constexpr (std::is_default_constructible<DstBufferT>::value) {
204 throw std::runtime_error(
"cuda::copyTo: copying an empty handle into a buffer type that is not "
205 "default-constructible requires a single-space buffer type and a prototype buffer");
210 if constexpr (srcDev) srcPtr = src.
deviceData();
211 else srcPtr = src.
data();
212 cudaCheck(cudaMemcpyAsync(dst.data(), srcPtr, bytes, cudaMemcpyDefault, stream));
214 cudaCheck(cudaStreamSynchronize(stream));
224template<
typename DstBufferT,
typename SrcBufferT>
227 cudaStream_t stream = 0;
237#undef NANOVDB_CUDA_HANDLESTORAGE_DEFERS_GRIDHANDLE_CUH
238#if defined(__CUDACC__) && !defined(NANOVDB_TOOLS_CUDA_GRIDCHECKSUM_DEFERS_GRIDHANDLE_CUH)
239#include <nanovdb/cuda/GridHandle.cuh>
Typed containers for CUDA memory: the owning, resource-aware, stream-ordered cuda::Buffer and the non...
Defines GridHandle, which manages a memory buffer containing one or more NanoVDB grids: host-resident...
HostBuffer - a buffer that contains a shared or private bump pool to either externally or internally ...
This class serves to manage a buffer containing one or more NanoVDB Grids.
Definition GridHandle.h:164
BufferT & buffer()
Return a reference to the buffer.
Definition GridHandle.h:297
uint64_t bufferSize() const
Returns the size in bytes of the raw memory buffer managed by this GridHandle.
Definition GridHandle.h:324
util::enable_if< BufferHasDeviceSingle< U >::value, constvoid * >::type deviceData() const
For a single-space buffer the device data is the buffer itself.
Definition GridHandle.h:316
static GridHandle adopt(BufferT &&buffer, std::vector< GridHandleMetaData > meta)
Constructs a handle over buffer from metadata the caller already knows to describe its contents,...
Definition GridHandle.h:213
void * data()
Returns a pointer to the host data; not available for a single-space device buffer,...
Definition GridHandle.h:307
Definition VoxToNanoVDB.h:15
void orderBeforeHandleConstruction(cudaStream_t stream)
Orders the host after stream where a handle is about to be constructed from bytes still being written...
Definition HandleStorage.h:105
void * deviceStorageData(BufferT &buffer)
The device address of a storage buffer made by createDeviceStorage: its one allocation is the device ...
Definition HandleStorage.h:71
BufferT createDeviceStorage(uint64_t bytes, const BufferT *proto, cudaStream_t stream)
Allocates bytes of device-resident storage of the single-space buffer type BufferT on the current dev...
Definition HandleStorage.h:46
DstBufferT makeTransferStorage(uint64_t bytes, cudaStream_t stream, const DstBufferT *proto)
Allocates bytes of destination storage for a cross-space transfer: single-space buffers allocate thro...
Definition HandleStorage.h:120
typename std::enable_if<!IsStreamArgument< BufferT >::value, T >::type PrototypeFormResult
Return type of a tool's prototype-buffer form: T, except when BufferT deduced as a stream (cudaStream...
Definition HandleStorage.h:96
constexpr NoInit noInit
Definition Buffer.h:29
GridHandle< DstBufferT > copyTo(const GridHandle< SrcBufferT > &src, cudaStream_t stream, const DstBufferT *proto=nullptr)
Deep-copies a grid handle into a different address space: the explicit, stream-carrying transfer betw...
Definition HandleStorage.h:190
Defines a simple memory pool used to call cub functions that use dynamic temporary storage.
Definition GridHandle.h:34
Cuda specific utility functions.
#define cudaCheck(ans)
Definition Util.h:49
static constexpr bool value
Definition HostBuffer.h:111
static constexpr bool value
Definition HostBuffer.h:120
static constexpr bool value
Definition HostBuffer.h:137
True when BufferT is a stream rather than a buffer: cudaStream_t, or another non-buffer type that con...
Definition HandleStorage.h:81
static constexpr bool value
Definition HandleStorage.h:82
Detection trait: is_async_resource<R>::value is true iff R models the stream-ordered AsyncResource co...
Definition DeviceResource.h:113
static GridHandle< DstBufferT > make(DstBufferT &&buffer, const GridHandle< SrcBufferT > &src)
Definition GridHandle.h:513