Four coupled integer species with per-species stencils
/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
Four integer species a, b, c, d (each in [0, 4095], stored as an array of 4 x int16 per
cell) live on a W x H grid that is periodic in x and mirrored in y: row -1 reads row 0,
row -2 reads row 1, row H reads row H-1, row H+1 reads row H-2 (clamped into range
for grids shorter than 2 rows). Initial values, a 64x64 reaction table with entries in
[-AMP, AMP] and a feed map (one value in [0, 15] per 16x16 block) come from seed.
Each of T steps updates all cells synchronously from the previous state:
la = 4 von Neumann neighbours of a - 4a
lb = 8 Moore neighbours of b - 8b
lc = c at distance 1 and 2 along both axes (8 cells) - 8c
ra = LUT[a >> 6][b >> 6]
a' = a + (la >> 3) + ra - ((a*c) >> 13) + (d >> 5)
b' = b + (lb >> 4) - ra + ((a*a) >> 14) - ((b*d) >> 14) + feed(x>>4, y>>4)
c' = c + ((3*lc) >> 5) + ((b*(4095-c)) >> 15) - (c >> 6)
d' = d + ((c-d) >> 4) + (a > 3000 ? 3 : 0) - (b > 3500 ? 5 : 0)
All shifts are arithmetic on 32-bit ints; every result is clamped to [0, 4095].
Input format
W H T
AMP
SEED
Output format
Let ck = max(1, T / 8). After step s (1-based) whenever s % ck == 0 or s == T:
step s a HASH SUM b HASH SUM c HASH SUM d HASH SUM
then final T ... in the same format (also when T = 0), then samples followed by the final
a,b,c,d of six hash-chosen cells. The hash of species k (0..3) is the sum over cells
i = y*W + x of mix64((i << 34) ^ (k << 32) ^ value) modulo 2^64, printed as 16 hex digits.
Hidden inputs
1 <= W, H <= 4096, 0 <= T <= 5000, 1 <= AMP <= 48, any 64-bit seed. Correctness inputs
include 1x1 and 2x2 grids, single rows and columns (where the radius-2 wrap and mirror fold
back onto the same cells), T = 0, tiny grids with many steps and a 4096-wide strip. The timing
input uses sides in [2816, 3328] and about 2600 steps.
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 be identical to the CPU program's output (trailing whitespace ignored). 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: The timing input is a grid of about 3072 x 3072 cells (each side drawn from [2816, 3328]) stepped about 2600 times (drawn from [2200, 3000]).
/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.