Skip to content

NanoVDB: encode points for any resource in PointsToGrid (CUDA) - #2244

Open
harrism wants to merge 3 commits into
AcademySoftwareFoundation:masterfrom
harrism:nanovdb-points-encode-resource
Open

NanoVDB: encode points for any resource in PointsToGrid (CUDA)#2244
harrism wants to merge 3 commits into
AcademySoftwareFoundation:masterfrom
harrism:nanovdb-points-encode-resource

Conversation

@harrism

@harrism harrism commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #2231, part of #2232 (NanoVDB injectable CUDA memory resources).

What

tools::cuda::PointsToGrid<Point, ResourceT> now encodes points for any resource. Previously the point-encoder lived only in the PointsToGrid<Point> full specialization (= PointsToGrid<Point, DeviceResource>), so a Point build with a custom resource missed it and fell through to the generic no-op — silently producing a grid with no encoded point data, no error. This was the known limitation called out in #2231's follow-ups.

The encoder is folded into the generic PointsToGrid<BuildT, ResourceT>::processPoints, gated by if constexpr (util::is_same<BuildT, Point>::value); the now-redundant full specialization is removed.

Why existing paths are unchanged

  • Non-Point builds: the if constexpr block is discarded, leaving the prior no-op body verbatim.
  • Default-resource Point builds: ResourceT == DeviceResource, so the same encode kernels run with the same alignment — byte-for-byte the previous path.

The resource governs allocation only; the encode kernels operate on device data, so making the encoder resource-agnostic is correct.

Testing

New TestMemoryResource.PointsToGrid_PointEncodedWithCustomResource builds a NanoGrid<Point> via PointsToGrid with a custom resource and asserts the encoded coordinates match the input — red on current code (captures the no-op), green after the fix. RTX 6000 Ada / CUDA 12.6: memory-resource suite 9/9, CPU nanovdb_test_nanovdb 153/153, nanovdb_test_cuda 53/53.

Non-CUDA builds

No impact on NANOVDB_USE_CUDA=OFF — the change is confined to tools/cuda/PointsToGrid.cuh (#if defined(__CUDACC__)-gated) and a CUDA-only test.

🤖 Generated with Claude Code

The point-encode step in tools::cuda::PointsToGrid was only reachable for
the default DeviceResource, because it lived in the BuildT=Point full
specialization of processPoints (i.e. <Point, DeviceResource>). A Point
grid built with a custom resource fell through to the generic no-op and
was silently left with unencoded point data.

Fold the encode into the generic processPoints and gate it with
if constexpr(is_same<BuildT, Point>). The encode kernels run on device
data and are independent of the resource; only the trailing d_indx
deallocation routes through ResourceT. Non-Point builds and default-
resource Point builds are unchanged.

Add a regression test that builds a NanoGrid<Point> through a custom
resource and asserts every input point is recoverable from the encoded
per-voxel data.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Mark Harris <mharris@nvidia.com>
@harrism

harrism commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

@kmuseth friendly ping — this has been open since July 2 with no review yet.

It's the smaller of the two follow-ups from #2231 (+117/-65, 2 files) and fixes a silent-wrong-output case: PointsToGrid<Point, CustomResource> currently falls through to the generic no-op and produces a grid with no encoded point data and no error, because the encoder only existed in the PointsToGrid<Point> full specialization. That was the known limitation called out in #2231's follow-up list.

Both existing paths are unchanged by construction — non-Point builds discard the if constexpr block, and default-resource Point builds run the same code that used to live in the specialization. New test covers the custom-resource Point combination that was previously silent.

Happy to rebase if it's gone stale.

harrism and others added 2 commits August 4, 2026 01:25
…code-resource

Signed-off-by: Mark Harris <mharris@nvidia.com>
nvcc rejects an extended lambda defined directly inside the block of an
if constexpr statement on some host compilers, so the nine encode
launches failed to compile against MSVC while building fine with gcc and
clang. Give them their own member function and have the branch call it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Mark Harris <mharris@nvidia.com>

@kmuseth kmuseth left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me - good catch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants