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.
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