Query-by-example keyword spotting with an LB_Keogh -> banded DTW cascade
/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
A query-by-example keyword-spotting job over an archive of synthetic speech feature streams (16-dimensional cepstral-like frames). The CPU source is the exact specification; in short:
- Templates. A 48-entry phone codebook and
Kkeyword templates are derived from the seed. Each template is 4–8 phones of 4–10 frames each (lengthL_kin 16..64, linearly interpolated towards the next phone). The template set is normalised with one set-level integer CMVN to int8. Each template gets a band radiusr_k = max(1, L_k*R/100), a thresholdtau_k = A*L_kand per-dimension Keogh envelopes (max/min of the template over[j-r_k, j+r_k]). - Streams.
Sstreams ofTframes: random phone sequences (8-frame segments, interpolated), additive noise, a per-stream channel bias and gain. Each full 384-frame slot may carry one planted keyword occurrence (probabilityPL/1000), time-warped by 0.88–1.12. Every stream is CMVN-normalised with its own integer mean/std (isqrt) and clamped to int8. - Search. For every stream, every start
twitht+L_k <= T, and every templatek: LB_Keogh of the window against the envelope (weighted L1 outside[Lo,U], early abandoned as soon as it exceedstau_k); survivors get a Sakoe-Chiba banded DTW (|i-j| <= r_k, frame cost = weighted L1 with weights 5,4,4,3,3,3,2,2,2,2,1,1,1,1,1,1, horizontal/vertical steps add penaltyP, abandoned when a whole row exceedstau_k). A detection is(k, s, t, dist)withdist <= tau_k. The detection set is exactly "all windows whose banded DTW is at mosttau_k"; the lower bound only prunes work. - NMS. Within each (template, stream), a detection is kept iff no other detection with
|t'-t| <= L_k/2has a smaller(dist, t)pair. - Scoring. A planted occurrence of
kat startpis hit if a kept detection ofkin the same stream has|t-p| <= L_k/4; a kept detection is true if such an occurrence exists, otherwise a false alarm. Recall/precision are reported in permille (integer division).
Input format
One line: S T K R P A PL seed (all integers, seed is unsigned 64-bit).
Output format
streams S frames T templates K
planted N raw_detections N kept N true N false_alarms N hits N
recall_permille N precision_permille N checksum HEX16
kw k L L_k r r_k tau tau_k planted N raw N kept N true N hits N mind N chk HEX16 (K lines)
raw counts detections before NMS, mind is the smallest kept distance (-1 if none), chk is the
sum over kept detections of mix64((s<<40) ^ (t<<8) ^ k) + dist (mod 2^64), and the global checksum is
sum_k chk_k * (2k+1) (mod 2^64). Output must match exactly.
Hidden inputs
1 <= S <= 100, 1 <= T <= 63000, 1 <= K <= 32, 8 <= R <= 20, 0 <= P <= 80,
300 <= A <= 600, 0 <= PL <= 1000. Correctness inputs (12) include T = 1 (no window fits),
T = 63 (only short templates fit), T < 384 (nothing planted), PL = 0 and PL = 1000,
K = 1 and K = 32, P = 0, the loosest threshold A = 600 and random small archives with
S <= 4, T <= 9000. The timing input has about 90 streams of 57000–63000 frames, K in 24..28,
R in 12..16, P in 30..50, A in 420..470, PL in 300..500.
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 searches about 90 streams of 57000-63000 frames (about 5.4M start positions) against 24-28 keyword templates of 16-64 frames.
/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.