Batched mixed-radix STFT spectral features
/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
Short-time spectral features of S synthetic signals.
- Signals. Signal
shasLENsamplesx_s[t]: three linear chirps with amplitude modulation plus hashed uniform noise. Its parameters come frommake_sig(SEED, s), the sample formula issample(...)in the CPU source (mix64is the SplitMix64 finaliser,unit(h) = (h >> 11) / 2^53). Every sample can be computed independently. - Frames.
F = (LEN - NFFT) / HOP + 1frames per signal; framefholds samplesf*HOP .. f*HOP + NFFT - 1, multiplied by the windoww(t) = sin(pi (t+0.5)/NFFT)^WP * (1 + WG cos(4 pi (t+0.5)/NFFT)). - Spectrum. Complex DFT of length
NFFT(NFFT = 2^a 3^b 5^c); powerP_k = |X_k|^2for binsk = 0 .. NFFT/2(nbin = NFFT/2 + 1bins). - Per-frame features (with
E = sum_k P_k,eps = 1e-10 * E / nbin):log E; centroidC = sum k P_k / E; spreadsqrt(sum (k - C)^2 P_k / E); flatnessexp(mean_k log(P_k + eps)) / (E/nbin + eps); flux (framesf >= 1)sum_k (sqrt(P_k) - sqrt(P_k^{prev}))^2 / E; for each ofNBbandslog(sum_k W_bk P_k + eps), whereWare triangular filters on the warped scalem(k) = log(1 + k/K0),K0 = max(1, NFFT/50)(seemake_bands). - Per-signal features (
5 + 2*NBnumbers): the frame means of log energy, centroid, spread, flatness, band log energies; the mean flux over frames1..F-1; and for each band the mean over frames1..F-1of the squared change of its log energy from the previous frame (flux and changes are 0 whenF = 1).
The CPU program uses its own mixed-radix (5, 3, 4, 2) Stockham FFT in double precision. Reduced precision is allowed for the transform: an FP32 FFT passes the tolerance below if the per-frame and per-signal accumulations (and the logs) are done in double precision.
Input format
One line: S LEN NFFT HOP NB WP WG SEED (WG decimal, SEED unsigned 64-bit, the rest integers).
Output format
signals S len LEN nfft NFFT hop HOP frames F bands NB
mean <5 + 2*NB values: mean over all signals of each per-signal feature>
meansq <5 + 2*NB values: mean over all signals of the squared feature>
signal i <5 + 2*NB values> (12 lines, i = s*S/12 for s = 0..11; fewer if S < 12)
Feature order: log energy, centroid, spread, flatness, flux, NB band log energies, NB band
changes. Values are printed with %.10e and compared numerically with rtol = 2e-5,
atol = 2e-5.
Hidden inputs
1 <= S <= 640,NFFT <= LEN <= 2^19,NFFTis a 5-smooth number (2^a 3^b 5^c) up to 2000 (including 1, 2, pure powers of 3, 5 and 2),max(1, NFFT/16) <= HOP <= NFFT,1 <= NB <= 32(some cases have more bands than bins, giving empty bands),1 <= WP <= 4,-0.3 <= WG <= 0.3.- Correctness inputs include a single frame per signal, one-sample frames, no overlap
(
HOP = NFFT) and one signal of2^19samples. - The timing input has
Sin[512, 640],LEN = 2^19,NFFTin{960, 1000, 1080, 1200, 1440, 1500, 1600, 1800, 2000},HOP = NFFT/8andNBin[16, 32].
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 have the same tokens as the CPU program's output. Numeric tokens may differ by at most
atol + rtol*|expected|with rtol = 2e-05 and atol = 2e-05; every other token must be identical. 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 512 to 640 signals of 2^19 samples, an FFT length in {960, ..., 2000} with hop NFFT/8 (about 2 to 3 million FFTs) and 16 to 32 bands.
/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.