Batched 1D compressible-Euler WENO5 finite volume with an invented EOS
/app/cpu/main.cpp is the source of a multicore CPU program (C++17, OpenMP).
The program takes one input-file path (PROGRAM INPUT_FILE) and writes its result to stdout.
What the program computes
The program advances a batch of independent 1D compressible-Euler systems with a
5th-order WENO finite-volume scheme for a fixed number of SSP-RK3 steps with a fixed
time step. Each system is a periodic domain [0,1) of NX cells with conserved state
(rho, rho*u, E).
Equation of state (invented). Pressure is an ideal thermal part plus a polytropic cold-pressure correction:
p = (GAMMA-1)*(E - 0.5*rho*u^2) + BETA*rho^GSTIFF
with GAMMA = 1.4, BETA = 0.4, GSTIFF = 2. The wave-speed estimate used by the flux
is a = |u| + sqrt(GAMMA*p/rho + BETA*GSTIFF*rho^(GSTIFF-1)).
Reconstruction. Primitive variables (rho, u, p) are reconstructed to both sides of
every interface with WENO5-JS (Jiang-Shu smoothness indicators, linear weights
0.1, 0.6, 0.3, eps = 1e-6). Tiny positivity floors (1e-9) are applied to
reconstructed density and pressure.
Flux. A local Lax-Friedrichs (Rusanov) interface flux uses the Euler flux
F = (rho*u, rho*u^2 + p, u*(E+p)) and alpha = max(a_L, a_R).
Time integration. SSP-RK3 with fixed dt = 0.08*dx, for NSTEP steps. Each stage
computes the flux divergence with periodic boundaries.
Initial condition. Each system gets its own smooth periodic field: rho, u, p
are sums of 4 Fourier modes with hashed amplitudes (decaying in mode number) and phases
from a SplitMix64 counter hash of the seed, around rho = 1, u = 0, p = 1. The
evolution stays smooth (pre-shock) over the fixed step count, so cell sampling is not
chaotic. All reductions use a fixed order (thread-count independent).
Input format
NSYS NX NSTEP seed
One line: number of systems NSYS >= 1, cells per system NX >= 8, step count
NSTEP >= 1, and a 64-bit seed.
Output format
nsys <NSYS> nx <NX> nstep <NSTEP>
sum_rho <total mass> sum_mom <total momentum> sum_E <total energy>
l2_rho <L2 norm of rho> l2_mom <L2 norm of mom> l2_E <L2 norm of E>
cell <s> <i> <rho> <mom> <E> (6 sampled cells)
Floating-point fields use %.10e. Comparison is numeric with rtol = 1e-5,
atol = 1e-7.
Hidden inputs
Correctness inputs (10 files) include a single tiny system (NX = 8), small batches with
NX in [16, 512] and NSTEP in [4, 300], a single large system (NX = 1536), and a
64-system batch. The timing input is 256 systems of 1536 cells advanced 1400
steps.
Your task
Port this program to CUDA in /app/gpu/main.cu: same command line (PROGRAM INPUT_FILE),
same output on stdout. Then make it as fast as you can on the GPU while keeping the output correct.
The main computation must execute on the GPU. Renaming CPU code to .cu, running a
CPU fallback, or launching a dummy kernel while computing the answer on the CPU does not satisfy this task.
The CPU source is the specification: when this text and the code disagree, the code wins.
This sandbox is for writing the source only: it has g++ and the CPU program, but no CUDA
compiler and no GPU. Compilation, execution and verification happen later on an H100 in a
separate verifier, and a port that does not compile is rejected, so check your logic against
the CPU program before you finish (for example by emulating your kernels on the host).
How your port is verified
- Only
/app/gpu/main.cuis collected. It is compiled withnvcc -O3 -arch=sm_90 -std=c++17 -o port /app/gpu/main.cu; no extra libraries are linked. The CUDA runtime and the header-only libraries that ship with the CUDA toolkit (CUB, Thrust, libcu++) are allowed. - Your source must not contain any of:
system(,popen(,fork(,exec*,dlopen(,getenv(,#include <filesystem>,/tests/,/proc/. The program may read only the input file it is given. - Verification runs on one H100 in a fresh container without network. Hidden inputs are generated with a fresh random seed at verification time.
- Correctness: every hidden input (small edge cases plus a large timing input) must pass.
Your output must have the same tokens as the CPU program's output. Numeric tokens may differ by at most
atol + rtol*|expected|with rtol = 1e-05 and atol = 1e-07; every other token must be identical. Any mismatch, crash or timeout is rejected. - GPU execution is checked: a port that computes its answer on the CPU is rejected even when its output is correct.
- Speed: The timing input is a batch of 256 independent systems of 1536 cells each, advanced 1400 SSP-RK3 steps with WENO5 reconstruction (about 0.55 billion cell-steps, each stage doing six WENO5 reconstructions).
/app/inputs/timing_example.inhas the shape and size of the hidden timing input. Your port is timed against a reference GPU port on it; the faster your port, the higher its score. /app/inputs/holds public input examples for understanding the input format.