Polar-code link simulation with dynamic frozen bits and SC decoding
/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 link-level Monte Carlo simulation of a polar code, the kind of job run for every point of a
frame-error-rate curve. For each operating point (n, K, DYN, AMP, F) (block length
N = 2^n) the program does the following (mix64 is the SplitMix64 finaliser in the CPU
source, all arithmetic is integer):
- Code construction.
pseed = mix64(SEED ^ 0x5851F42D4C957F2D * (p+1))for pointp(0-based). WeightsW0 = 4096,W(j+1) = W(j) + floor(49 W(j) / 256). Indexigets the score64 * sum{W(j) : bit j of i set} + (mix64(pseed ^ C * (i+1)) & 63). Indices sorted by (score, index) ascending: the lastKare information positions, theDYNbefore them are dynamic frozen positions, all others are static frozen (value 0). A dynamic frozen positionihas three dependencies, each an information position< ipicked byinfo[mix64(...) % m](m= number of information positions belowi; none ifm = 0, then it behaves like a static frozen bit); its value is the XOR of the bits at the three dependencies (a repeated dependency cancels). - Per frame
fr(0..F-1). Frame seedfs = mix64(pseed ^ 0x9E3779B97F4A7C15 * (fr+1)). Information bitiis the top bit ofmix64(fs ^ C * (i+1)); dynamic frozen bits follow from their dependencies. Encoding is the natural-order polar transformx = u F^{(x)n}(for len = 1, 2, .. N/2: x[j] ^= x[j+len]on the first half of every block of2 len). - Channel.
y = (x ? -AMP : AMP) + noise, wherenoiseis the sum of the four 16-bit fields ofmix64(fs ^ ... ^ C * (i+1))minus 131070 (Irwin-Hall, sd ~ 37837). The channel LLR isclamp(floor(y / 2048), -63, 63). - Successive-cancellation decoding in the usual depth-first order (left child first),
with min-sum
f(a,b) = sign(a) sign(b) min(|a|,|b|)(sign of 0 is +),g(a,b,s) = clamp(s ? b - a : b + a, -127, 127), hard decisionu = (L < 0)at information leaves, 0 at static frozen leaves and the XOR of the already decided dependency bits at dynamic frozen leaves. Partial sums are combined as(left XOR right, right). - Statistics. Information-bit errors, frame errors, a 16-bin histogram of the first wrong
information position (
bin = (first * 16) >> n, frames with errors only), and the checksumsum over frames and decided information bits equal to 1 of mix64((fr << 13) ^ i ^ pseed)(mod 2^64).
Input format
P SEED
n K DYN AMP F (P lines)
1 <= n <= 12, 0 <= K <= 2^n, 0 <= DYN <= 2^n - K, 0 <= AMP <= 10^6, 0 <= F,
SEED is an unsigned 64-bit integer.
Output format
One line per point:
pt p N N K K dyn DYN amp AMP frames F biterr BE frameerr FE firsterr h0 .. h15 check XXXXXXXXXXXXXXXX
then total biterr SUM frameerr SUM check XXXXXXXXXXXXXXXX (checksums in 16 hex digits, sums
mod 2^64). The output must match exactly.
Hidden inputs
Correctness inputs (10 files, 1 to 6 points each) include n = 1, 2, 3, K = 0, K = N,
DYN = N - K, AMP = 0 (pure noise), AMP = 10^6 (no errors), F = 0, seeds 0 and
2^64-1, n = 12 with a few hundred frames, and random points with 3 <= n <= 11 and up to
about 1.5*10^7 / (N n) frames. The timing input has 6 points with n in {10, 11, 12}, the six
rates 1/4, 1/3, 1/2, 2/3, 3/4, 5/6 (K = round(R N)), DYN <= N/16, amplitudes in the
waterfall region (AMP = 18000 + 70000 R + [-4000, 2000]) and F = round(40 / (4.4e-9 N n)) frames per point (about 185 000 for n = 12 up to
890 000 for n = 10; every point has about the same F N n).
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 6 operating points (N = 1024, 2048 or 4096, rates 1/4 to 5/6, waterfall-region amplitudes) with 185k-890k frames each, about the same FNlog2(N) per point.
/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.