Skip to content

Mesh distance: write the missing CUHOST launchers for sdt_naive, udt and udt_naive #121

Description

@balbasty

Split out of fastfields-lib#5, which fastfields/fastfields-cuda-impl#46 partially addressed.

fastfields/fastfields-cuda-impl#46 wired distance_mesh::dt's signed/tree-accelerated branch into the sdt launcher, so ff::dt_mesh reaches real CUDA code for the first time. The other three branches still throw, because their device kernels have no host launcher:

_signednaiveCPUCUDA
truefalsesdtsdt() — dispatched (#46)
truetruesdt_naivesdt_naive_kernel — no launcher
falsefalseudtudt_kernel — no launcher
falsetrueudt_naiveudt_naive_kernel — no launcher

All three kernels exist and are type-checked — tests/compile_probe_mesh.cu takes their addresses precisely because nothing else instantiates them — but none has a CUHOST function to build/upload the inputs, size the grid and launch.

What each one needs

udt — the closest to done. It walks the same BVH as sdt_kernel, so its launcher is sdt's minus the normals: build the tree, flatten_tree into the DeviceNode POD mirror, upload, size the grid from prod(size, nbatch), allocate the per-lane treetrace buffer. sdt is a direct template — most of it is deletion, not new logic.

sdt_naive / udt_naive — brute force over all M faces, no BVH and no trace buffer, so the launcher is much smaller: upload faces/vertices (+ normals for the signed one) and launch. These are also the references the BVH paths are supposed to be validated against on hardware, which is the main reason they are worth having.

Notes for whoever picks this up

  • Take the mesh counts as (nb_faces, nb_vertices). distance_mesh: dispatch dt's signed/tree branch into the sdt launcher fastfields-cuda-impl#46 reordered sdt to match cpu-impl and dt after finding it was the one place in the project with the opposite order; both are offset_t, so getting it wrong compiles clean and silently builds the mesh from the wrong counts.
  • Guard the stride_nearest upload on nearest_vertex being non-null. nearest_vertex is optional and cuda-lib passes a null stride with it; distance_mesh: dispatch dt's signed/tree branch into the sdt launcher fastfields-cuda-impl#46 fixed exactly this in sdt, where an unguarded copyToDeviceAsync(nullptr, ...) turns into cudaErrorInvalidValuestd::bad_alloc on the default call pattern.
  • Extend tests/compile_probe_mesh.cu to call each new launcher rather than just taking the kernel's address, and drop the corresponding probe_*_kernel helper once the launcher covers it. probe_dt already instantiates all four dt branches, so each new launcher gets type-checked through the real entry point automatically.
  • Add the branch to dt's dispatch and to the coverage table in its header comment, and delete the matching throw.

Out of scope

Real-hardware validation of any of this, including the sdt path fastfields/fastfields-cuda-impl#46 wired up — that remains on fastfields-lib#5. There is no GPU in CI, so the bar here is the same compile+link gate every other cuda-lib module is held to.

🤖 Generated with Claude Code

https://claude.ai/code/session_016AjQcY78NgbagPSbPJRr6Z

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions