Peaceman-Rachford ADI for quasi-linear anisotropic diffusion with cyclic line solves
/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
An implicit Peaceman-Rachford ADI integration of a 2D quasi-linear reaction-diffusion problem
on an NX x NY cell grid (cell (i, j) stored at j*NX + i, i is x, grid spacing 1):
u_t = d/dx(kx du/dx) + d/dy(ky du/dy) + R(u, x, y, t)
-
Conductivities.
Kx(i,j)andKy(i,j)are built from the seed: a smooth part (sums of rational bumps) times a high-contrast multiplier from up to 64 elliptical inclusions (ellipse membership is an exact integer test; the multipliers for x and y are chosen independently from{0.02, 0.1, 10, 50}, so inclusions are strongly anisotropic). Each step uses the lagged effective valuesk = K * (1 + BETA * u^2 / (1 + u^2))computed from the field at the start of the step. Interior face coefficients are harmonic means2ab/(a+b)of the two cells. -
Boundaries. x has Dirichlet walls: ghost values
gL(j)left ofi = 0andgR(j)right ofi = NX-1, with the boundary face coefficient2 * kof the adjacent cell. y is periodic (rowNY-1neighbours row0). -
Reaction.
R = Q_s(t) - RHO * u / sqrt(1 + u^2), whereQ_s(t) = A_s cos(om_s t + ph_s)inside source discs(up to 8 discs, last disc wins) and 0 elsewhere. It is always treated explicitly. -
Time stepping. With
h = DT/2,t = n*DT, each step is- half step 1, implicit in x: for every row
j, solve the tridiagonal system(I - h Ax) u* = u + h Ay(u) + h R(u, t)(Thomas algorithm, Dirichlet ends); - half step 2, implicit in y: for every column
i, solve the cyclic tridiagonal system(I - h Ay) u_new = u* + h Ax(u*) + h R(u*, t + h)(Sherman-Morrison: two Thomas solves withgamma = -b_0, exactly as in the CPU source).
Both operators use the conductivities lagged at
t_n. Every row and every column is an independent line solve; there areNY + NXsolves of lengthNXresp.NYper step. - half step 1, implicit in x: for every row
All arithmetic is FP64. The scheme is dissipative (the reaction is monotone and its explicit step is
kept within h*RHO <= 0.9), so rounding differences stay at rounding level. Any correct method is
accepted (other tridiagonal algorithms such as cyclic reduction / PCR, other summation orders,
fused kernels) as long as the printed numbers agree within the tolerance below.
Input format
One line: NX NY STEPS DT BETA RHO NINC NSRC SEED (NX, NY, STEPS, NINC, NSRC integers,
DT, BETA, RHO decimals, SEED unsigned 64-bit). Requires NX >= 1, NY >= 3,
0 <= NINC <= 64, 0 <= NSRC <= 8.
Output format
check K step S mean M rms R maxabs X (8 lines, K = 1..8)
blocks BX BY
BY lines of BX block means
probe I J U(I, J) (8 lines)
- Checkpoint
Kis taken after stepceil(K * STEPS / 8)(all at step 0 whenSTEPS = 0): mean, root mean square and maximum of|u|over the grid. BX = min(16, NX),BY = min(16, NY); block(bi, bj)coversi in [bi*NX/BX, (bi+1)*NX/BX)andj in [bj*NY/BY, (bj+1)*NY/BY)(integer division).- Probe positions come from hashing the seed (see the CPU source).
Numbers are printed with %.12e and compared with the tolerance given below (rounding noise of a
correct FP64 port is below 1e-12 relative; a missing term, a wrong boundary coefficient or an
off-by-one changes many outputs by far more).
Hidden inputs
1 <= NX <= 4224,3 <= NY <= 4224,0 <= STEPS <= 300,0.5 <= DT <= 8,0 <= BETA <= 1,RHO = r * 2 / DTwith0 <= r <= 0.9,0 <= NINC <= 64,0 <= NSRC <= 8.- Correctness inputs include
NX = 1,NX = 2,NY = 3,STEPS = 0, a pure linear case (BETA = RHO = 0, no sources or inclusions), thin1 x 4096and4096 x 3grids, and one4096 x 4096grid with a single step. - The timing input has
NX,NYin[3968, 4224], 200-240 steps,DTin[1, 3], 24-64 inclusions and 8 sources.
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-09 and atol = 1e-11; 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 NX, NY in [3968, 4224] (about 16.7M cells) and 200-240 full ADI steps, i.e. about 8200 line solves of length ~4100 per step. 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.