-
Notifications
You must be signed in to change notification settings - Fork 765
NanoVDB: support single-space device buffers in GridHandle (CUDA) #2288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
c927ae7
0f4395d
5ea0b9e
e86e55e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,6 +62,18 @@ class Buffer : private detail::StreamHolder<is_async_resource<R>::value> | |
|
|
||
| static constexpr bool IsAsync = is_async_resource<R>::value; | ||
|
|
||
| public: | ||
| /// @brief Element and resource types, for generic code that rebinds one | ||
| /// or constructs sibling buffers over the same resource. | ||
| using ElementType = T; | ||
| using ResourceType = R; | ||
|
|
||
| /// @brief Alias for a sibling buffer over the same resource with a | ||
| /// different element type. | ||
| template<typename U> | ||
| using rebind = Buffer<U, R>; | ||
|
|
||
| private: | ||
| R mResource; | ||
| T* mData = nullptr; | ||
| size_t mSize = 0; // element count | ||
|
|
@@ -156,6 +168,11 @@ class Buffer : private detail::StreamHolder<is_async_resource<R>::value> | |
| return out; | ||
| } | ||
|
|
||
| /// @brief 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, int> = 0> | ||
| Buffer copy() const { return this->copy(this->stream()); } | ||
|
|
||
| /// @brief Returns a deep copy of this buffer, allocated from a copy of the | ||
| /// synchronous resource. | ||
| template<typename S = R, std::enable_if_t<!is_async_resource<S>::value && is_resource<S>::value, int> = 0> | ||
|
|
@@ -255,6 +272,13 @@ class Buffer : private detail::StreamHolder<is_async_resource<R>::value> | |
| T* data() { return mData; } | ||
| const T* data() const { return mData; } | ||
|
|
||
| /// @brief Returns a copy of the resource; for a ResourceRef this refers | ||
| /// to the same underlying instance. | ||
| /// @note Requires R to be copy-constructible (the cuda::mr convention: | ||
| /// resources are cheap handles). A resource that owns its pool by | ||
| /// value hands the caller an independent copy of that pool. | ||
| R resource() const { return mResource; } | ||
|
|
||
| /// @brief Returns the number of elements. | ||
| size_t size() const { return mSize; } | ||
|
|
||
|
|
@@ -402,6 +426,40 @@ class BufferView | |
|
|
||
| } // namespace cuda | ||
|
|
||
| // Primary template defined in HostBuffer.h; declared here so this header | ||
| // stays self-contained without pulling in the host-buffer machinery. | ||
| template<typename BufferT> | ||
| struct BufferTraits; | ||
|
|
||
| /// @brief GridHandle support for the single-space cuda::Buffer: the buffer | ||
| /// owns exactly one allocation, resident on the device, so the handle | ||
| /// parses metadata through a device read and exposes only the device | ||
| /// accessors. Requires byte-addressed storage. | ||
| /// @note This trait doubles as the definition of the single-space | ||
| /// device-buffer concept: a buffer whose BufferTraits specialization | ||
| /// sets hasDeviceSingle guarantees ElementType and ResourceType | ||
| /// typedefs, data(), size() and size_bytes() (byte-addressed elements, | ||
| /// enforced by the consumer), resource(), copy(), clear(), and stream() | ||
| /// when the resource is stream-ordered. Any consumer of hasDeviceSingle | ||
| /// may rely on exactly this interface and nothing more; in particular, | ||
| /// scratch allocates through resource() as a cuda::Buffer, so a | ||
| /// conforming buffer never needs to be constructible by a consumer. | ||
| template<typename T, typename R> | ||
| struct BufferTraits<cuda::Buffer<T, R>> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 suggestion: This @note is effectively the definition of a "single-space buffer concept" — it lists exactly the members a buffer must provide for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in e86e55e — the @note now defines the single-space device-buffer concept and enumerates the exact interface a consumer of |
||
| { | ||
| static constexpr bool hasDeviceDual = false; | ||
| // Device-resident storage; the byte-addressed requirement is enforced by | ||
| // the single-space GridHandle constructor, so trait queries stay | ||
| // answerable for any element type. | ||
| static constexpr bool hasDeviceSingle = !cuda::is_host_accessible_resource<R>::value; | ||
| // A buffer over a host-accessible resource (e.g. PinnedResource) is | ||
| // host-readable, but GridHandle's host paths also require the create() | ||
| // static interface and byte-count size semantics that cuda::Buffer does | ||
| // not provide -- GridHandle rejects such buffers with a named error until | ||
| // that adaptation lands. | ||
| static constexpr bool hasHostSingle = cuda::is_host_accessible_resource<R>::value; | ||
| }; | ||
|
|
||
| } // namespace nanovdb | ||
|
|
||
| #endif // end of NANOVDB_CUDA_BUFFER_H_HAS_BEEN_INCLUDED | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💅 polish: Tiny one: a rebind alias here (
template<class U> using rebind = Buffer<U, R>;) would let generic code construct sibling buffers without spelling the full type —makeMetaScratchspellscuda::Buffer<GridHandleMetaData, ResourceT>manually today, and the VBM follow-up will spell two more.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in e86e55e. One deliberate non-use: the GridHandle constructor keeps spelling
cuda::Buffer<std::byte, ResourceT>for its scratch rather than rebindingBufferT, sorebindstays out of the single-space concept — scratch only needs the buffer's resource, not a sibling of the buffer type.