Skip to content

Recording rosidl::Buffer (CUDA) topics in rosbag2: prototype and feedback wanted

ROS Discourse — Community updates1Lunascian

A ROS2 community prototype allows recording of CUDA-backed rosidl::Buffer topics by enabling the recorder to handle serialization on a separate thread, reducing publish latency from approximately 4.6 ms to 0.14 ms for 1920x1080 images at 30 Hz on an RTX 3060. The tool introduces opt-in command-line flags --acceptable-buffer-backends and --buffer-aware-topics, with the bag format remaining unchanged. Only the CUDA backend has been tested on hardware, and manual topic listing is required since the recorder cannot automatically detect publisher backends.

Hi all,

With rosidl::Buffer backends arriving in Lyrical, the recorder faces an issue: ros2 bag record only accepts the cpu backend, so every publisher converts its buffers to CPU memory and serializes them inside publish(), just because a recorder is subscribed. This prototype lets the recorder accept a backend and does that work on its own thread instead.

What it does

  • Two opt-in options, --acceptable-buffer-backends (default cpu, so nothing changes) and --buffer-aware-topics, also available as node parameters and in rosbag2_py.
  • A subscription that takes messages through the typed path and serializes them on the recorder’s side. A generic subscription cannot do this, because rmw_fastrtps deliberately rejects serialized takes of backend messages. The bag format and stored bytes are the same as before.
  • An unknown backend name fails at startup and lists the installed backends.
  • A message whose backend buffer arrives empty is dropped, counted as lost and logged, instead of being written as a valid-looking empty message.

Numbers

CUDA publisher, 1920x1080 sensor_msgs/Image at 30 Hz, RTX 3060: publish() goes from about 4.6 to 6 ms to 0.14 ms. The recorded messages are identical to the CPU path.

Testing it out

Branch (based on rolling): GitHub - UseTheForce007/rosbag2 at UseTheForce007/buffer-backend-recording · GitHub

ros2 bag record -s mcap -o my_bag --acceptable-buffer-backends any --topics /my_cuda_image

Caveats

  • The recorder cannot see which backend a publisher uses (no public rmw/rclcpp API for it), so --buffer-aware-topics is a manual list. Types without a rosidl::Buffer field automatically keep the cheaper generic subscription.
  • Conversion runs on one executor thread, so a recorder with several 4K streams at 30 Hz can fall behind. A worker pool is a follow-up.
  • Only the CUDA backend has been tested on hardware.

I’d love to hear back from the community if it’s useful and if there’s any bugs I might have overlooked.

Source notes

  1. Recording rosidl::Buffer (CUDA) topics in rosbag2: prototype and feedback wanted↩
Source evidence

Reported by the source; not independently verified.

  1. Hi all, With rosidl::Buffer backends arriving in Lyrical, the recorder faces an issue: ros2 bag record only accepts the cpu backend, so every publisher converts its buffers to CPU memory and serializes them inside publish() , just because a recorder is subscribed. This prototype lets the recorder accept a backend and does that work on its own thread instead. What it does Two opt-in options, --acceptable-buffer-backen
    Exact source
  2. fails at startup and lists the installed backends. A message whose backend buffer arrives empty is dropped, counted as lost and logged, instead of being written as a valid-looking empty message. Numbers CUDA publisher, 1920x1080 sensor_msgs/Image at 30 Hz, RTX 3060: publish() goes from about 4.6 to 6 ms to 0.14 ms. The recorded messages are identical to the CPU path. Testing it out Branch (based on rolling ): GitHub
    Exact source
  3. - UseTheForce007/rosbag2 at UseTheForce007/buffer-backend-recording · GitHub ros2 bag record -s mcap -o my_bag --acceptable-buffer-backends any --topics /my_cuda_image Caveats The recorder cannot see which backend a publisher uses (no public rmw/rclcpp API for it), so --buffer-aware-topics is a manual list. Types without a rosidl::Buffer field automatically keep the cheaper generic subscription. Conversion runs on o
    Exact source
  4. ne executor thread, so a recorder with several 4K streams at 30 Hz can fall behind. A worker pool is a follow-up. Only the CUDA backend has been tested on hardware. I’d love to hear back from the community if it’s useful and if there’s any bugs I might have overlooked.
    Exact source
  5. Recording rosidl::Buffer (CUDA) topics in rosbag2: prototype and feedback wanted
    Exact source
  6. ds (default cpu , so nothing changes) and --buffer-aware-topics , also available as node parameters and in rosbag2_py . A subscription that takes messages through the typed path and serializes them on the recorder’s side. A generic subscription cannot do this, because rmw_fastrtps deliberately rejects serialized takes of backend messages. The bag format and stored bytes are the same as before. An unknown backend name
    Exact source

Automatically extracted; no manual editorial approval recorded.

Article details
Signal

This prototype enables ROS2 bag recording of CUDA-backed rosidl::Buffer topics by offloading serialization to a dedicated thread, reducing publish latency from approximately 4.6 ms to 0.14 ms on an RTX 3060 for 1920x1080 images at 30 Hz, though backend detection remains manual and performance under high stream counts is untested.

Timezone · UTC

Article dates follow your selected timezone. Briefing editions use Hong Kong time (UTC+8).