Sparse multi-phase-field recrystallisation with top-4 phase lists
/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
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 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 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 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.