Fixed-point embedded-atom-method metal MD with two-pass neighbour gather
/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 fixed-point embedded-atom-method (EAM) metal molecular dynamics. N
atoms live in a periodic cube of side 2^32 (positions are uint32) with signed integer
velocities. Initial positions are uniform, or (for a fraction of atoms) inside one of K
compact blobs; velocities are small and uniform. Six integer lookup tables are built
deterministically from seed:
- distance-bucket tables
wdens,gw,pw,peof length 1024, indexed byk = d2 >> QSHwhered2is the squared integer separation andQSH = 2*CS - 10(CS = 32 - LOGG); - density-bucket tables
EF(embedding energy) andDF(embedding derivative) of length 1024, indexed bymin(rho >> 12, 1023).
A cutoff cell list (cell size 2^CS, cutoff d2 < 2^(2*CS)) is rebuilt each step. Then each
of T steps does:
- Pass 1 (density): for each atom
i,rho_i = sum over neighbours j of wdens[k]. Map it to the embedding derivativemu_i = DF[min(rho_i>>12, 1023)]. - Pass 2 (force): for each atom
i, walk the neighbours again; for each pair the force scalar isfs = (mu_i + mu_j)*gw[k] + pw[k](so it gathers the neighbour's embedding derivativemu_j). The force issum of fs * (x_i - x_j)per component. Pair energy accumulatespe[k], the virial accumulatesfs * k. - Integrate:
v += force / 2^DS, then dampingv -= v/64, clamp to[-VMAX, VMAX](VMAX = 2^(CS - VSH)), thenx += v(wrapping).
Because (mu_i + mu_j) and the weights are symmetric while (x_i - x_j) is antisymmetric,
the pair forces are exactly antisymmetric, so total momentum is conserved. Per printed step
the program reports total pair energy (sum/2), total embedding energy (sum of EF) and
the virial (sum/2). Energies and virial are signed 64-bit (wrapping). After T steps it
reports a position hash, a velocity hash, total momentum, the summed density, and six
components each of four sampled atoms.
Input format
One simulation on a single line:
N LOGG T EVERY DS VSH K seed
N >= 1; LOGG in [2, 27] (G = 2^LOGG cells per axis); T >= 0 steps printing every
EVERY; DS >= 0 force shift; VSH with 1 <= VSH < CS; K >= 0 blobs; seed unsigned
64-bit.
Output format
eam N <N> grid <G>^3 steps <T>
step <t> epair <Ep> eemb <Ee> virial <W> (for each printed step)
position_hash <hex16> velocity_hash <hex16>
momentum <px> <py> <pz> sumrho <S>
atom <i> x <x> <y> <z> v <vx> <vy> <vz> (4 lines)
Hidden inputs
Correctness inputs cover N = 1 (no neighbours), N = 2, T = 0, K = 0 (no clustering),
clustered systems, finer grids, and random configurations with N in [1500, 12000],
LOGG in [3, 6], T in [1, 8], DS in [24, 30], VSH = 3, K in [0, 16]. The
timing input uses N = 400,000, LOGG = 4, T about 12, DS = 28, VSH = 3, K = 24.
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 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. - This sandbox has no GPU.
nvccworks here for compiling. To run on the GPU, use/app/bin/gpu_run [--repeat N] [--quiet] SOURCE.cu INPUT_FILE...: it compiles the file with the flags above on a remote H100 worker, runs it on each input, and prints stdout, exit code and wall-clock time. Grading also runs your code on an H100 worker, one job per GPU at a time. Inputs are generated with a new random seed at grading time, so they cannot be known in advance. - 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.
- Speed: The timing input is one simulation of N = 400,000 atoms in a 16^3 cell grid (so cells hold tens to a few hundred atoms) run for about 12 steps, each doing two full neighbour sweeps; clustering into 24 blobs makes some cells much denser than others. 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.