Log-domain Sinkhorn optimal transport with an invented ground cost
/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
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 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 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. - 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 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 public input examples for understanding the input format.