Sparse multi-phase-field recrystallisation with top-4 phase lists
/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
A complete static-recrystallisation study of a deformed 3D polycrystal with a sparse
multi-phase-field model (the program cpu.cpp is the exact specification; all arithmetic is
integer, so the output is exact):
- Polycrystal. A periodic
NX x NY x NZvoxel box is cut into coarse cells of sideCELL; each cell holds one jittered seed (position frommix64of the cell index). Each voxel joins the nearest seed (periodic squared distance) among the 27 neighbouring cells, ties to the smaller grain id. Grains0 .. G0-1are deformed and carry a hashed stored energyE(g) in [40,120]. - Sparse multi-phase-field steps. Every voxel stores at most
K = 4pairs (grain id, phi) with phi in Q15 and the phis summing to exactly 32768. One step, per voxel: merge the own list with the 6 face neighbours' lists into a candidate set (fixed discovery order), compute per-candidate Laplacians, accumulate the pairwise interface term (hashed anisotropic grain-boundary energygbe(a,b)from a misorientation class plus per-pair hash jitter, low/high-angle mobility) and the stored-energy driving termisqrt(phi_i*phi_j) * (E_j - E_i), clamp, re-select the top 4 candidates by (phi desc, id asc) and renormalise with a largest-remainder rule to exactly 32768. All voxels update simultaneously from the previous state. - Nucleation every
NUC_EVERYsteps (after the step): a voxel whose dominant grain is deformed and whose second phase has phi >= 2048 is a candidate if a per-(voxel, step) hash passes a threshold proportional toE(dominant) * NUC_P. A candidate wins only if its key is the strict minimum (key, then voxel index) inside the periodic Chebyshev window of radiusNUC_R. Winners get new strain-free grain ids (E = 0) in increasing voxel order and seed a 3x3x3 cube. - Report. Every
REPORT_EVERYsteps (and at the last step) the recrystallised fraction (ppm), cumulative nuclei, number of grains that are dominant somewhere, and interface-voxel count; then the first step with fraction >= 50%, final grain counts and log2 grain-size histograms for deformed and recrystallised grains, the 5 largest grains and a checksum of the whole field.
Input format
NX NY NZ CELL
STEPS NUC_EVERY NUC_R NUC_P REPORT_EVERY
SEED
NX, NY, NZ are multiples of CELL; NUC_EVERY = 0 disables nucleation; SEED is a 64-bit
unsigned integer.
Output format
grains0 G0 voxels N
t T X_ppm X nuclei NN alive A iface I (one line per report step)
t50 T50 (-1 if never reached)
final deformed_grains D rx_grains R rx_mean_size M
hist_def b0 .. b23 (grains with floor(log2(size)) = b, capped at 23)
hist_rx b0 .. b23
top id:size ... (up to 5, size desc then id asc)
checksum HEX16
Hidden inputs
Correctness inputs (11 files): boxes from 8^3 to 32^3 voxels (CELL in {4,5,6,8,12,16}, including a
single-grain box, a non-cubic box, STEPS = 0), 0 to 45 steps, NUC_EVERY in 0..10, NUC_R in 2..5,
NUC_P in 0..200, seeds including 0 and 2^64-1. The timing input is a 128^3 box with CELL = 16
(512 grains), 300 steps, NUC_EVERY = 10, NUC_R = 3, NUC_P in [20, 40], REPORT_EVERY = 25;
the recrystallised fraction rises through an Avrami-type S-curve and roughly half of all voxels lie
in interfaces.
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 source generation only. Write /app/gpu/main.cu; compilation,
execution and verification are performed later in a separate verifier environment.
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.
- 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 a periodic 128^3 voxel box with 512 initial grains, 300 sparse phase-field steps with nucleation every 10 steps (exclusion radius 3) and a report every 25 steps. 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 public input examples for understanding the input format.