HadrienG2 / grayscott

Rust version of the "Performance with stencil" course's examples
9 stars 1 forks source link

Performance with stencil (Rust version)

This is a Rust version of the examples from the "Performance with Stencil" course, with a few new tricks of mine.

Prerequisites

In addition to a recent Rust toolchain, you will need to install development packages for the following C/++ libraries:

Additinally, GPU examples use the Vulkan API through the vulkano library, which comes with extra build requirements.

In addition to the Vulkano build requirements, actually running the GPU examples requires at least one working Vulkan implementation. Any reasonably modern Linux GPU driver will do, or if you just want them to run and don't care about actual performance, you may alternatively using the llvmpipe software renderer.

Debug builds additionally enable Vulkan validation layers for richer debug logs, so these must be installed too.

Overall, if you want to be able to run these examples in all possible configurations, you will want to install the following native packages:

# Example given for Ubuntu, other linux distributions will be similar except the
# packages will be named a little differently
sudo apt install git build-essential curl \
    libhdf5-dev libhwloc-dev libudev-dev pkgconf \
    cmake ninja-build python3 \
    vulkan-validationlayers-dev libvulkan-dev vulkan-tools
# A rust toolchain can be installed in a distribution-agnostic fashion
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

The microbenchmarks are implemented using criterion, and we use the newer cargo-criterion runner mechanism, which requires a separate binary that you can install using this command:

$ cargo install cargo-criterion

Structure

In the same spirit as the C++ version, the code is sliced into several crates:

Usage

To run the simulation, build and run the simulate program as follows...

$ cargo run --release --bin simulate --features <backend> -- <CLI args>

...where <backend> is the name of a compute backend, such as "compute_block", and <CLI args> accepts the same arguments as the C++ version. You can put a --help in there for self-documentation.

Then, to convert the HDF5 output into PNG images for visualization purposes, you can use the data-to-pics program, using something like the following...

$ mkdir -p pics
$ cargo run --release --bin data-to-pics -- -i <input> -o pics

...where <input> is the name of the input HDF5 file produced by simulate (output.h5 by default).

Alternatively, you can run a live version of the simulation which produces a visual render similar to the aforementioned PNG images in real time, using the following command:

$ cargo run --release --bin livesim --features <backend> -- <CLI args>

To run all the microbenchmarks, you can use this command:

$ cargo criterion

Alternatively, you can run microbenchmarks for a specific compute backend xyz, which can speed up compilation by avoiding compilation of unused backends:

$ cargo criterion --package xyz

You can also selectively run benchmarks based on a regular expression, like so:

$ cargo criterion -- '(parallel|gpu).*2048x.*32'

The microbenchmark runner exports a more detailed HTML report in target/criterion/reports/index.html that you may want to have a look at.


The build system is configured to generate binaries that are optimized for your CPU, using the Rust equivalent of GCC's -march=native. You can change this using the .cargo/config.toml configuration file.