FM-index backward search with bounded wildcard branching
/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 reads N, M, seed. It generates a text T of N symbols over the
alphabet {0,1,2} (symbol i is mix64(seed ^ (i*0xD1B54A32D192ED03)) % 3, where mix64
is the SplitMix64 finaliser in the source), appends a unique sentinel that sorts before every
real symbol, and builds an FM-index:
- the suffix array of the sentinel-terminated string,
- the Burrows-Wheeler transform, stored packed 2 bits per symbol (32 symbols per 64-bit word; the sentinel is stored as the value 3 and is never counted by a query),
- checkpoint counts: for every block of
K = 256BWT positions, the cumulative number of each real symbol before that block.rank(c, i)= checkpoint value + a scan of the packed words from the block start toi. - the first-column array
C[c](C[0]=1,C[1]=1+#0,C[2]=1+#0+#1).
It then generates M patterns and runs backward search on each. Pattern idx has length
P = 6 + (h0 % 11) with h0 = mix64((seed ^ 0xA5A5A5A5A5A5A5A5) + idx*0x9E3779B97F4A7C15).
Character j (0-based) is derived from hj = mix64(h0 + (j+1)*0xC2B2AE3D27D4EB4F):
- if
hj % 6 == 0and fewer thanWMAX = 2wildcards have been used so far (scanning the pattern right to left, as backward search does), positionjis a wildcard: the current suffix-array interval[lo,hi)is split into up to three children, one per real symbol; - otherwise it is the literal symbol
hj % 3.
Backward search maintains the set of live intervals (at most 3^WMAX = 9); each step maps
[lo,hi) to [C[c]+rank(c,lo), C[c]+rank(c,hi)) and drops empty intervals. If all intervals
die, the pattern search stops early. The pattern's occurrence count is the sum of the
widths of the surviving intervals.
Aggregated over all patterns the program reports:
MATCHED= number of patterns with count > 0,B1,B2,B3= number of patterns with count in[1,9],[10,99],>=100,TOTALOCC= sum of all counts (mod 2^64),HASH= sum ofmix64((count * 0x9E3779B97F4A7C15) ^ h0)over patterns (mod 2^64),MAXCOUNT= largest count,MAXIDX= the smallest pattern index achieving it (-1ifM=0).
Input format
N M seed
Output format
One line:
N M MATCHED B1 B2 B3 TOTALOCC HASH MAXCOUNT MAXIDX
Hidden inputs
0 <= N <= 262144, 0 <= M <= 280,000,000, seed is any 64-bit value. Correctness inputs
(15 files) include the empty text (N=0), a single symbol (N=1), M=0 and M=1, texts of
exactly 255, 256, 257 symbols (around one checkpoint block), and random mixes with
N up to 60000 and M up to 120000. The timing input uses N = 262144 and
M = 280,000,000; mix64 and all arithmetic are 64-bit unsigned, every count is 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 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 be identical to the CPU program's output (trailing whitespace ignored). Any mismatch, crash or timeout gives reward 0.
- Speed: The timing input builds the index over N = 262144 symbols (plus a sentinel) and backward-searches M = 280,000,000 generated patterns of length 6..16; pattern search dominates the run (index build is well under a second). 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.