Multi-word Myers bit-vector matching of long IUPAC patterns
/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
Approximate matching of many long IUPAC patterns against a long DNA-like text, with Myers' bit-vector algorithm (multi-word version).
Text. N symbols over A C G T plus the masked symbol N, generated from the seed
(mix64 is the SplitMix64 finaliser; exact formulas in the CPU source):
- a base layer cut into 4096-symbol segments: the first segment and 60% of the others are fresh random bases; every other segment copies earlier text at a power-law distance (at least 4096 back), with 3% point mutations;
- an overlay on 2048-symbol slots: 1/16 of the slots get a run of 20-319 masked
Nsymbols, 3/16 get a planted occurrence of a random pattern with substitutions, insertions and deletions (cut off at the slot end).
Patterns. P patterns with lengths m in [LMIN, LMAX] over the 15 IUPAC codes
(A C G T R Y S W K M B D H V N, stored as 4-bit masks over A, C, G, T), each with a threshold
k = floor(m * rate / 1000), rate in [50, 150]. About half of the patterns are copies of the
base layer at a random position with ~3% substitutions and ~4% positions widened to an ambiguity
code; the others are random with ~6% ambiguity codes. A pattern symbol matches a text base when its
mask contains the base; the text symbol N matches nothing.
Matching. For every pattern and every text end position j (0-based) the program computes
the semi-global edit distance
D(j) = min over t <= j+1 of EditDistance(pattern, T[t..j]) (unit costs, empty substring allowed)
with Myers' algorithm on ceil(m/64) 64-bit words per pattern (multi-word addition and shift
with carries). A hit is an end position with D(j) <= k; a run is a maximal block of
consecutive hit positions. It also reports the exact minimum of D(j) over all j (not capped at
k) and the leftmost position where it occurs.
The CPU program processes (pattern, 65536-position chunk) work items and restarts each chunk 2m
columns early, which gives exactly the same columns as one pass over the whole text (an optimal
alignment never spans more than 2m text symbols).
Input format
One line:
N P LMIN LMAX SEED
Output format
text N masked X patterns P
hits H runs R
hithash HH
pathash PH
pat p m M k K hits H runs R min D at J (one line per pattern, p = 0..P-1)
X: number of masked text symbols.H,R: hits and runs (per pattern on thepatlines, summed on the second line).HH: sum over all hits ofmix64((p << 48) | (j << 10) | D(j))modulo 2^64.PH: sum over patterns ofmix64((p << 40) ^ (hits << 20) ^ (min + 1) ^ ((at + 1) << 24))modulo 2^64.min D at J: the minimum distance and its leftmost end position; for an empty text it ismin m+1 at -1.
Hidden inputs
0 <= N <= 2^27,1 <= P <= 128,1 <= LMIN <= LMAX <= 1024.- Correctness inputs include an empty text, a one-symbol text, a text shorter than every pattern,
patterns of exactly 64 and 65 symbols, 1024-symbol patterns, 1-8 symbol patterns (
k = 0), texts spanning several chunks, 128 patterns, and random mixes. - The timing input has
Nabout 2^26 (64M +- 5%),Pin [88, 104],LMIN = 128,LMAX = 1024: about 6*10^10 64-bit word steps.
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 be identical to the CPU program's output (trailing whitespace ignored). 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 a text of about 64M symbols and 88-104 patterns of 128-1024 symbols with k = 5-15% of the length: about 6e10 64-bit word 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.