|
| 1 | +# SYCL-Crowd-Simulation |
| 2 | + |
| 3 | +SYCL GPU-accelerated crowd simulation engine based on Helbing et. al.'s social force model. |
| 4 | + |
| 5 | +Dirk Helbing introduced the social force model in a paper in 1995, aimed at modelling the behaviour of crowds using Langevin equations. He proposed a refined model in a 2000 paper, "Simulating Dynamical Features of Escape Panic". Helbing posits that human behaviour in large crowds is determined by three component forces: A personal impulse towards one's destination, the cumulative force exerted by neighbouring people, and the repulsive force of any nearby walls. Together, these forces form the basis of a differential equation which can subsequently be integrated in order to calculate the actor's velocity. |
| 6 | + |
| 7 | +## Features |
| 8 | + |
| 9 | +- Performantly simulate tens of thousands of actors in real time |
| 10 | +- Define different crowds with different characteristics and different destinations |
| 11 | +- Define rooms and obstacles |
| 12 | +- Fully configurable environments (see [Input Format](#input-format)) |
| 13 | +- Record and graph simulation metrics |
| 14 | +- Target and build for multiple SYCL supported backends |
| 15 | +- Apply a force heatmap across actors |
| 16 | +- The simulation kernels may be used separately from the GUI |
| 17 | + |
| 18 | +## Dependencies |
| 19 | + |
| 20 | +- The [DPC++ compiler](https://intel.github.io/llvm-docs/GetStartedGuide.html) is required to compile SYCL code |
| 21 | +- If targeting the DPC++ CUDA backend, the [CUDA runtime](https://intel.github.io/llvm-docs/GetStartedGuide.html#build-dpc-toolchain-with-support-for-nvidia-cuda) is required |
| 22 | +- If targeting the DPC++ OpenCL backend, an [OpenCL runtime](https://intel.github.io/llvm-docs/GetStartedGuide.html#install-low-level-runtime) is required |
| 23 | +- Graphics are rendered with [SDL2](https://lazyfoo.net/tutorials/SDL/01_hello_SDL/linux/index.php), installed with apt: `$ apt install libsdl2-dev` |
| 24 | +- Input files are parsed using [RapidJSON](https://rapidjson.org/index.html) |
| 25 | +RapidJSON is a header-only library, so can be installed by simply copying the directory `include/rapidjson` into your system include path |
| 26 | +- Python is needed to run scripts |
| 27 | +- Graphs are plotted using matplotlib, installed via pip: `$ pip install matplotlib` |
| 28 | +- To run simulations in headless mode and record video output, install [xvfb](https://www.x.org/releases/X11R7.6/doc/man/man1/Xvfb.1.xhtml) and [ffmpeg](https://ffmpeg.org/download.html) using apt |
| 29 | + |
| 30 | +## Building |
| 31 | + |
| 32 | +Build configuration is carried out using CMake. |
| 33 | + |
| 34 | +The option `-DSYCL_BACKEND` allows you to select which backend to build for (spir, cuda or hip). By default, it builds for spir. |
| 35 | + |
| 36 | +When enabled, the `-DPROFILING_MODE` option builds a headless version which can be run without the SDL dependency. |
| 37 | + |
| 38 | +When enabled, the `-DSTATS` option will collect metrics whilst the simulation is running. Results are written to `output/outputStats`.txt. Graphs can be produced from these metrics by running the python script [PlotGraphs.py](scripts/PlotGraphs.py). |
| 39 | + |
| 40 | +By default, CMake should generate example input files by running [InputFileGenerator.py](scripts/InputFileGenerator.py) when generating the project makefiles. |
| 41 | + |
| 42 | +The `crowdsim` executable takes an input configuration JSON as a command line argument. |
| 43 | + |
| 44 | +``` |
| 45 | +$ git clone https://[repo link] |
| 46 | +$ cd crowd-simulation |
| 47 | +$ mkdir build && cd build |
| 48 | +$ cmake -DCMAKE_CXX_COMPILER=path/to/llvm/build/bin/clang++ -DSYCL_BACKEND=spir -DPROFILING_MODE=off -DSTATS=on .. |
| 49 | +$ cmake --build . |
| 50 | +$ ./crowdsim ../input/evacuateRoom.json |
| 51 | +``` |
| 52 | + |
| 53 | +## Input Format |
| 54 | + |
| 55 | +Below is an annotated example input file which creates a room containing two actors with two different destinations. |
| 56 | + |
| 57 | +``` |
| 58 | +{ |
| 59 | + "config": { <-- Configure environment |
| 60 | + "width": 9, |
| 61 | + "height": 9, |
| 62 | + "scale": 100, |
| 63 | + "delay": 0, |
| 64 | + "bgColor": [0, 0, 0], |
| 65 | + "wallColor": [255, 255, 255], |
| 66 | + "heatmapEnabled": true <-- Flag denoting whether |
| 67 | + }, the heatmap should be |
| 68 | + applied to actors |
| 69 | + "room": { |
| 70 | + "walls": [ |
| 71 | + [0.5, 0.5, 8.5, 0.5], <-- Walls are defined via their |
| 72 | + [8.5, 0.5, 8.5, 8.5], start and end points |
| 73 | + [8.5, 8.5, 0.5, 8.5], |
| 74 | + [0.5, 8.5, 0.5, 0.5] |
| 75 | + ] |
| 76 | + }, |
| 77 | + |
| 78 | + "actors": [ <-- Populate environment with |
| 79 | + { actors |
| 80 | + "pos": [3.4, 5.6], |
| 81 | + "velocity": [0.0123, 0.0567], |
| 82 | + "desiredSpeed": 0.6, |
| 83 | + "pathId": 0, |
| 84 | + "mass": 50, |
| 85 | + "radius": 0.05, |
| 86 | + "atDestination": false, |
| 87 | + "color": [255, 0, 0], |
| 88 | + "heatmapEnabled": true |
| 89 | + }, |
| 90 | + { |
| 91 | + "pos": [0.7, 7.3], |
| 92 | + "velocity": [0.0789, 0.0444], |
| 93 | + "desiredSpeed": 0.6, |
| 94 | + "pathId": 1, |
| 95 | + "mass": 45, |
| 96 | + "radius": 0.06, |
| 97 | + "atDestination": false, |
| 98 | + "color": [0, 255, 0], |
| 99 | + "heatmapEnabled": true |
| 100 | + } |
| 101 | + ], |
| 102 | +
|
| 103 | + "paths": [ |
| 104 | + { |
| 105 | + "id": 0, <-- Each path has a unique id, |
| 106 | + "checkpoints": [[[7.9, 5.6], [8.1, 5.8]]] referenced by any actor which |
| 107 | + }, takes that path |
| 108 | + { |
| 109 | + "id": 1, |
| 110 | + "checkpoints": [[[7.9, 5.6], [8.1, 5.8]], <-- Paths consist of checkpoints |
| 111 | + [[1.5, 2], [1.7, 2.2]]] Each checkpoint is a rectangular |
| 112 | + } region defined as: |
| 113 | + ] [[minX, minY], [maxX, maxY]] |
| 114 | +} |
| 115 | +``` |
| 116 | + |
| 117 | +Larger input configurations can be generated with python scripts, as demonstrated in [InputFileGenerator.py](scripts/InputFileGenerator.py). |
| 118 | + |
| 119 | +The social force model itself can be tweaked by altering the constexprs defined in [DifferentialEq.hpp](external/DifferentialEq.hpp). For example, in simulations involving large numbers of actors (10,000+), the values `WALLAi` and `PEOPLEAi` will need to be increased to prevent any clipping issues. |
| 120 | + |
| 121 | +## Benchmarks |
| 122 | + |
| 123 | +## Citations |
| 124 | + |
| 125 | +- Helbing, D., Farkas, I. & Vicsek, T. Simulating dynamical features of escape panic. Nature 407, 487–490 (2000). https://doi.org/10.1038/35035023 |
| 126 | +- Marsaglia, G. (2003). Xorshift RNGs. Journal of Statistical Software, 8(14), 1–6. https://doi.org/10.18637/jss.v008.i14 |
0 commit comments