Log-domain Sinkhorn optimal transport with an invented ground cost
/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 solves an entropic optimal-transport problem between a source point set
(n points) and a target point set (m points) with stabilized log-domain
Sinkhorn iterations and a fixed epsilon-annealing schedule (no convergence-based
stop), then reports summaries of the resulting transport plan.
Data. Each source point i and target point j carries D = 6 features drawn
from a SplitMix64 counter hash of the seed. Source marginal a_i and target marginal
b_j are hashed positive weights, each normalised to unit total mass in a fixed order.
Ground cost (invented, non-Euclidean). For a source point i and target point j,
C_ij = sum_d ( A_d*(f_id - g_jd)^2 + B_d*|f_id - g_jd| ) + K*|p_i - q_j|
where p_i = sum_d U_d f_id, q_j = sum_d U_d g_jd, and A, B, U, K are fixed
invented coefficients. It mixes a weighted squared distance, a weighted L1 distance and
a projected-L1 cross term. The dense cost is never materialised: C_ij is recomputed
from features on the fly.
Solver. Dual potentials f (size n) and g (size m) start at zero. With
regularisation eps, each iteration performs two log-sum-exp updates:
f_i = eps*log a_i - eps * logsumexp_j[ (g_j - C_ij)/eps ]
g_j = eps*log b_j - eps * logsumexp_i[ (f_i - C_ij)/eps ]
The schedule runs NSTAGE = 5 stages with eps = 0.5 * 0.5^stage, each stage doing
INNER = 20 inner iterations. Each log-sum-exp is computed as an exact max followed by
a sum of exponentials in a fixed order (thread-count independent).
Plan. The final coupling is P_ij = exp((f_i + g_j - C_ij)/eps_final) with
eps_final = 0.5 * 0.5^4.
Input format
n m seed
One line: n >= 1 source points, m >= 1 target points, and a 64-bit seed.
Output format
n <n> m <m> stages <NSTAGE> inner <INNER>
eps_final <eps_final>
transport_cost <sum_ij P_ij C_ij>
marginal_violation <sqrt(||rowsum(P)-a||^2 + ||colsum(P)-b||^2)>
total_mass <sum_ij P_ij>
f <i> <f_i> (4 sampled source potentials)
g <j> <g_j> (4 sampled target potentials)
Floating-point fields use %.10e. Comparison is numeric with rtol = 1e-6,
atol = 1e-8.
Hidden inputs
Correctness inputs (10 files) include n = m = 1, strongly rectangular shapes
(1 x 8, 8 x 1, 1000 x 300), 3 x 2, and square sizes 16, 64, 200, a random
square size in [300, 700], and 1200 x 1200. The timing input has n = m about
6000. All coefficients and the epsilon schedule are fixed in the program.
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. - Grading runs on one H100 in a fresh container without network. 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 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-08; every other token must be identical. Any mismatch, crash or timeout gives reward 0. - Speed: The timing input has n = m = 6000 points with 6 features each, a 5-stage geometric epsilon schedule and 20 inner Sinkhorn iterations per stage (about 14 billion ground-cost evaluations in total). 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.