|
| | Buffer ()=default |
| | Default c-tor of an empty buffer; performs no allocation.
|
| template<typename S = R, std::enable_if_t< is_async_resource< S >::value, int > = 0> |
| | Buffer (cudaStream_t stream, R resource, size_t count, NoInit) |
| | C-tor allocating count uninitialized elements, stream-ordered on stream. Parameter order follows cuda::buffer: (stream, resource, count, no_init).
|
| template<typename S = R, std::enable_if_t< is_async_resource< S >::value, int > = 0> |
| | Buffer (cudaStream_t stream, size_t count, NoInit) |
| | Convenience c-tor using a default-constructed resource.
|
| template<typename S = R, std::enable_if_t<!is_async_resource< S >::value &&is_resource< S >::value, int > = 0> |
| | Buffer (R resource, size_t count, NoInit) |
| | C-tor allocating count uninitialized elements from a synchronous resource: the stream-less analog of (stream, resource, count, no_init).
|
| template<typename S = R, std::enable_if_t<!is_async_resource< S >::value &&is_resource< S >::value, int > = 0> |
| | Buffer (size_t count, NoInit) |
| | Convenience c-tor using a default-constructed resource.
|
| | Buffer (const Buffer &)=delete |
| | Explicitly disallow copy construction and assignment operation.
|
| Buffer & | operator= (const Buffer &)=delete |
| | Buffer (Buffer &&other) noexcept |
| | Move c-tor; steals the allocation (and retained stream, if any) and leaves other empty.
|
| Buffer & | operator= (Buffer &&other) noexcept |
| | Move assignment; frees the current allocation first, then steals from other and leaves it empty. Self-move is a no-op.
|
| template<typename S = R, std::enable_if_t< is_async_resource< S >::value, int > = 0> |
| Buffer | copy (cudaStream_t stream) const |
| | Returns a deep copy of this buffer, allocated from a copy of the resource; the allocation and element copy are ordered on stream, which becomes the copy's retained stream.
|
| template<typename S = R, std::enable_if_t< is_async_resource< S >::value, int > = 0> |
| Buffer | copy () const |
| | Returns a deep copy of this buffer ordered on the retained stream, i.e. copy(this->stream()).
|
| template<typename S = R, std::enable_if_t<!is_async_resource< S >::value &&is_resource< S >::value, int > = 0> |
| Buffer | copy () const |
| | Returns a deep copy of this buffer, allocated from a copy of the synchronous resource.
|
| | ~Buffer () |
| | D-tor. A stream-ordered resource frees on the retained stream; a synchronous resource frees immediately.
|
| template<typename S = R, std::enable_if_t< is_async_resource< S >::value, int > = 0> |
| cudaStream_t | stream () const |
| | Returns the retained stream, i.e. the stream the buffer's memory will be freed on.
|
| template<typename S = R, std::enable_if_t< is_async_resource< S >::value, int > = 0> |
| void | set_stream (cudaStream_t stream) |
| | Replaces the retained stream without synchronizing; subsequent deallocation (and destruction) is ordered on stream instead.
|
| template<typename S = R, std::enable_if_t< is_async_resource< S >::value, int > = 0> |
| void | resize (size_t count, cudaStream_t stream) |
| | Resizes the buffer to count elements, preserving the leading min(old, new) elements. Every operation — the new allocation, the prefix copy, and the free of the old block — is ordered on stream, which becomes the retained stream: the prefix copy is the old block's last use, so that is the stream its free must be ordered on.
|
| template<typename S = R, std::enable_if_t<!is_async_resource< S >::value &&is_resource< S >::value, int > = 0> |
| void | resize (size_t count) |
| | Resizes the buffer to count elements through the synchronous resource, preserving the leading min(old, new) elements.
|
| T * | data () |
| | Returns a pointer to the elements, or nullptr if empty.
|
| const T * | data () const |
| R | resource () const |
| | Returns a copy of the resource; for a ResourceRef this refers to the same underlying instance.
|
| size_t | size () const |
| | Returns the number of elements.
|
| size_t | size_bytes () const |
| | Returns the size of the buffer's allocation in bytes.
|
| bool | empty () const |
| | Returns true if this buffer manages no memory.
|
| void | destroy () |
| | Frees the buffer memory (if any) and resets to the empty state. A stream-ordered resource frees on the retained stream.
|
| void | clear () |
| | Frees the buffer memory (if any) and resets to the empty state.
|
| template<typename S = R, std::enable_if_t< is_async_resource< S >::value, int > = 0> |
| void | destroy (cudaStream_t stream) |
| | Frees the buffer memory (if any) on stream and resets to the empty state. stream becomes the retained stream.
|
| void | swap (Buffer &other) noexcept |
| | Exchanges the contents of this buffer with other. Neither buffer allocates, frees, or copies element data.
|
template<typename T, typename R = DeviceResource>
class nanovdb::cuda::Buffer< T, R >
Owning, typed container of T elements allocated from a memory resource R held by value.
- Template Parameters
-
| T | element type; sizes are expressed in elements, not bytes |
| R | memory resource, either stream-ordered (AsyncResource concept, see is_async_resource) or synchronous (Resource concept, see is_resource). When R provides both interfaces the stream-ordered one is used. |
With a stream-ordered resource the Buffer retains the stream of the most recent allocation (or the one supplied via set_stream) and orders its deallocation on that stream. Buffer is move-only.
- Note
- Cross-stream ordering is the caller's, expressed with ordinary CUDA events – the buffer deliberately tracks nothing. To hand a buffer's contents to work on another stream (a consumer library, a wrapped tensor), record after the last write and make the consumer wait:
cudaEvent_t ready;
cudaEventCreateWithFlags(&ready, cudaEventDisableTiming);
cudaEventRecord(ready, producerStream);
cudaStreamWaitEvent(consumerStream, ready);
and order the buffer's destruction (which frees on its retained stream) after all consumers the same way, or synchronize.