skip to content

GPU-Accelerated Drone Swarm Simulation

[completed]
  • CUDA
  • Python
  • CuPy>=12.0.0
  • Numba>=0.64.0
  • NumPy>=2.4.1
  • WebSocket
  • Three.js^0.170.0
  • React^18.3.1

Project Overview

My senior design project at TED University, built as a team project with Turkish Aerospace (TUSAŞ) under the TUSAŞ Lift-Up program. It took 2nd place at the GBYF (Genç Beyinler Yeni Fikirler) graduation-project exhibition in Ankara, 2026.

our team on stage at TED University with the 2nd-place award cheque at the GBYF 2026 exhibition, organised with Türkiye Bilişim Derneği Ankara

A full simulator can't step hundreds of drones in real time on a laptop, and most of our time went into getting the toolchain to agree with itself rather than into the swarm. The finished project is a lightweight, in-process Python simulator: physics, control, sensors, collision handling and state streaming all run in one process, with the hot paths on the GPU. It's not a flight-accurate aerodynamic model. It's a fast, inspectable swarm testbed for comparing CPU and GPU execution strategies at scale.

It's also where swarmscale started: its APF controller is swarmscale's parity oracle.

Stack

  • Simulation: Python 3.12, NumPy, a 250 Hz physics step with a 50 Hz control loop
  • Parallelization: CuPy with hand-written CUDA RawKernels on the GPU, Numba prange on the CPU
  • Execution modes: CPU, GPU, HYBRID (NumPy physics + GPU controller) and AUTO, which picks a backend from the swarm size
  • Visualization: Pygame 2D / 2.5D views, a Matplotlib live dashboard, and a React + React Three Fiber browser viewer fed over WebSocket
  • Analysis: a benchmark package with four backends, plus MATLAB surface plots of the sweeps

How It Works

1. Control

Each drone runs a velocity-profiled position controller, v = √(2·a_max·d), the same braking profile ArduPilot and PX4 use. It reaches zero velocity on arrival instead of oscillating around the target. A 0.15 m deadband hard-zeroes settled drones. Drone-to-drone and drone-to-obstacle avoidance use Khatib-style artificial potential fields (η·(1/q − 1/q₀)/q²), with tangent steering around spheres, cylinders and boxes to get out of the classic local minima.

2. Formations without crossings

Switching between grid, circle, V, column, arrow, helix and rings formations doesn't snap drones to new slots. The planner assigns drones to slots to minimize path crossings, splits them into altitude layers, raises the layers, moves them horizontally, then descends. Without this, a formation change sends dozens of drones through the same patch of sky.

3. One kernel instead of thirty

The first GPU version was "NumPy on the GPU": it built an (N, N, 3) pairwise tensor and ran 30+ separate CuPy ops per step. At 5,000 drones that's a ~300 MB intermediate and 30 kernel launches, and it lost to Numba on the CPU (68 ms vs 16 ms per step). The fix was a fused CUDA RawKernel with one thread per drone. Each thread walks its N−1 neighbors and accumulates separation, cohesion, alignment and target tracking in registers, followed by one small integrate kernel. That's 2 launches per step and no intermediate buffer, and the step went from 68 ms to 0.94 ms (73×) on the same RTX 4070 Laptop GPU.

4. Live viewer and replay

My largest piece was the observation side. The simulator publishes one WebSocket stream of typed JSON envelopes (meta, state at 30 Hz, obstacles only when they change) and records the same stream to a .jsonl file per session. A React + React Three Fiber viewer either connects live or replays a recording with seek and speed controls. It draws instanced GLTF drones with spinning rotors, a heightmap terrain, target lines, and live telemetry panels (altitude, speed, battery). I also built the in-simulator performance panel and fixed a crash-cascade bug where already-crashed drones kept triggering new crashes.

Key Results

Latest committed sweep (RTX 4070 Laptop, ms per simulation step):

DronesBest CPU (Numba, 8 threads)Fused CUDA kernelSpeedup
5000.250.141.7×
1,0001.000.234.4×
5,00027.770.9230×
  • Crossover: the GPU starts winning at around 300 drones. AUTO mode switches at 500 to leave a safety margin, because below that, kernel-launch overhead costs more than the work itself.
  • Parity: after 100 steps from the same seed, the GPU and CPU-parallel trajectories differ by at most 2 mm at N = 1,000. That's float32 summation order, not an algorithmic difference.
  • The big number on the poster: ~20,000× over the serial Python loop at 5,000 drones. Be careful with it: serial was too slow to run at that size, so its time comes from a quadratic fit (R² ≈ 0.999995) to the measured points. The 30× over the best parallel CPU is the honest comparison.

Limitations

  • The benchmark measures a standard Boids-style O(N²) workload, not the exact production controller. The production controller's cohesion is mostly switched off, and its avoidance radius is tuned for small fleets. The kernel cost is representative, but "5,000 drones in 0.92 ms" is the workload, not the full simulator with sensors and rendering.
  • Every drone checks every other drone. There's no spatial hashing, so the cost still grows quadratically. swarmscale exists partly to fix that.
  • Below a few hundred drones the GPU buys nothing. For the 25–50-drone demo swarms, CPU mode is just as fast.

What I Learned

  • Dropping the full robotics simulator was the best decision we made. We traded physical fidelity for being able to iterate and measure, and for a project whose question was "does parallelization pay off?", measuring was the whole point.
  • Moving code to the GPU doesn't make it fast; how you write the kernel does. The same GPU went from losing to the CPU to beating it by 30×, just by fusing kernels and keeping data in registers.
  • Watching a swarm with your own eyes catches bugs that metrics miss. Several controller bugs, like oscillation, crash cascades and wrong altitudes, only became obvious once we could replay a run and follow a single drone.