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
NX, NYin[272, 304],NZin[136, 160]andTin[1400, 1700].
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 source generation only. Write /app/gpu/main.cu; compilation,
execution and verification are performed later in a separate verifier environment.
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.
- 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 = 5e-05 and atol = 2e-06; 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 grid of about 272-304 x 272-304 x 136-160 cells (~12.5M) and 1400-1700 explicit steps. 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 public input examples for understanding the input format.