Skip to content

[Caspar] Own the GraphSolver device buffer with a unique_ptr - #3

Open
sarlinpe wants to merge 1 commit into
caspar-barrier-scoped-csefrom
caspar-solver-move-semantics
Open

sarlinpe wants to merge 1 commit into
caspar-barrier-scoped-csefrom
caspar-solver-move-semantics

Conversation

@sarlinpe

@sarlinpe sarlinpe commented Dec 4, 2026

Copy link
Copy Markdown
Member

Stacked on #2.

GraphSolver held its device allocation in an uninitialized raw pointer, with defaulted move operations and an unconditional cudaFree in the destructor. A moved-from solver therefore freed the buffer a second time, and move assignment leaked the target's previous buffer.

The buffer is now held in a std::unique_ptr whose deleter frees it on the device it was allocated on, so the defaulted move operations and destructor are correct. The public interface is unchanged.

Test plan

  • New test in caspar_solver_cuda_test.cc: move-constructs and move-assigns a solver, destroys the moved-from one, and checks that the moved-to solver matches an unmoved one and that no CUDA error is left behind. The leak on move assignment is fixed by construction but not asserted.
  • symforce_caspar_codegen_test.py and the Caspar CUDA tests pass (nvcc, A100).

GraphSolver held its device allocation in an uninitialized raw pointer,
with defaulted move operations and an unconditional cudaFree in the
destructor. A moved-from solver therefore freed the buffer a second time,
and move assignment leaked the target's previous buffer.

Hold the buffer in a std::unique_ptr whose deleter frees it on the device
it was allocated on. The defaulted move operations and destructor are then
correct, and the public interface is unchanged.

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