Multichannel rational-ratio sample-rate conversion with dither and gated metering
/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 batch sample-rate-conversion job, as run when a multichannel audio or RF capture library is
converted between rates (44.1 kHz <-> 48 kHz, 32 kHz <-> 44.1 kHz, ...). Each job converts C
channels of N input samples by the rational factor L/M and meters the result. Everything is
integer arithmetic, so the output is exact.
- Synthesis. Channel
cof jobjis 24-bit PCM generated per sampleifrom a counter-based hash (mix64, the SplitMix64 finaliser): three DDS tones read from a 4096-entry Q15 sine table, a gain envelope that changes every 2^14 samples (1 in 8 segments silent), "hot" square-wave bursts in 1 of 8 segments of 2^15 samples, and uniform noise; clamped to [-2^23, 2^23-1]. Seechan_keyandsynthin the CPU source. - Filter design (integer only). A prototype of
L*Ttaps: windowed sinc with cutoffR/1000 * 1/(2*max(L,M))(cycles per upsampled sample), 4-term Blackman-Harris window. The sine is a fixed-point odd polynomial on Q32 turns (isin_q30), the sinc division and window use exact 64/128-bit integer arithmetic. Phasep(0 <= p < L) owns tapsh[p + k*L], k < T; every phase is rescaled to sum to exactlyG << 10(the per-job gainGin Q12, residual added to the first largest-magnitude tap).BANKis a checksum of the bank. - Polyphase resampling.
NOUT = ceil(N*L/M). Outputmusesv = m*M + floor(L*T/2),n = floor(v/L),p = v mod Landacc = sum_{k<T} bank[p][k] * x[n-k](int64, samples outside[0, N)are 0). - Requantisation. TPDF dither
dfrommix64of the output index (two 16-bit uniforms),q = (acc + d*16384 + 2^29) >> 30(arithmetic shift), saturated to 16 bit; every saturation counts as a clip. - Metering. Per channel: peak
|q|, clip count, energysum q^2, and the checksumsum mix64((q & 0xFFFF) ^ (m << 16) ^ (c << 58))(mod 2^64). The output is cut into sub-blocks of 4096 samples (only complete ones); windows of 4 consecutive sub-blocks (hop 1) get the channel-weighted energyz = sum_c w_c * E_c(w = 181 for channels withc mod 6in {4,5}, else 128). Two-stage gating: absolute gatez >= 400*16384*128, then relative gate at one tenth of the mean of the absolutely gated windows;LOUDis the floor mean of the windows passing both gates.
Input format
SEED J
C N L M T R G (J lines, one per job)
SEED is a 64-bit unsigned integer. Per job: 1 <= C <= 16, 0 <= N <= 2^28,
1 <= L, M <= 640, 1 <= T <= 512, L*T <= 262144, 800 <= R <= 990, 2048 <= G <= 6144.
L and M need not be coprime.
Output format
Per job:
JOB j L=.. M=.. T=.. C=.. N=.. NOUT=.. BANK=<u64>
CH c PEAK CLIPS ENERGY HASH (C lines)
PROG NSUB NWIN NABS NREL LOUD MAXWIN
NSUB complete sub-blocks, NWIN = max(0, NSUB-3) windows, NABS/NREL windows passing the
absolute / both gates, LOUD the gated mean (0 if no window passes), MAXWIN the largest z.
Hidden inputs
Correctness inputs (12 files, 1-4 jobs each): empty and 1-sample channels, L = M = 1 with a
single tap, extreme ratios 640/1 and 1/640, 16 channels, seed 0 and 2^64-1, gain 6144 (heavy
clipping), the largest bank (L=512, T=512), non-coprime ratios, and random jobs with
N <= 10^6. The timing input has 3 jobs with distinct ratios from {160/147, 147/160, 441/320,
320/441, 2/1, 1/2}, 6 <= C <= 10, 320 <= T <= 448 and N chosen so that each job does about
2*10^11 multiply-accumulates (C x NOUT x T), i.e. tens of millions of samples per channel.
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 source generation only. Write /app/gpu/main.cu; compilation,
execution and verification are performed later in a separate verifier environment.
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. - GPU verification uses the backend selected for this run: an H100 attached to the separate verifier, or a remote H100 worker. Hidden inputs use a fresh random seed.
- 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.
- GPU execution: a separate, untimed CUPTI check must observe completed GPU kernel activity on the hidden timing input. A CPU-only submission receives reward 0 even if its output is correct.
- Speed: The timing input has 3 jobs (distinct 44.1k/48k/32k-style ratios, 6-10 channels, 320-448 taps per phase), each about 2e11 multiply-accumulates, i.e. 50-140 million input samples per channel. 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 public input examples for understanding the input format.