Skip to content

[Caspar] Check CUDA errors in the generated solver and runtime - #4

Open
sarlinpe wants to merge 1 commit into
caspar-solver-move-semanticsfrom
caspar-cuda-error-checking
Open

sarlinpe wants to merge 1 commit into
caspar-solver-move-semanticsfrom
caspar-cuda-error-checking

Conversation

@sarlinpe

@sarlinpe sarlinpe commented Dec 4, 2026

Copy link
Copy Markdown
Member

Stacked on #3.

The generated GraphSolver and the Caspar runtime ignored the results of CUDA runtime calls, CUB calls, runtime kernel launches, and the StackedToCaspar/CasparToStacked mappings. A failed cudaMalloc, for example, left the solver with invalid device pointers: later kernels then failed with a sticky cudaErrorIllegalAddress that broke every subsequent solve in the process, and host read-backs silently returned zeros.

  • Add CASPAR_CUDA_CHECK in solver_tools.h. It throws a std::runtime_error naming the failed expression, its location, and the CUDA error, and is used for all such calls in the solver template, the runtime sources, and the Python mapping bindings.
  • finish_indices() and solve() synchronize and check for errors before returning.
  • Runtime functions and mappings that launch kernels return early on empty inputs, which would otherwise launch zero blocks and fail the new checks.

This complements the per-kernel launch check that upstream added in kernel.cu.jinja (dc269a3), which is left untouched.

Test plan

  • New tests in caspar_solver_cuda_test.cc: an allocation that cannot succeed throws with the CUDA error name, leaves no pending CUDA error, and a later solve still works; an empty problem runs through index setup, solve, and read-back without error.
  • symforce_caspar_codegen_test.py and the Caspar CUDA tests pass (nvcc, A100).
  • The change to the Python mapping bindings is only compile-checked (g++ -fsyntax-only on a generated pybinding.cc); no test builds the bindings.

The generated GraphSolver and the Caspar runtime ignored the results of
CUDA runtime calls, CUB calls, runtime kernel launches, and the
StackedToCaspar/CasparToStacked mappings. A failed cudaMalloc, for
example, left the solver with invalid device pointers: the following
kernels then failed with a sticky cudaErrorIllegalAddress that broke every
later solve in the process, and host read-backs silently returned zeros.

Add CASPAR_CUDA_CHECK in solver_tools.h, which throws a std::runtime_error
naming the failed expression, its location, and the CUDA error, and use it
for all such calls in the solver, the runtime, and the Python mapping
bindings. finish_indices() and solve() also synchronize and check for
errors before returning.

Return early on empty inputs from the runtime functions and mappings that
launch kernels, which would otherwise launch zero blocks and fail the new
checks.

Signed-off-by: Paul-Edouard Sarlin <psarlin@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant