4D-Var data assimilation with a checkpointed discrete adjoint
/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 observing-system simulation experiment (OSSE) with strong-constraint 4D-Var data assimilation for a two-species reactive tracer model, solved one problem after another.
Model. Species u, v on a doubly periodic NX x NY grid (cell c = j*NX + i). Face
winds U, V come from a generated stream function on cell corners (discretely divergence
free), modulated in time by s(n); centred flux-form advection, 5-point diffusion (ku,
kv), invented photochemistry (+a1 v - a2 u v - a3 u for u, -a1 v - a4 v^2 for v) and
emissions Eu, Ev scaled by a diurnal factor d(n). One time step is Heun's method
(explicit RK2): xs = x + dt F(x, n), x <- x + dt/2 (F(x, n) + F(xs, n+1)). All fields,
rate constants and the initial truth xt / background xb are generated from the seed with
SplitMix64-style hashing and smooth analytic functions (see the CPU source).
Observations. NST fixed stations observe u by bilinear interpolation; a moving satellite
swath observes 4x4-cell averages of v (footprints on a shifted 8-cell lattice, inside a
band that moves with time). Both are taken every OBSINT steps (state after the step) from a
truth run started at xt, plus Gaussian noise (SIG_ST = 0.02, SIG_SAT = 0.01) drawn from
hashes.
Cost. J(x0) = 1/2 |A (x0 - xb)|^2 / SIG_B^2 + 1/2 sum_obs (H(x_n) - y)^2 / sigma^2,
A = I - ELL2 * Laplacian (periodic 5-point), SIG_B = 0.1, ELL2 = 1, where x_n is the
model trajectory from x0.
Gradient. Exact discrete adjoint of the whole forward computation: a forward run storing
K = ceil(NSTEP / C) checkpoints (C = ceil(sqrt(NSTEP))), then a backward sweep over the
segments in reverse order; each segment is recomputed from its checkpoint, and every Heun step
is reversed with the transposed tendency Jacobian (written in the CPU source as the scatter an
AD tool would generate; rows processed in two colours of 4-row blocks so the order of
accumulation is fixed). Observation misfits add their forcing to the adjoint state at their
times; the background term adds A^T A (x0 - xb) / SIG_B^2.
Mission. Starting from x = xb, NOUT outer iterations of steepest descent: probe
J(x - tau g/|g|) (first tau = 0.25 |xb - xt|, afterwards the previous step), fit a parabola
through J(x), the slope -|g| and the probe, step to its minimum (alpha = |g| / (2 c2), or
tau if the curvature c2 <= 0), re-evaluate cost and gradient there. Reported are the cost
split, the gradient norms, the probe/step lengths, the cost reduction and the RMS error
against the truth of the background and of the analysis at the initial time and after
NSTEP steps (forecast). The iteration stops early if the gradient is exactly zero.
FP64 throughout. All reductions use fixed chunks of 4096 values summed in order, so the CPU output is independent of the thread count.
Input format
NP
NX NY NSTEP OBSINT NST NOUT DT SEED (NP lines)
NX, NY are multiples of 8 (8 <= NX, NY), 0 <= NSTEP, 1 <= OBSINT, 0 <= NST,
0 <= NOUT, DT a decimal with three digits, SEED an unsigned 64-bit integer.
Output format
Per problem:
problem p grid NX NY steps NSTEP obs_times NOBS stations NST footprints NFP
iter 0 J <J> Jb <Jb> Jst <Jst> Jsat <Jsat> gnorm <|g_u|> <|g_v|>
grad0 cell <c> <g_u[c]> <g_v[c]> (4 lines)
iter k probe <tau> <J(probe)> slope <(J-Jprobe)/(tau|g|)> step <alpha> J .. Jb .. Jst .. Jsat .. gnorm .. ..
reduction J_final/J_initial <ratio>
rmse_t0 background <u> <v> analysis <u> <v>
rmse_tN background <u> <v> analysis <u> <v>
Reals use %.10e; they are compared numerically with the task's tolerance (FP64 is
required), integers must match exactly.
Hidden inputs
Correctness inputs (10 files, 1-3 problems each): grids from 8 x 8 to 64 x 64,
0 <= NSTEP <= 160, 1 <= OBSINT <= 50, 0 <= NST <= 60, 0 <= NOUT <= 4,
DT in {0.1, 0.2, 0.25, 0.3, 0.35}; they include NSTEP = 0, no observation time
(OBSINT > NSTEP), no stations, NOUT = 0, observations every step, and NSTEP not a
multiple of the checkpoint interval. The timing input is one problem with NY = 512,
NX in {504, 512, 520}, NSTEP = 1200, OBSINT = 12, 300 <= NST <= 500, NOUT = 4,
DT in {0.25, 0.3}.
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-10; 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 is a single 512 x ~512 problem (about 260k cells, two species) with 1200 Heun steps, observations every 12 steps and 4 outer iterations (5 gradient evaluations with checkpointed adjoint sweeps plus 4 line-search forward runs). 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.