20#ifndef NANOVDB_CUDA_HANDLESTORAGE_H_HAS_BEEN_INCLUDED
21#define NANOVDB_CUDA_HANDLESTORAGE_H_HAS_BEEN_INCLUDED
54template<
typename BufferT>
55inline BufferT
createDeviceStorage(uint64_t bytes,
const BufferT* proto,
int device, cudaStream_t stream)
58 using ResourceT =
typename BufferT::ResourceType;
61 if constexpr (std::is_default_constructible<ResourceT>::value) {
63 else return BufferT(bytes,
noInit);
65 throw std::runtime_error(
"createDeviceStorage: a buffer over a non-default-constructible "
66 "resource requires a prototype buffer to take the resource from");
70 return BufferT(stream, proto->resource(), bytes,
noInit);
73 return BufferT(proto->resource(), bytes,
noInit);
76 return BufferT::create(bytes, proto, device, stream);
84template<
typename BufferT>
88 else return buffer.deviceData();
98template<
typename BufferT>
103 cudaCheck(cudaStreamSynchronize(stream));
113template<
typename DstBufferT>
117 using ResourceT =
typename DstBufferT::ResourceType;
122 if constexpr (std::is_default_constructible<ResourceT>::value) {
124 else return DstBufferT(bytes,
noInit);
126 throw std::runtime_error(
"cuda::copyTo: a destination buffer over a non-default-constructible "
127 "resource requires a prototype buffer");
131 return DstBufferT(stream, proto->resource(), bytes,
noInit);
134 return DstBufferT(proto->resource(), bytes,
noInit);
137 return DstBufferT::create(bytes, proto);
147 template<
typename BufferT>
153 template<
typename BufferT>
156 return handle.mMetaData;
198template<
typename DstBufferT,
typename SrcBufferT>
204 "cuda::copyTo does not support dual-space buffers: use deviceUpload/deviceDownload on the handle");
205 static_assert(srcDev || dstDev,
206 "cuda::copyTo is for cross-space transfers involving a device buffer: use GridHandle::copy for host-to-host");
209 if constexpr (std::is_default_constructible<DstBufferT>::value) {
212 throw std::runtime_error(
"cuda::copyTo: an empty handle cannot be copied to a buffer type "
213 "that is not default-constructible");
218 if constexpr (srcDev) srcPtr = src.
deviceData();
219 else srcPtr = src.
data();
220 cudaCheck(cudaMemcpyAsync(dst.data(), srcPtr, bytes, cudaMemcpyDefault, stream));
222 cudaCheck(cudaStreamSynchronize(stream));
233template<
typename DstBufferT,
typename SrcBufferT>
236 cudaStream_t stream = 0;
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:109
BufferT & buffer()
Return a reference to the buffer.
Definition GridHandle.h:215
uint64_t bufferSize() const
Definition GridHandle.h:256
util::enable_if< BufferTraits< U >::hasDeviceDual, constvoid * >::type deviceData() const
Definition GridHandle.h:232
void * data()
Returns a pointer to the host data; not available for a single-space device buffer,...
Definition GridHandle.h:225
Definition GridHandle.h:37
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:99
void * deviceStorageData(BufferT &buffer)
The device address of a storage buffer made by createDeviceStorage: data() for a single-space buffer,...
Definition HandleStorage.h:85
BufferT createDeviceStorage(uint64_t bytes, const BufferT *proto, int device, cudaStream_t stream)
Allocates bytes of device-resident storage of buffer type BufferT: single-space buffers allocate thro...
Definition HandleStorage.h:55
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:114
Definition GridHandle.h:37
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:199
Defines a simple memory pool used to call cub functions that use dynamic temporary storage.
Definition GridHandle.h:31
Cuda specific utility functions.
#define cudaCheck(ans)
Definition Util.h:49
static constexpr bool value
Definition HostBuffer.h:112
static constexpr bool value
Definition HostBuffer.h:121
static constexpr bool value
Definition HostBuffer.h:138
static constexpr bool hasDeviceDual
Definition HostBuffer.h:102
The one gateway for constructing a GridHandle from a buffer plus metadata that is already known to be...
Definition HandleStorage.h:146
static GridHandle< BufferT > make(BufferT &&buffer, std::vector< GridHandleMetaData > meta)
Definition HandleStorage.h:148
static const std::vector< GridHandleMetaData > & meta(const GridHandle< BufferT > &handle)
Definition HandleStorage.h:154
Detection trait: is_async_resource<R>::value is true iff R models the stream-ordered AsyncResource co...
Definition DeviceResource.h:118