← All works

CUDA Flocking

A flocking simulation in CUDA after Craig Reynolds’ boids model: cohesion, separation and alignment for up to ten million boids, with three neighbour searches compared.

  • Rendering & GPU
  • C++
  • CUDA
  • GPU Programming
  • Parallel Computing
  • Spatial Data Structures
  • Performance Optimization
Clouds of coloured boids flocking inside a cube
Year
2024
Type
Individual project
Course
CIS 5650 GPU Programming and Architecture at UPenn
Tested on
RTX 4090, i7-13700K, Windows 11
  • 43 → 2,677 fps100,000 boids, brute force against the coherent uniform grid
  • 18 fpsat 10 million boids on the coherent grid, where brute force shows 0
  • 3neighbour-search implementations compared

Overview

  • Three rulesCohesion, separation and alignment
  • Brute forceEvery boid checks every other boid
  • Scattered uniform gridBoids are binned into cells, so only nearby cells are searched
  • Coherent uniform gridBoid data is reordered to follow the cells, which makes memory access contiguous

Finer cells helped more than expected. Above 100,000 boids, a cell width of 1× the rule distance beat 2×, although 27 cells are checked instead of 8: the coherent grid then reaches 791 fps at 1 million boids and 18 fps at 10 million.

Frames per second, cell width 2×, no visualization

BoidsBrute forceScattered gridCoherent grid
5,0001,206.42,788.52,758.6
100,00043.02,578.52,676.8
1,000,0000.6312.1455.7
10,000,0000.04.06.5