Colinear seed chaining with an invented banded gap 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 reads B and seed and processes B independent reads. For read d
(mix64 is the SplitMix64 finaliser in the source), g0 = mix64(seed ^ d*0x9E37..) fixes the
anchor count nA = 1 + g0 % 2000 and a per-read diagonal offset diag_off = mix64(g0^0x5151..) % 20000.
Anchor i (0-based) uses hi = mix64(g0 + (i+1)*0xD1B54A32D192ED03):
xis strictly increasing:x[i] = x[i-1] + 1 + hi % 30(so index order == x order),y[i]is, with probability ~1/2 (bit 61 ofhi), a random value in[0,50000), otherwise a "planted diagonal" valueclamp(x[i] + diag_off + (mix64(hi^0x9A9A..)%41 - 20), 0, 49999),- weight
w[i] = 1 + mix64(hi^0x3C3C..) % 8.
A chain is a subsequence strictly increasing in both x and y. The score is the sum of
anchor weights minus the gap cost of each jump. The DP (anchors in index order) is
dp[j] = w[j] + max(0, max over valid i<j of ( dp[i] - gap(i,j) ))
gap(i,j) = 2*|dx-dy| + 1*(max(dx,dy) >> 6), dx = x[j]-x[i], dy = y[j]-y[i]
valid i : y[i] < y[j], dx <= 3000, dy <= 3000
Per read the program computes best = max_j dp[j], nend = number of anchors j with
dp[j] == best, and sumdp = sum_j dp[j]. Aggregated over all reads it reports:
SUM_BEST= sum ofbest(mod 2^64),SUM_NEND= sum ofnend(mod 2^64),SUMDP= sum of per-readsumdp(mod 2^64),HASH= sum ofmix64(d ^ best*0x9E3779B97F4A7C15 ^ (nend<<40) ^ sumdp)(mod 2^64),MAXBEST= largest per-readbest,MAXREAD= smallest read index achieving it (-1ifB=0).
Input format
B seed
Output format
One line:
B SUM_BEST SUM_NEND SUMDP HASH MAXBEST MAXREAD
Hidden inputs
0 <= B <= 300000, seed any 64-bit value. Correctness inputs (12 files) include B=0,
B=1, B=2, and random sizes up to 2000. The timing input uses B = 300000. All anchor
coordinates, weights and dp values are integer and the output is compared exactly.
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 writing the source only: it has g++ and the CPU program, but no CUDA
compiler and no GPU. Compilation, execution and verification happen later on an H100 in a
separate verifier, and a port that does not compile is rejected, so check your logic against
the CPU program before you finish (for example by emulating your kernels on the host).
How your port is verified
- 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. - Verification runs on one H100 in a fresh container without network. Hidden inputs are generated with a fresh random seed at verification time.
- Correctness: every hidden input (small edge cases plus a large timing input) must pass. Your output must be identical to the CPU program's output (trailing whitespace ignored). Any mismatch, crash or timeout is rejected.
- GPU execution is checked: a port that computes its answer on the CPU is rejected even when its output is correct.
- Speed: The timing input chains B = 300000 generated reads; each read has up to 2000 anchors and runs the O(nA^2) max-plus chaining DP with banding.
/app/inputs/timing_example.inhas the shape and size of the hidden timing input. Your port is timed against a reference GPU port on it; the faster your port, the higher its score. /app/inputs/holds public input examples for understanding the input format.