Streamed multi-pattern automaton over a host-generated text
/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
Multi-pattern matching over a long generated text.
The text is produced by a sequential host-side generator: a 64-bit state is updated by a
nonlinear step (s ^= s >> 30; s *= C1; s += C2) and each output word s ^ (s >> 28) holds 16
four-bit symbols (lowest nibble first), mapped to an 8-letter alphabet with skewed frequencies.
The step cannot be jumped ahead or split into independent substreams, so the generator is
inherently sequential and has to run on the CPU. The text is 16*NW letters long and is never
stored as a whole by the CPU program.
NPAT patterns (lengths in [LMIN, LMAX], letters from the same skewed distribution) are derived
from the seed with a counter-based hash. Duplicate patterns are allowed and counted separately.
The program builds an Aho-Corasick automaton (full DFA over the 8 letters, plus for every state the
list of all patterns that end there) and reports every occurrence of every pattern, identified by
its end position p (0-based letter index) and pattern id.
The CPU program cuts the text into segments and restarts the automaton LMAX-1 letters before
each segment; this recovers the exact automaton state because a state never depends on more than
the last LMAX letters.
Input format
One line:
NW NPAT LMIN LMAX SEED
Output format
symbols 16*NW states S
matches M positions DP
poshash H
first F last L maxgap G
pathash PH
top pid length count (up to 10 lines)
S: number of automaton states;M: number of (position, pattern) occurrences;DP: number of distinct end positions with at least one occurrence.H: sum over occurrences ofmix64(p * 0xC6A4A7935BD1E995 + pid)modulo 2^64.F,L: first and last end position with an occurrence;G: the largest difference between consecutive distinct end positions (0 if fewer than two). Printed asfirst - last - maxgap 0when there is no occurrence.PH: sum over patterns ofmix64(pid * 0x9E3779B97F4A7C15 + count) ^ mix64(pid ^ firstpos)modulo 2^64, wherefirstposis the pattern's first end position (2^64-1 if it never occurs).top: the 10 patterns with the most occurrences (ties: smaller id first).
Hidden inputs
0 <= NW <= 1.5*10^9,1 <= NPAT <= 8192,1 <= LMIN <= LMAX <= 16.- Correctness inputs include an empty text, a single word, one-letter patterns (occurrences at almost every position), only length-16 patterns, 8192 patterns over a short text, and texts spanning several of the CPU program's 2^20-word chunks.
- The timing input has
NWin [720M, 820M],NPATin [6000, 8000],LMINin {5, 6} andLMAXin [13, 16]: about 12G letters (6 GB of generator output) and about 45K automaton states.
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 has about 770M generator words (about 12G symbols, 6 GB of raw output) and 6000-8000 patterns of length LMIN..LMAX with LMIN 5-6 and LMAX 13-16 (about 45K automaton states).
/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.