Skip to content

MendaciousQuark/TNSim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

525 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TNSim (Train Network Simulator)

This is a real-time, GPGPU-accelerated train network simulator developed as part of a master's-level university group project. It is built in C++17 and CUDA, using CMake as the build system.

Prerequisites

Before you can build this project, you will need the following software installed:

  • A C++17 Compiler (e.g., Visual Studio 2019/2022, GCC 9+, Clang 10+).

  • CMake 3.18 or newer.

  • The NVIDIA CUDA Toolkit (e.g., CUDA 11.x or 12.x).

How to Build

The project is configured using CMake.

1. On University Systems (Linux)

University machines often use a module system to manage software.

Load the necessary modules. You must load the C++ compiler (if not default) and the CUDA toolkit. The exact names may differ, but the command will look like this:

This is an example! Use module avail to find the right names.

module load gcc/11.4.0
module load cuda/11.8

Run the standard CMake build:

1. Go to the project's root directory

cd /path/to/TNSim

2. Create and enter the build directory

mkdir build
cd build

3. Configure the project

(This finds CUDA and generates the Makefiles)

cmake ..
(optional: to specify cmake generator and avoid nmake, use "cmake .. -G "Visual Studio 17 2022" -A x64" or similar)

4. Compile the code

cmake --build .

5. Run

./TNSim

Semi-Automatic Build + Performance Pipeline

To run a clean local pipeline that rebuilds from scratch and runs a performance check only when you execute it:

./scripts/semi_auto_pipeline.sh

This script does:

  1. Delete build/
  2. Recreate build/
  3. Configure with CMake
  4. Run an initial build of target TNSim
  5. Run the full build
  6. Execute ./TNSim, then print:
    • PERF_SUMMARY (tick timing from the simulator)
    • PERF_RSS_KB (peak RAM from /usr/bin/time)
    • elapsed time and CPU%

You can pass configure arguments through the script, for example:

./scripts/semi_auto_pipeline.sh -DCMAKE_CUDA_ARCHITECTURES=86

You can also pass runtime args to ./TNSim after --, for example:

./scripts/semi_auto_pipeline.sh -DCMAKE_CUDA_ARCHITECTURES=86 -- --tick-ms 10 --max-ticks 800

Runtime Performance Options

./TNSim now prints a PERF_SUMMARY line at shutdown with average/p95/min/max tick timings in milliseconds.

Optional runtime flags:

./TNSim --tick-ms 14 --max-ticks 500
  • --tick-ms: target tick duration in ms
  • --max-ticks: safety cap for benchmark/test run length

Using the DEBUG crash catcher

cd build
cmake --build . --config Debug
.\Debug\TNSim.exe 2>&1 | Tee-Object -FilePath crash.log

2. On a Personal Machine (Windows/Linux)

Make sure all prerequisites (Visual Studio, CUDA Toolkit, CMake) are installed and added to your system's PATH.

Follow the same build steps as above. On Windows, CMake will automatically generate a Visual Studio Solution (.sln) inside the build/ folder.

Overriding GPU Architecture

The project defaults to compiling for NVIDIA 40-series GPUs (Architecture "89"). If you are building on a machine with a different card (e.g., a 20-series "75" or 30-series "86"), you should override this default when you configure the project.

This ensures you are AOT-compiling for your specific hardware.

Example: Overriding for an RTX 2070 (Turing)

cd build
cmake .. -DCMAKE_CUDA_ARCHITECTURES="75"

Example: Overriding for an RTX 3080 (Ampere)

cmake .. -DCMAKE_CUDA_ARCHITECTURES="86"

About

Group Project for MEng Computer Science with AI (4th Year) at the University of Leeds

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors