3D FP32 reaction-diffusion with a variable anisotropic tensor and cross terms
/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
Explicit time stepping, in single precision (FP32), of a 3D reaction-diffusion equation
u_t = div(D grad u) + s - mu u^3
on an NX x NY x NZ grid (unit spacing, x fastest in memory), with a spatially varying,
symmetric positive-definite conductivity tensor
D = [[Dxx, Dxy, 0], [Dxy, Dyy, Dyz], [0, Dyz, Dzz]]
The fields Dxx, Dyy, Dzz, Dxy, Dyz, the source s and the initial state u0 are computed
once (in double precision, then rounded to float) from smooth trigonometric functions whose
phases and frequencies come from the seed, and u0 adds per-cell hash noise in
[-0.2, 0.2) (see build in the CPU source for the exact formulas).
One step computes, for every cell c (all in float, exactly as written in step):
- the diagonal part with face-averaged coefficients, e.g. for
+x:0.5*(Dxx[c] + Dxx[c+x]) * (u[c+x] - u[c]), summed over the 6 faces; - the cross terms
0.5*Dxy[c]*uxy + 0.5*Dyz[c]*uyzwith the 4-corner differencesuxy = (u[+x+y] - u[-x+y]) - (u[+x-y] - u[-x-y])and the analogousuyz; u_new = u + dt * (lap + s - mu*u^3).
Boundaries: zero flux in x (a missing x-neighbour is replaced by the cell itself),
periodic in y, and u = 0 outside the grid in z (a missing z-face contributes
Dzz[c]*(0 - u[c]), and missing z-neighbours in uyz are 0).
Input format
One line: NX NY NZ T DT MU Q0 SEED (T steps; DT, MU, Q0 decimals; SEED unsigned 64-bit).
Output format
grid NX NY NZ steps T
checkpoint t sum S (after steps t with 4*t % T == 0 and t < T, i.e. at T/4, T/2, 3T/4)
sum S
sum_sq S2
grad_sq G (sum of squared forward differences over interior faces)
max M
layer z S_z (8 lines, z = j*(NZ-1)/7)
sample x y z U (16 lines; positions derived from the seed)
Sums are accumulated in double. Values are printed with %.9e and compared numerically with
rtol = 5e-5, atol = 2e-6. A correct FP32 port with FMA contraction or a different
operation order differs from the CPU output by about 1e-7, so FP32 state and arithmetic are
fine (summation order is free); FP16/BF16 state is not accurate enough.
Hidden inputs
1 <= NX, NY, NZ <= 320,0 <= T <= 1700,0.06 <= DT <= 0.12,0.1 <= MU <= 1,0.02 <= Q0 <= 0.1.- Correctness inputs include grids of size 1 in any dimension,
T = 0, 1, 2, and small to medium grids (up to about128 x 70 x 64). - The timing input has the shape and size of
/app/inputs/timing_example.in.
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 = 5e-05 and atol = 2e-06; 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:
/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.