CUDA Pollution Simulation
Diffusion across a grid, one thread per cell.
- Kind
- coursework
- Context
- Collaborative university project
- Domain
- COMPUTE
A screen capture of the simulation running is far more convincing than a still. Short, silent, looping MP4.
/projects/cuda-pollution/simulation.mp4
Overview
A collaborative university project for a parallel algorithms course: a 2D diffusion simulation where every cell of the grid is updated in parallel by a custom CUDA kernel. Pollution sources add concentration, absorbers remove it, and the simulation tracks danger zones and hotspots that persist over time.
The grid is configurable, so the same code runs from a size you can debug by eye up to one where the GPU is doing something worth doing.
Simulation step
- Grid state
- CUDA kernel
- Buffer swap
- Hotspot detection
Technical challenge
A naive diffusion step reads and writes the same grid, which makes the result depend on thread scheduling. The simulation uses double-buffered GPU memory so every read comes from the previous state and updates are race-free.
The second cost is transfer, not arithmetic. Device allocations persist across steps rather than being reallocated per frame, which keeps CPU–GPU traffic down to what actually has to cross the bus.
What it does
- 01Custom CUDA kernels for the diffusion step
- 02Parallel diffusion across a configurable grid
- 03Pollution sources and absorbers
- 04Danger-zone tracking
- 05Persistent hotspot detection
- 06Double-buffered GPU memory for race-free updates
- 07Persistent device allocations to reduce CPU–GPU transfer overhead
Technologies
- Compute
CUDA C
PyCUDA
Custom kernels
- Host
Python
NumPy