Backward-Euler 3D variable-coefficient diffusion solved by fixed geometric multigrid V(2,2) cycles
/app/cpu/main.cpp is a multicore CPU program (C++17, OpenMP). It is built as
/app/bin/cpu_baseline with g++ -O3 -march=native -fopenmp -std=c++17 and run as
cpu_baseline INPUT_FILE
It reads one input file and writes its result to stdout.
What the program computes
Backward-Euler time stepping of 3D diffusion with absorption and moving sources on an
NX x NY x NZ cell-centred grid (cell (i, j, k) at (k*NY + j)*NX + i, spacing 1):
u_t = div(kappa grad u) - sigma u + f(x, t)
with Dirichlet walls (u = 0) at the x boundaries, Neumann walls (no flux) at the y boundaries and
periodicity in z. kappa is a smooth field times high-contrast multipliers ({0.02, 0.1, 10, 50})
from up to 64 box/sphere inclusions (exact integer membership, last one wins); sigma >= 0 is
smooth; f is four rational source bumps that drift along z with modulated amplitudes. All model
parameters come from SEED exactly as in the CPU source.
Every step solves (I + DT*sigma - DT*div(kappa grad)) u_new = u_old + DT*f(t_{n+1}) approximately
with exactly CYCLES geometric multigrid V(2,2) cycles started from u_old (no convergence test):
- Levels.
LEVELSlevels; levellhasN/2^lcells per dimension and spacingH = 2^l. Operator per level:(A u)_c = (1 + DT sigma_c) u_c + (DT/H^2) sum_faces k_f (u_c - u_nb), where a Dirichlet face uses the ghost-u_cand Neumann faces drop out. - Coefficients. Finest interior faces use the harmonic mean of the two cells'
kappa; Dirichlet boundary faces use the adjacent cell'skappa. A coarse face coefficient is the average of the 4 fine faces it covers; coarsesigmais the average of the 8 children. - Smoother. Red-black Gauss-Seidel: all cells with
(i+j+k)even, then all odd; one sweep is both colours. 2 sweeps before and 2 after the coarse-grid correction; 24 sweeps on the coarsest level. - Transfers. Restriction: coarse right-hand side = average of the 8 fine residuals, coarse
initial guess 0. Prolongation: cell-centred trilinear interpolation (weights 27, 9, 3, 1 over 64)
with ghost values
-e(x walls),+e(y walls) and periodic wrap (z), added to the fine solution.
All arithmetic is FP64. The arithmetic of every operation (order of the neighbour sum, division by the diagonal, ...) is defined by the CPU source; ports may differ at rounding level only.
Input format
One line: NX NY NZ LEVELS STEPS CYCLES DT SIGMA NINC SEED. With s = 2^(LEVELS-1): NX and NY
are multiples of s with NX/s, NY/s >= 2, NZ is a multiple of 2s; 1 <= LEVELS <= 12,
CYCLES >= 1, 0 <= NINC <= 64.
Output format
step S res R0 R1 ... R_CYCLES (8 lines, checkpoint steps)
field mean M rms R
block BZ BY V0 V1 V2 V3 (16 lines for a 4 x 4 x 4 block grid)
probe I J K U (8 lines)
- Checkpoint steps are
ceil(K * STEPS / 8),K = 1..8(no step lines whenSTEPS = 0).R0is the RMS of the finest-level residualb - A ubefore the first cycle of that step,Rcafter cyclec. - Block means use
min(4, N)blocks per dimension with boundsb*N/B(integer division).
Residuals are printed with %.10e, everything else with %.12e, compared with the tolerance given
below. Measured rounding noise between correct builds is below 1e-9 relative, except for residuals
that a tiny single-level run drives down to the rounding floor (around 1e-12); the absolute part of the
tolerance covers those.
Hidden inputs
- Grids from
2 x 2 x 2up to160 x 160 x 128,1 <= LEVELS <= 6,0 <= STEPS <= 700,1 <= CYCLES <= 4,5 <= DT <= 40,0 <= SIGMA <= 0.3,0 <= NINC <= 64. - Correctness inputs include single-level runs (
LEVELS = 1), a2 x 2 x 2grid,STEPS = 0, non-cubic grids, coarsest levels of 2 to 5 cells per side and one128^3case with 6 levels. - The timing input has
NX, NYin{128, 160},NZ = 128,LEVELS = 6(coarsest level 4-5 x 4-5 x 4),CYCLES = 3,DTin[10, 40], 32-64 inclusions, and about600 * 128^3 / (NX*NY*NZ)steps (about 1200-1900 V-cycles in total).
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.
How you are scored
- 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. - GPU verification uses the backend selected for this run: an H100 attached to the separate verifier, or a remote H100 worker. Hidden inputs use a fresh random seed.
- For public GPU experiments, use
/app/bin/gpu_run [--backend auto|local|remote] [--repeat N] [--quiet] SOURCE.cu INPUT_FILE.... The default usesGPU_RUNNER_URLwhen configured, otherwise a GPU attached to this sandbox. Sandbox GPU access is configured independently from verification; a CPU-only sandbox needs a runner URL. - Correctness: every hidden input (small edge cases plus the 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-07 and atol = 1e-09; every other token must be identical. Any mismatch, crash or timeout gives reward 0. - GPU execution: a separate, untimed CUPTI check must observe completed GPU kernel activity on the hidden timing input. A CPU-only submission receives reward 0 even if its output is correct.
- Speed: The timing input has a 128-160 x 128-160 x 128 grid with 6 levels, 3 V(2,2) cycles per time step and about 600 * 128^3/(NXNYNZ) steps (about 1200-1900 V-cycles). Your port and our GPU reference are each run on it
once to warm up and then 5 times, interleaved; the time is the wall clock of the whole process
(including CUDA initialisation, input parsing and output). When correct,
reward = min(2, t_reference / t_yours)using the medians. /app/inputs/holds a few public inputs./app/bin/run_public.shcompiles your port with the flags above and compares it against the CPU baseline on each of them.