High-performance and Flexible IPC for tensor data with seamless ROS integration for robotics research.
tensor-ipc provides efficient shared memory communication for tensor data between processes, with built-in support for ROS topics. It enables zero-copy data sharing using POSIX shared memory and integrates with ROS for distributed communication and sim/real transfer.
- Zero-Copy Shared Memory: POSIX shared memory with per-frame locking for safe concurrent access
- ROS Integration: Built-in ROS producers and consumers with automatic type conversion (custom types are supported through ros2_numpy)
- Multi-Backend Support: Native support for NumPy, PyTorch (CPU/CUDA), and JAX (CPU/GPU)
- DDS Notifications: Real-time notifications and synchronization using CycloneDDS for efficient polling
- Type Safety: Automatic validation of tensor shapes, dtypes, and devices
- History Management: Configurable history buffers with circular indexing
pip install tensor-ipcOptional dependencies:
- PyTorch support:
pip install tensor-ipc torch - JAX support:
pip install tensor-ipc jax jaxlib - JAX GPU support:
pip install tensor-ipc "jax[cuda12]" cupy-cuda12x - ROS support: Install ros2_numpy in the same Python environment
Without optional dependencies, only the NumPy backend is available.
Refer to examples/ to see basic usage. Documentation is coming soon (hopefully).
import torch
from tensor_ipc.core.producer import TensorProducer
# CUDA tensors with IPC sharing
if torch.cuda.is_available():
cuda_tensor = torch.zeros(3, 224, 224, device='cuda:0')
producer = TensorProducer.from_sample("cuda_pool", cuda_tensor)
# Publish CUDA tensor directly
gpu_data = torch.randn(3, 224, 224, device='cuda:0')
producer.put(gpu_data)def on_new_data(data):
print(f"Callback triggered with data shape: {data.shape}")
consumer = TensorConsumer(
metadata,
on_new_data_callback=on_new_data
)
# Callback will be triggered when new data arrives# Get last 5 frames in chronological order
history = consumer.get(history_len=5, latest_first=False)
# Get last 3 frames with latest first
recent = consumer.get(history_len=3, latest_first=True)- Backends: Pluggable backends for NumPy, PyTorch (CPU/CUDA), and JAX (CPU/GPU)
- Shared Memory: NumPy/PyTorch/JAX CPU backends use POSIX shared memory. CUDA backends use CUDA IPC handles for GPU memory sharing.
- Locking: Per-frame reader-writer locks for safe concurrent access
- Notifications: CycloneDDS for real-time progress updates
- ROS Bridge: Automatic conversion between ROS messages and tensor data
TensorProducer: Creates and publishes to shared memory poolsTensorConsumer: Subscribes to and reads from shared memory poolsPoolMetadata: Describes pool structure and properties
ROSTensorProducer: Publishes shared memory data to ROS topicsROSTensorConsumer: Subscribes to ROS topics and creates shared memory pools
MetadataCreator.from_numpy_sample(): Create metadata from NumPy arraysMetadataCreator.from_torch_sample(): Create metadata from PyTorch CPU tensorsMetadataCreator.from_torch_cuda_sample(): Create metadata from PyTorch CUDA tensorsMetadataCreator.from_jax_sample(): Create metadata from JAX CPU arraysMetadataCreator.from_jax_gpu_sample(): Create metadata from JAX GPU arraysMetadataCreator.from_sample(): Unified creation from any supported tensor type
- Python 3.8+
- NumPy
- Linux (POSIX shared memory)
- Optional: PyTorch (for torch/torch_cuda backends)
- Optional: JAX + jaxlib (for jax backend)
- Optional: JAX + CuPy (for jax_gpu backend)
- Optional: ROS 2 + ros2_numpy (for ROS integration)
MIT License
This library (especially documentation) is partly written by various LLMs.