Status Update: 2023-02-01 #180
Replies: 2 comments
-
ROS 2 Benchmark retrospectiveROS 2 Shared memoryShared Memory and Zero Copy:
it is not possible within ROS2 to switch from shared memory to normal memory as we do with iceoryx and Zenoh. This is linked to the ROS2 API design. You are required to explicitely pass a ros2 shared memory message type and use the Quantitative resultsAll benchmark I've made on ROS2/CycloneDDS on both Rust and Python shows that it does not use shared memory when not loaning messages. Speed is TCP speed. Issues with ROS Messages. Bridging generic data type.ROS message type requires to create bridges to and from generic data type due to its memory layout. It is often not clear if those bridges are zero copy or not. For exemple, for The main challenge is that ROS message requires ownership of the data. This often means needing a copy. Apache Arrow to the rescueApache Arrow solves a big part of those performance issues by being in the right memory layout, making it zero copy for basic type. See: to_numpy () Apache arrow has it's own limitation as well as the data typing might be less verbose. Image information might not include encoding for example. Apache Arrow zero-copy for Python APIUsing arrow for python without copy is being implemented in jorgecarleitao/arrow2#1369 of arrow2. This is unsafe and we will have to double check on safety but using zero copy gives a significant performance advantage compared to other framework. Implementation details. See: main...slice-arrow Arrow zero copy for C/C++Moving our C/C++ API from our own ffi pointer to arrow array and schema pointer should be pretty straight-forward. This removes the need for a copy and potentially removes the need for serialisation (autocore currently use Ex: https://github.com/apache/arrow-nanoarrow Implementation details: fn to_c_ptr(array: Box<dyn Array>, py: Python) ... {
let schema = Box::new(ffi::export_field_to_c(&Field::new(
"",
array.data_type().clone(),
true,
)));
let array = Box::new(ffi::export_array_to_c(array));
let schema_ptr: *const arrow2::ffi::ArrowSchema = &*schema;
let array_ptr: *const arrow2::ffi::ArrowArray = &*array;
// ...
// Ex from nanoarrow
int print_simple_array(struct ArrowArray* array, struct ArrowSchema* schema) {
struct ArrowError error;
struct ArrowArrayView array_view;
NANOARROW_RETURN_NOT_OK(ArrowArrayViewInitFromSchema(&array_view, schema, &error)); The Array traitThe Array trait is implemented for a large range of datatype, and is transmute-free.
Arrow zero-copy for RustWe can have a relatively close to the other API implementation where data is a let array_trait: Box<dyn Array>
let data = array_trait
.as_any()
.downcast_ref::<PrimitiveArray<u8>>()
.wrap_err("Could not cast sent output to arrow uint8 array")
.unwrap() Notes on dataflow typing.This means that typing is going to be managed imperatively and not declaratively meaning that it's not going to be present within the dataflow. This has the advantage to make implementation celerity faster. But the inconvenient is that it is not "checkable" with cli by default. We can potentially create macros to generate metadata that can be used to check. Quick recap of Dora - Arrow vs ROS2
|
Beta Was this translation helpful? Give feedback.
-
dora-daemon
|
Beta Was this translation helpful? Give feedback.
-
🥇
Beta Was this translation helpful? Give feedback.
All reactions