Cellular Potts model with a global per-cell volume constraint
/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
The program is a cellular Potts model (CPM) on a periodic L x L lattice (L even).
Every site holds a cell ID in [0, M). Each cell c has a type ctype[c] in [0, 4) and a
target volume Vt[c], both built deterministically from seed. A symmetric 4x4 contact
energy table J (per type pair) is also built from seed. The lattice is initialised as
GB x GB compact square blocks (GB = round(sqrt(M))), and V[c] is the number of sites
with ID c (a global per-cell volume accumulator).
Dynamics are checkerboard Metropolis copy attempts. A sweep has two sub-sweeps, one per
colour (x+y)&1. At the start of each sub-sweep the volumes are frozen into a snapshot
Vf. Then every site t of that colour:
- draws one 64-bit random number
rfrom a counter-based hash keyed by(seed, sweep, colour, t); - picks a von-Neumann neighbour
srcbyr & 3(up/down/left/right, periodic) and proposes copyingid[src]intot. Ifid[src] == id[t]nothing happens; - otherwise computes
dE = (adhesion with new ID) - (adhesion with old ID) + (volume term). Adhesion of a labelwis the sum over the 4 neighboursnofJ[type[w]][type[n]]whenw != id[n](else 0). The volume term, using the frozen volumes, isLAMBDA*(2*(Vf[v]-Vt[v])+1) + LAMBDA*(-2*(Vf[u]-Vt[u])+1)whereu = id[t],v = id[src]; - accepts if
dE <= 0, rejects ifdE > 4096, else accepts when(r >> 32) < thr[dE](thr[0] = 2^32,thr[d] = (thr[d-1]*w) >> 32).
An accepted move writes id[t] = v and updates the global volumes V[u] -= 1, V[v] += 1
(integer, so the order of concurrent updates does not matter). Because decisions use the
frozen snapshot and no two same-colour sites are adjacent, all decisions in a sub-sweep are
independent.
Per printed sweep the program reports the total adhesion energy, the total volume energy
LAMBDA * sum_c (V[c]-Vt[c])^2, and the cumulative accepted-copy count. After all sweeps it
reports a 16-bucket histogram of cell volumes, the total volume per type, and a lattice hash.
Input format
One simulation on a single line:
L M LAMBDA w SWEEPS EVERY seed
L even in [2, 4096]; M >= 1 cells; LAMBDA >= 1; w with 0 < w < 2^32
(= round(2^32 * exp(-1/T))); SWEEPS >= 0 printing every EVERY; seed unsigned 64-bit.
Output format
cpm L <L> cells <M> sweeps <SWEEPS>
sweep <s> eadh <Ea> evol <Ev> acc <cumulative_accepts> (for each printed sweep)
hist <h0> ... <h15>
tvol <t0> <t1> <t2> <t3>
hash <H>
All reported values are non-negative 64-bit integers (sums modulo 2^64).
Hidden inputs
Correctness inputs cover M = 1 (single cell, no moves), tiny lattices, few-big-cells and
many-small-cells, SWEEPS = 0, and random configurations with even L in [8, 220],
M a perfect square up to 256, LAMBDA in [1, 4], w in [3.6e9, 4.2e9], SWEEPS in
[1, 16]. The timing input uses L = 4096, M = 1024, LAMBDA = 2, w = 4.0e9,
SWEEPS about 1360.
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 be identical to the CPU program's output (trailing whitespace ignored). 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 one L = 4096 lattice with M = 1024 cells (so ~16k sites per cell contend on each volume counter) run for about 1360 checkerboard sweeps (two sub-sweeps each), printing every ~68 sweeps. 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.