Add cuda_buffer_py - #6
Open
nvcyc wants to merge 2 commits into
Open
Conversation
nvcyc
marked this pull request as ready for review
August 10, 2026 17:54
nvcyc
force-pushed
the
nvcyc/cuda_buffer_py
branch
4 times, most recently
from
August 19, 2026 07:51
4aae907 to
c18390d
Compare
yuanknv
reviewed
Aug 25, 2026
nvcyc
force-pushed
the
nvcyc/cuda_buffer_py
branch
from
August 27, 2026 18:01
c18390d to
1c05282
Compare
Signed-off-by: CY Chen <cyc@nvidia.com>
nvcyc
force-pushed
the
nvcyc/cuda_buffer_py
branch
from
August 27, 2026 21:00
1c05282 to
3ff611f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds Python bindings for the CUDA buffer backend, enabling
rclpypublishers and subscribers to exchange CUDA-backed ROS message fields without converting them to CPU memory.The new
cuda_buffer_pypackage exposes CUDA allocation and scoped read/write APIs that follow the existing C++ buffer lifecycle model.Python API
The package adds:
CudaBuffer.from_cpu(data)— copy CPU data into a CUDA-backed buffer.CudaBuffer.from_size(size)— create a zero-initialized CUDA-backed buffer.CudaBuffer.allocate_buffer(size)— allocate uninitialized CUDA storage without synchronization.CudaBuffer.from_output_buffer(buffer, stream)— acquire aCudaWriteHandle.CudaBuffer.from_input_buffer(buffer, stream)— acquire aCudaReadHandle.CudaReadHandleandCudaWriteHandleare context managers that expose the CUDA device pointer throughdevice_ptrandget_ptr().Python type stubs and a
py.typedmarker are included.Synchronization and lifecycle
The scoped Python handles preserve the synchronization and lifetime guarantees of the C++ implementation:
CPU-backed inputs can still be promoted to CUDA automatically. The
from_cpu()andfrom_size()convenience APIs synchronize initialization before returning, whileallocate_buffer()and the scoped-handle path support asynchronous device-only workflows.
The bindings use the process-wide CUDA allocation pool provided by the installed
cuda_buffershared library. This allows the Python extension and dynamically loaded serialization backend to resolvethe same CUDA allocations during descriptor creation.
rclpy usage
Publishers can allocate and populate message fields directly on the GPU:
Testing
The package includes unit tests for allocation, conversion, scoped handles, synchronization, error handling, and lifetime management.
It also includes a Fast RTPS multiprocess regression test that: