Multichannel CIC decimation with compensation FIR and peak detection
/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 multichannel recording is synthesised from the seed and every channel c goes through:
- Signal
x[n],0 <= n < L: hashed noise in[-512, 511], plus a per-channel triangle tone (>> 3of a wave in[-16384, 16384]), plus bursts of +6000 on hashed 512-sample blocks (seesample()). - CIC decimator:
Nintegrator stages in 64-bit wrap-around arithmetic; after everyR-th input sample (n % R == R-1) the last integrator value goes throughNcomb stagesy - y_delayedwith differential delayM(zero initial state). The decimated signal isv[m] = (int64)comb >> (N * ceil(log2(R*M)))(arithmetic shift),m < Ld = floor(L / R). - Compensation FIR:
e[m] = (sum_{j<17} TAPS[j] * v[m-j]) >> 7withv[<0] = 0and the 17 integer taps in the source. - Peaks:
mis a peak whenP <= m < Ld - P,e[m] > e[m-j]ande[m] >= e[m+j]forj = 1..P, ande[m] - min(e[m-P..m+P]) >= THR.
Input format
One line: C L N R M P THR SEED with 1 <= C <= 16384, 0 <= L <= 2^31 - 1,
1 <= N <= 6, 1 <= R <= 32, 1 <= M <= 4, 1 <= P <= 8, 0 <= THR <= 10^6,
SEED unsigned 64-bit.
Output format
channels C decimated Ld shift SHIFT
peaks NPEAKS sum SUM energy ENERGY hash HASH chash CHASH
max VALUE at CHANNEL INDEX (or "max none" when Ld == 0)
top c:count c:count ... (up to 8 channels, most peaks first, ties by smaller c)
SUM is the signed sum of all e, ENERGY the sum of e^2 mod 2^64, HASH the sum over
peaks of mix64(((c << 40) | m) ^ ((uint32)e[m] << 20)), and CHASH the sum over channels of
mix64((c << 32) ^ peaks_c ^ (energy_c * 0x9E3779B97F4A7C15)), all mod 2^64. max reports the
largest e and its first position (smallest channel, then smallest m).
Hidden inputs
Correctness inputs include L = 0, L < R (no decimated samples), R = 1, N = 1 and
N = 6, M = 4, P = 1 and P = 8, THR = 0, a single channel, 16384 channels, and random
parameters within the ranges above. The timing input has 7000 to 8192 channels of 5,000,000
samples each, N in [3, 5], R in {8, 16, 32}, M in {1, 2}, P in [2, 6] and
THR in [50, 1500].
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 7000 to 8192 channels of 5,000,000 samples each (about 38 gigasamples), N in [3, 5], R in {8, 16, 32}, M in {1, 2}.
/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.