This project ships a Criterion benchmark suite in benches/advection.rs that covers:
- per-stage GPU kernels (advection, Hanna, Langevin, dry/wet deposition, concentration gridding),
- an end-to-end forward time-loop benchmark (
ForwardTimeLoopDriver::run_timestep), - CPU reference baselines for the same stages and an end-to-end CPU step benchmark.
Three named scenarios are always present: 1M, 10M, 100M.
Each scenario runs at min(target_particles, FLEXPART_BENCH_MAX_PARTICLES). When clamped
below target, the label becomes 10M (scaled_250.00K) etc. A scaled run does NOT
represent the named scenario — at low particle counts the GPU dispatch overhead dominates
and the results are meaningless for speedup analysis.
Benchmarks are deterministic by construction:
- fixed synthetic meteorology and surface fields,
- deterministic particle initialization (index-driven hash, no system RNG),
- fixed Philox key/counter for Langevin updates,
- fixed deterministic deposition/scavenging forcing vectors.
Given the same binary, backend, and environment variables, inputs are identical across runs.
| Pitfall | Why it invalidates results |
|---|---|
| Running at 1K particles | GPU dispatch latency (~50–200 µs) dominates; you measure overhead, not compute throughput. |
Comparing base vs new in Criterion |
They represent consecutive runs of the same benchmark, not GPU vs CPU. |
| Mixing readback modes | GPU with SYNC_HOST=1 does a full buffer download each step; comparing that to GPU-no-readback conflates transfer cost with compute cost. |
| Single sample | Wall-clock variance (thermal throttling, OS scheduling) requires ≥10 samples. |
| Not warming up the GPU | First dispatch compiles shaders / allocates; warm-up of ≥2 s is needed. |
Three independent quantities give the full picture:
- GPU throughput (fire-and-forget) — readbacks off, pure pipeline speed.
- GPU strict (readbacks on) — realistic worst-case where host needs data each step.
- CPU reference (Rust) — single-threaded CPU baseline for the same pipeline.
From these:
- Speedup (fire-and-forget) = CPU / GPU-no-readback
- Speedup (strict) = CPU / GPU-strict
- Readback overhead = GPU-strict − GPU-no-readback
GPU compute becomes dominant over dispatch overhead roughly above 100K particles. Meaningful speedup numbers require ≥ 1M particles. The canonical comparison points are 1M and 10M.
For stable estimates at large particle counts:
| Parameter | Value | Rationale |
|---|---|---|
SAMPLE_SIZE |
20 | Enough for CI/stddev estimates without excessive runtime |
WARMUP_SECS |
3 | Shader compilation + thermal stabilization |
MEASUREMENT_SECS |
10 | Enough iterations even at 10M particles |
All commands below invoke cargo bench, which implies --release. Ensure
the build is up to date before comparing runs — a stale binary invalidates
everything.
Measures pure GPU pipeline throughput at 1M and 10M particles.
FLEXPART_BENCH_MAX_PARTICLES=10000000 \
FLEXPART_BENCH_SAMPLE_SIZE=20 \
FLEXPART_BENCH_WARMUP_SECS=3 \
FLEXPART_BENCH_MEASUREMENT_SECS=10 \
FLEXPART_BENCH_TIMELOOP_SYNC_HOST=0 \
FLEXPART_BENCH_TIMELOOP_COLLECT_PROBABILITIES=0 \
cargo bench --bench advection -- 'pipeline_end_to_end_timeloop/forward_step'Measures GPU pipeline with host synchronization and probability collection enabled.
FLEXPART_BENCH_MAX_PARTICLES=10000000 \
FLEXPART_BENCH_SAMPLE_SIZE=20 \
FLEXPART_BENCH_WARMUP_SECS=3 \
FLEXPART_BENCH_MEASUREMENT_SECS=10 \
FLEXPART_BENCH_TIMELOOP_SYNC_HOST=1 \
FLEXPART_BENCH_TIMELOOP_COLLECT_PROBABILITIES=1 \
cargo bench --bench advection -- 'pipeline_end_to_end_timeloop/forward_step'Important: Run B writes to the same Criterion directory as Run A.
Criterion will treat Run A's results asbaseand Run B asnew, which is useful for seeing the delta but not a GPU-vs-CPU comparison. To preserve both, copytarget/criterion/pipeline_end_to_end_timeloopafter Run A:cp -r target/criterion/pipeline_end_to_end_timeloop{,_no_readback}
Measures the single-threaded Rust CPU pipeline at the same particle counts.
FLEXPART_BENCH_MAX_PARTICLES=10000000 \
FLEXPART_BENCH_SAMPLE_SIZE=20 \
FLEXPART_BENCH_WARMUP_SECS=3 \
FLEXPART_BENCH_MEASUREMENT_SECS=10 \
cargo bench --bench advection -- 'pipeline_end_to_end_timeloop_cpu'Criterion writes JSON estimates to:
target/criterion/<group>/<bench_id>/<scenario>/new/estimates.json
The mean.point_estimate field is in nanoseconds. To compare:
speedup = cpu_mean_ns / gpu_mean_ns
readback_cost_ns = gpu_strict_mean_ns - gpu_noreadback_mean_ns
readback_overhead_pct = readback_cost_ns / gpu_noreadback_mean_ns * 100
To identify which kernel is the bottleneck, run the per-stage benchmarks at the same particle count:
FLEXPART_BENCH_MAX_PARTICLES=10000000 \
FLEXPART_BENCH_SAMPLE_SIZE=20 \
FLEXPART_BENCH_WARMUP_SECS=3 \
FLEXPART_BENCH_MEASUREMENT_SECS=10 \
cargo bench --bench advection -- 'pipeline_stage_'This benches: advection, hanna, langevin, dry_deposition, wet_deposition, concentration_gridding — each with GPU and CPU variants.
| Variable | Default | Description |
|---|---|---|
FLEXPART_BENCH_MAX_PARTICLES |
1000000 |
Caps effective particle count per scenario. |
FLEXPART_BENCH_SAMPLE_SIZE |
10 |
Criterion sample size (minimum 10). |
FLEXPART_BENCH_WARMUP_SECS |
1 |
Criterion warm-up duration. |
FLEXPART_BENCH_MEASUREMENT_SECS |
3 |
Criterion measurement duration. |
FLEXPART_BENCH_TIMELOOP_SYNC_HOST |
0 |
1 = sync host particle store each step (GPU readback). |
FLEXPART_BENCH_TIMELOOP_COLLECT_PROBABILITIES |
0 |
1 = download dry/wet probability vectors each step. |
FLEXPART_BENCH_AUTOTUNE |
0 |
1 = run workgroup auto-tuning before benchmarks. |
FLEXPART_BENCH_AUTOTUNE_PARTICLES |
min(MAX, 250k) | Particle count for auto-tuning harness. |
FLEXPART_BENCH_AUTOTUNE_CANDIDATES |
— | Comma-separated candidate workgroup sizes. |
FLEXPART_WG_AUTOTUNE_DETERMINISTIC |
1 |
Deterministic tie-breaking in auto-tune. |
FLEXPART_WG_AUTOTUNE_DISABLE_CACHE |
0 |
1 = ignore saved autotune cache and use defaults/overrides only. |
FLEXPART_WG_AUTOTUNE_CACHE |
~/.cache/flexpart-gpu/… |
Override auto-tune cache path. |
FLEXPART_WG_SIZE_DEFAULT |
— | Default workgroup size for all key kernels. |
FLEXPART_WG_SIZE_<KERNEL> |
— | Per-kernel override (ADVECTION, LANGEVIN, HANNA_PARAMS, DRY_DEPOSITION, WET_DEPOSITION, CONCENTRATION_GRIDDING, PBL_DIAGNOSTICS, PBL_REFLECTION, PARTICLE_STEP). |
FLEXPART_GPU_VALIDATION |
0 |
1 = use separated Hanna → Langevin dispatches instead of fused production path. |
If no GPU adapter is available, GPU groups emit a placeholder entry; CPU baselines still run.
In addition to the Criterion micro-benchmarks above, the project includes a
Fortran FLEXPART vs GPU end-to-end comparison using the fortran-validation
binary and the compare-fortran.sh orchestration script. Both engines run on an
identical synthetic scenario; comparison scripts produce statistical metrics and
particle position comparisons.
Canonical 1M report:
benchmark-fortran-vs-gpu-current.md- Conservative speedup (all reps): 8.32x
- Warm steady-state speedup: 11.16x
Latest replicated 10M report:
benchmark-fortran-vs-gpu-10m-production-20260307.md- Conservative speedup (all reps): 9.67x
- Warm steady-state speedup: 9.88x
- Docker with
docker compose(for the Fortran side). - The Fortran Docker image must be built:
cd ../flexpart-fortran-docker && docker compose build
- The Fortran FLEXPART binary must be compiled (done once during setup):
scripts/compare-fortran.sh compose setup
Measures GPU end-to-end time at 1M particles, no Fortran needed:
# Production mode (readback off) — measures pure GPU pipeline
OUTPUT_PATH=/dev/null PARTICLES=1000000 SYNC_READBACK=0 \
/usr/bin/time -f 'REAL_SECONDS=%e' \
cargo run --release --bin fortran-validation
# Validation mode (readback on) — includes GPU→CPU transfer at each step
OUTPUT_PATH=/dev/null PARTICLES=1000000 SYNC_READBACK=1 \
/usr/bin/time -f 'REAL_SECONDS=%e' \
cargo run --release --bin fortran-validationMeasures per-step GPU compute time with deposition, spatially-varying met:
PARTICLES=1000000 WARMUP_STEPS=5 MEASURE_STEPS=30 \
cargo run --release --bin bench-timeloopOptional forcing shape toggle for bench-timeloop:
# Default: per-particle forcing vectors
FORCING_MODE=per_particle cargo run --release --bin bench-timeloop
# Uniform forcing values (same scalar for all particle slots)
FORCING_MODE=uniform cargo run --release --bin bench-timeloopOptional runtime workgroup override A/B:
# Use autotune cache/default runtime config
PARTICLES=10000000 WARMUP_STEPS=3 MEASURE_STEPS=20 \
cargo run --release --bin bench-timeloop
# Force explicit kernel sizes (example candidate pair)
FLEXPART_WG_AUTOTUNE_DISABLE_CACHE=1 \
FLEXPART_WG_SIZE_ADVECTION=128 \
FLEXPART_WG_SIZE_LANGEVIN=256 \
PARTICLES=10000000 WARMUP_STEPS=3 MEASURE_STEPS=20 \
cargo run --release --bin bench-timeloopRun both engines and produce a scientific comparison:
# Step 1: Run GPU with readback on (exports particle positions)
OUTPUT_PATH=target/validation/gpu_1m_readback_on.json \
PARTICLES=1000000 SYNC_READBACK=1 \
/usr/bin/time -f 'REAL_SECONDS=%e' \
cargo run --release --bin fortran-validation
# Step 2: Set Fortran particle count to match
# Edit ../flexpart-fortran-docker/comparison/validate_run/options/RELEASES
# Set PARTS = 1000000
# Step 3: Run Fortran
cd ../flexpart-fortran-docker
/usr/bin/time -f 'REAL_SECONDS=%e' \
docker compose run --rm flexpart-fortran bash -c \
'cd /workspace/comparison/validate_run && /workspace/flexpart/src/FLEXPART'
cd ../flexpart-gpu
# Step 4: Run scientific comparison (partposit-based)
.venv/bin/python scripts/compare_concentrations.py \
--fortran-output ../flexpart-fortran-docker/comparison/validate_run/output \
--gpu-output target/validation/gpu_1m_readback_on.json \
--output-json target/validation/comparison_1m_report.json \
--verbose
# Step 5: Run clean aligned comparison (same gridding operator)
.venv/bin/python scripts/compare_clean_partposit.py \
--repo-root . \
--fortran-output ../flexpart-fortran-docker/comparison/validate_run/output \
--gpu-output target/validation/gpu_1m_readback_on.json \
--output-json target/validation/comparison_1m_clean_report.jsonThe compare-fortran.sh script automates the full workflow:
# Full setup + Fortran run + GPU tests
scripts/compare-fortran.sh compose all
# Scientific validation only (builds, runs, compares)
scripts/compare-fortran.sh compose validateThe same wrapper now supports a GPU-only performance action:
# Default: 1M particles, strict + production + profiled timeloop
scripts/compare-fortran.sh compose perf
# Optional overrides for faster smoke runs
PERF_PARTICLES=100000 PERF_WARMUP_STEPS=1 PERF_MEASURE_STEPS=3 \
scripts/compare-fortran.sh compose perfetex-run supports streaming meteorological snapshot prefetch with a runtime toggle:
# Prefetch enabled (default)
ETEX_STREAM_PREFETCH=1 \
cargo run --release --bin etex-run
# Prefetch disabled (A/B reference)
ETEX_STREAM_PREFETCH=0 \
cargo run --release --bin etex-runUse the same PARTICLES and OUTPUT_PATH settings for fair ON/OFF comparison.
At the end of each run, etex-run reports:
met prefetch stats: hits=<N>, misses=<M>met load timing: init=<ms> prefetch_wait=<ms> sync_wait=<ms> total_wait=<ms>
This helps verify that asynchronous loading is actually used during bracket transitions.
Recommended quick campaign (alternating OFF/ON):
for mode in 0 1 0 1 0 1; do
ETEX_STREAM_PREFETCH=$mode PARTICLES=50000 \
OUTPUT_PATH="target/etex/gpu_output_prefetch_${mode}.json" \
/usr/bin/time -f 'REAL_SECONDS=%e' \
cargo run --release --bin etex-run
done| Variable | Default | Description |
|---|---|---|
PARTICLES |
10000 |
Number of particles to release |
OUTPUT_PATH |
target/validation/gpu_concentration.json |
Output JSON path |
SYNC_READBACK |
1 |
0 = fire-and-forget (production), 1 = full readback each step (validation) |
| Variable | Default | Description |
|---|---|---|
PARTICLES |
1000000 |
Number of particles |
WARMUP_STEPS |
3 |
Warm-up steps (not measured) |
MEASURE_STEPS |
20 |
Steps to measure |
TIMESTEP_SECONDS |
1 |
Simulation timestep |
FORCING_MODE |
per_particle |
per_particle or uniform forcing fields for deposition inputs |
Detailed benchmark results are in docs/benchmarks/:
benchmark-fortran-vs-gpu-current.md— canonical replicated baseline for Fortran serial vs GPU production at 1M.benchmark-fortran-vs-gpu-10m-production-20260307.md— replicated Fortran serial vs GPU production campaign at 10M.benchmark-1m-fortran-vs-gpu0.md— scientific comparison at 1M particles (clean aligned gridding, COM, correlation, known differences).benchmark-scientific-validation.md— physics-focused validation report: advection, vertical/horizontal diffusion, vertical profile analysis, aligned physics inventory.