Streamed multi-pattern automaton over a host-generated text
/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
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 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. - This sandbox has no GPU.
nvccworks here for compiling. To run on the GPU, use/app/bin/gpu_run [--repeat N] [--quiet] SOURCE.cu INPUT_FILE...: it compiles the file with the flags above on a remote H100 worker, runs it on each input, and prints stdout, exit code and wall-clock time. Grading also runs your code on an H100 worker, one job per GPU at a time. 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 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). 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.