- Sharvin Mhatre (ECS Dept., SIES Graduate School of Technology)
- Archit Jaijith (ECS Dept., SIES Graduate School of Technology)
- Saumitrya Chavan (ECS Dept., SIES Graduate School of Technology)
In autonomous swarm robotics, verifying the proximity of agents in real-time is vital to prevent collisions and coordinate formations. SwarmDB simulates a dense environment of active robots navigating a 3D coordinate space.
Calculating pairwise distances for a swarm requires comparing every robot against every other robot. At scale (e.g.,
SwarmDB was conceptualized for the NVIDIA CINECA hackathon to manage and query real-time telemetry data for autonomous robotic swarms using GPU acceleration. It transitions spatial queries from CPU bottlenecks to a high-throughput, parallelized CUDA database engine.
graph TD
A[Robot Swarm Positions - N x 3] --> B{Choose Evaluation Engine}
B -->|CPU Baseline O N^2| C[Pairwise Distance Matrix]
C -->|Vectorized NumPy| C1[Compute A^2 + B^2 - 2AB]
C2[Filter by Collision Radius]
C1 --> C2
B -->|CPU Optimized O N log N| D[cKDTree Spatial Partitioning]
D -->|SciPy cKDTree| D1[Query Neighbors within Radius]
B -->|GPU CUDA O N^2 / Block| E[CUDA Spatial Kernels]
E -->|CuPy Elementwise| E1[Elementwise Kernel]
E -->|PyCUDA / CuPy Raw| E2[Grid-Stride Loop Kernel]
E2 --> E3[kinetic_join_strided_kernel]
C2 --> F[Collision Pairs output]
D1 --> F
E1 --> F
E3 --> F
F --> G[FastAPI Endpoint /swarm/collisions]
H[Autonomous Agents] -->|Read / Write| I[P2P Decentralized Memory Vault]
I -->|Decentralized Sync| I1[SwarmDBNode Cluster]
The core operation of this database is the Kinetic Join: a continuous spatial query that identifies all pairs of robots
Uses NumPy vectorization to perform matrix expansion of the squared Euclidean distance:
-
Bottleneck: For
$N = 10,000$ , a single calculation generates a dense$10,000 \times 10,000$ float matrix containing$100,000,000$ distance values, causing high execution time and Out-Of-Memory (OOM) faults as the swarm scales.
Leverages SciPy's cKDTree to index the 3D space, which allows querying coordinate neighbors within a radius without evaluating the global distance matrix.
The project implements CUDA execution paths to compile and run GPU kernels:
- Elementwise Kernel: Maps thread indices directly to matrix coordinate computations to run in parallel.
- Grid-Stride Loop Kernel (
kinetic_join_strided_kernel): Assigns a global 1D thread sequence across a grid-stride loop. This allows threads to process multiple data elements sequentially and scale dynamically past physical block layout limits, keeping register utilization highly efficient and cutting the upper-triangle calculation workload exactly in half.
Includes a Peer-to-Peer (P2P) database node model (SwarmDBNode) where multiple AutonomousAgent entities write and read cached states. When an agent updates its local memory node, the node automatically broadcasts the sync update across the cluster. This allows agents to share parameters and bypass redundant computation loops.
- Python:
python 3.9+(Recommended) - CUDA Toolkit: Required if you plan to run the GPU CUDA acceleration engines.
# Clone the repository
git clone https://github.com/LuxShar007/SwarmDB.git
cd SwarmDB
# Create python virtual environment
python -m venv swarm_env
# Activate virtual environment
# On Windows (Command Prompt)
swarm_env\Scripts\activate.bat
# On Windows (PowerShell)
.\swarm_env\Scripts\Activate.ps1
# On Linux/macOS
source swarm_env/bin/activatepip install -r requirements.txtNote
If you have a CUDA-compatible GPU, you can install cupy-cuda12x (or your matching CUDA version) or pycuda to enable the hardware acceleration engines.
To compare performance between the CPU Baseline, CPU Optimized cKDTree, and GPU CUDA (if available) engines, execute:
python benchmark.pySwarmDB hosts a web API to run and query the spatial engine remotely.
uvicorn src.api.main:app --reloadOnce running, you can access the interactive API docs at http://127.0.0.1:8000/docs.
-
POST /swarm/initialize: Initialise a new swarm of$N$ robots. -
POST /swarm/update: Step forward robot coordinate telemetry. -
GET /swarm/positions: Fetch current coordinates of all robots. -
POST /swarm/collisions: Run Kinetic Join using eitherbaseline,optimized, orcuda. -
POST /memory/connect: Link P2P memory nodes. -
POST /memory/write: Write cached parameter to a node. -
POST /memory/read: Read cached parameter from a node. -
GET /swarm/benchmark: Run the benchmark suite through the API.
To run the decentralized multi-agent shared memory synchronization simulation, execute:
python agent_swarm_memory.pyDepending on your hardware setup, running benchmark.py will demonstrate the extreme speedup achieved by the spatial optimizations and CUDA GPU engines (benchmarked on an NVIDIA GeForce RTX 3050 Laptop GPU):
| Swarm Size (N) | CPU Baseline |
CPU Optimized |
GPU CUDA (Grid-Stride) |
|---|---|---|---|
| 1,000 | ~0.040 s | ~2.198 s (init/tree build) | ~1.977 s (warmup JIT) |
| 2,500 | ~0.163 s | ~0.001 s | ~0.001 s |
| 5,000 | ~0.734 s | ~0.003 s | ~0.001 s |
| 10,000 | ~5.450 s | ~0.007 s | ~0.003 s |
| 25,000 | π₯ High Overhead | ~0.019 s | ~0.005 s |
| 50,000 | π₯ OOM / Memory Crash | ~0.044 s | ~0.013 s |