Deterministic-annealing EM for a weighted diagonal Gaussian mixture with background
/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
Deterministic-annealing EM for a mixture of K axis-aligned (diagonal) Gaussians in D
dimensions plus a fixed uniform background component, on N weighted points. Everything is
double precision.
Data. K planted components have means in K distinct cells of a 4^D lattice
(spacing 16, centred at the origin, the cells chosen by sorting cell hashes) plus a jitter
of up to +-3, and standard deviations in [0.5, 2). Point i (with
h = mix64(SEED + 0x5555*(i+1))) belongs to planted component h % K, has weight
w_i in [0.5, 1.5) and Box-Muller normal coordinates; see the CPU source for the exact
formulas (mix64 is the SplitMix64 finaliser).
Initial guess. Planted means shifted by up to +-1.5, all variances 4, equal weights
pi_k = (1 - PI0)/K, with PI0 = 0.02 the fixed background weight. The background
density is uniform on a box of side 64: log b = log(PI0) - D log 64.
Iteration t = 0..T-1. beta = BETA0 + (1 - BETA0) * t / (T/2) for t < T/2 (integer
T/2), else beta = 1. With l_ik = log pi_k - 1/2 sum_d [log(2 pi var_kd) + (x_id - mu_kd)^2 / var_kd]:
r_ik = exp(beta l_ik) / (exp(beta log b) + sum_j exp(beta l_ij)) (tempered responsibilities)
N_k = sum_i w_i r_ik, S1_kd = sum_i w_i r_ik x_id, S2_kd = sum_i w_i r_ik x_id^2
pi_k = (1 - PI0) (N_k + 1) / (Wsum (1 - PI0) + K) (Wsum = sum_i w_i)
mu_kd = S1_kd / (N_k + 1)
var_kd = (S2_kd - 2 mu_kd S1_kd + mu_kd^2 N_k + 1) / (N_k + 2)
When beta == 1 the iteration also reports the log-likelihood (under the parameters used
in that E-step) sum_i w_i log(b + sum_k exp(l_ik)).
Input format
One line: N D K T BETA0 SEED (BETA0 decimal, SEED unsigned 64-bit).
Output format
points N dims D comps K iters T
weight_sum Wsum
iter t loglik LL (for every t with beta == 1: t >= T/2, or all t if BETA0 = 1)
comp k pi P mu M_1 .. M_D var V_1 .. V_D (K lines, final parameters)
Values are printed with %.12e and compared numerically with rtol = 1e-6, atol = 1e-9.
The problem is well conditioned: a correct FP64 port with any summation order or FMA
contraction differs by ~1e-12, and computing the E-step (distances, exponentials) in FP32
while accumulating the statistics in FP64 differs by ~1e-8, which the tolerance allows.
FP32 accumulation of the statistics over millions of points is not accurate enough.
Hidden inputs
0 <= N <= 7.5e6,D in {3, 4},1 <= K <= 32,0 <= T <= 44,0.2 <= BETA0 <= 1.- Correctness inputs include
N = 0, 1, 5,Naround multiples of 2048,K = 1,K = 32,T = 0, 1, 2,BETA0 = 1, and problems with up to 80000 points. - The timing input has
Nin about[6.0e6, 7.0e6],D = 4,K = 32,Tin[36, 44],BETA0in[0.3, 0.6].
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 have the same tokens as the CPU program's output. Numeric tokens may differ by at most
atol + rtol*|expected|with rtol = 1e-06 and atol = 1e-09; every other token must be identical. 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 has 6.0-7.0 million 4-D points, 32 components and 36-44 EM iterations. 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.