AcademySoftwareFoundation / AcademySoftwareFoundation/openvdb
[BUG] NanoVDB new device buffer segfault due to "cudaCpuDeviceId"
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 3.4k
- Forks
- 777
- Avg merge
- 3d 9h
- Merged PRs (30d)
- 34
Description
Bug: Segfault in DeviceBuffer constructor
OpenVDB 12.1.0
Windows 10
Cuda 12.8
Summary:
Creating a nanovdb::GridHandle<nanovdb::cuda::DeviceBuffer> on the host and passing it to a cuda function such as nanovdb::tools::cuda::voxelsToGrid causes a segmentation fault. The crash occurs because the DeviceBuffer(const HostBuffer&, ...) constructor defaults its device parameter to cudaCpuDeviceId (-1), which is then used as an invalid index for the mGpuData array. Removing the "cudaCpuDeviceId" and setting it to 0 works.
Problematic Code :
https://github.com/AcademySoftwareFoundation/openvdb/blob/dd0ac130d0110f15ca75b8de5bb227a1870665bf/nanovdb/nanovdb/cuda/DeviceBuffer.h#L130-L142
Reproduce :
Host Code :
nanovdb::GridHandle<nanovdb::cuda::DeviceBuffer> handle;
CreateIndexGrid(data, handle, voxelSize); // <- Function from .cu file
Device Code :
void create_index_grid(HNS::GridIndexedData& data, nanovdb::GridHandle<nanovdb::cuda::DeviceBuffer>& handle, const float voxelSize) {
nanovdb::Coord* d_coords = nullptr;
cudaMalloc(&d_coords, data.size() * sizeof(nanovdb::Coord));
cudaMemcpy(d_coords, data.pCoords(), data.size() * sizeof(nanovdb::Coord), cudaMemcpyHostToDevice);
handle = nanovdb::tools::cuda::voxelsToGrid<nanovdb::ValueOnIndex, nanovdb::Coord*>(d_coords, data.size(), voxelSize);
cudaFree(d_coords);
}
This is maybe not a bug rather an unexpected behaviour, as it was working fine before the DeviceBuffer rework in OpenVDB 12.0,
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in nanovdb/nanovdb/cuda/DeviceBuffer.h at lines 130-142 and inspect how the DeviceBuffer constructor uses its device parameter and mGpuData. Run the provided host and device reproduction with OpenVDB 12.1.0, Windows 10, and CUDA 12.8. Done means creating the GridHandle and calling voxelsToGrid no longer segfaults when using the default device argument.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100