Punctured K=9 soft Viterbi decoding with a-priori input
/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
Soft-decision maximum-likelihood (Viterbi) decoding of a batch of independent frames sent over a
noisy channel with a punctured, terminated, rate-1/2 convolutional code of constraint length 9
(256 trellis states). Everything is generated inside the program from the seed with the
counter-based hash hkey(seed, tag, f, j) = mix64(seed + ((tag << 56) | (f << 14) | j)).
For frame f:
hf = hkey(seed, 0, f, 0); lengthL = LMIN + hf % (LMAX - LMIN + 1)info bits; puncturing patternpats[(hf >> 40) % NP].- Info bits: word
jishkey(seed, 1, f, j)(bittof the frame is bitt % 64of wordt / 64). Eight zero tail bits follow, so the trellis hasT = L + 8steps and starts and ends in state 0. - Encoder: the 9-bit window at step
tisw = (u_t << 8) | (u_{t-1} << 7) | ... | u_{t-8}; coded bitsc0 = parity(w & G0),c1 = parity(w & G1). - Channel (per step,
hn = hkey(seed, 2, f, t)):r = clamp(±AMP + floor(g * NOISE / 128), -127, 127)(+AMPfor a 0 bit) wheregis the sum of four bytes ofhnminus 510 (bytes 0-3 forc0, bytes 4-7 forc1). The decoder seesq = compress(r)(magnitudes above 48 are halved beyond 48), or 0 where the puncturing pattern drops the bit (pattern positiont % P). - A-priori value for info bit
t < L:clamp(±APRI + floor(g' * APRI / 64), -31, 31)from bytes 2-5 ofhkey(seed, 3, f, t); 0 for tail steps.
Decoder: path metrics are maximised; the branch metric into state s' from predecessor
p = ((s' << 1) & 255) | b is ±q0 ±q1 ±a (sign - when the corresponding coded bit, or the input
bit u = s' >> 7, is 1). Metrics are 32-bit integers, start at 0 for state 0 and -2^28 elsewhere,
are never normalised, and states with u = 1 are forced to -2^28 during the 8 tail steps. On a tie
the even predecessor (b = 0) wins. Traceback starts from state 0 at step T. Per frame the program
records the final metric of state 0, the number of decoded info bits that differ from the
transmitted ones, and hash = sum_j mix64(dw_j ^ (j * 0x9E3779B97F4A7C15)) over the decoded info
words dw_j (same packing as the info words), all modulo 2^64.
The six puncturing patterns (positions 0,1,2,... of the two coded streams) are:
0 rate 1/2 (1/1), 1 rate 2/3 (11/10), 2 rate 3/4 (101/110), 3 rate 4/5
(1011/1100), 4 rate 5/6 (10101/11010), 5 rate 7/8 (1000101/1111010).
Input format
NF SEED
G0 G1
LMIN LMAX
AMP NOISE APRI
NP p_1 ... p_NP
G0, G1 are octal. p_i are pattern ids in 0..5.
Output format
frames NF infobits B
biterrors E frameerrors FE
metricsum S
framehash H
pattern p frames n biterrors e frameerrors fe metricsum s (one line per pattern used, ascending p)
errhist n0 n1 n2 n3 n4 n5
worst f errors e (omitted when NF = 0)
frame f L L pattern p metric m errors e hash h (frames 0..min(NF,8)-1)
B is the total number of info bits, E the total bit errors, FE the number of frames with at
least one error, S the sum of final metrics, H = sum_f mix64(hash_f + f * 0xD1B54A32D192ED03)
mod 2^64. errhist counts frames with 0, 1-3, 4-15, 16-63, 64-255 and 256+ bit errors. worst is
the first frame with the largest number of errors.
Hidden inputs
0 <= NF <= 400000,1 <= LMIN <= LMAX <= 8192,0 <= AMP <= 127,0 <= NOISE <= 64,0 <= APRI <= 31,1 <= NP <= 6; generator pairs have taps 0 and 8 set and free distance 12.- Correctness inputs include
NF = 0, a single 1-bit frame, frames of length 1-9, a noiseless channel, very noisy channels with hundreds of errors per frame, saturating amplitudes, frames of the maximum length 8192 and random mixes of patterns. - The timing input has about 260000 frames with
Luniform in [2048, 8192],AMP = 32,NOISEin [14, 18],APRIin [2, 6] and all six patterns (a few percent bit errors on the high-rate patterns, none on rate 1/2).
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 about 260000 frames with 2048-8192 info bits each (about 1.3G trellis steps), all six puncturing patterns and a noise level that leaves a few percent bit errors on the high-rate patterns.
/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.