Cauchy Reed-Solomon encode and erasure repair over GF(2^8)
/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
Systematic Cauchy Reed-Solomon erasure coding over GF(2^8) for a batch of stripes: every stripe is
encoded (k data blocks to m parity blocks) and then repaired (k received blocks rebuild every erased
block). All data comes from the counter-based generator
bkey(seed, tag, s, j, w) = mix64(seed + ((tag << 56) | (s << 18) | (j << 13) | w))
(64-bit word w of block j of stripe s; bytes of a word are little-endian).
- Field. GF(2^8) defined by the primitive polynomial
POLY(hex, degree 8);x = 2generates the multiplicative group (log/exp tables as in the source). - Codes. Configuration
chaskdata andmparity blocks ofBbytes. Its parity matrixE(m x k) comes from a Fisher-Yates shuffle of the 256 field elements driven bybkey(seed, 9, c, 0, i):x_i = perm[i](i < m),y_j = perm[m + j],C[i][j] = 1/(x_i + y_j); then every column is divided by its row-0 entry and every row by its column-0 entry (row 0 and column 0 ofEbecome all ones). The generator of the code is[I_k ; E]; blocki < kis data blocki, blockk + iis parityi. - Stripe
s.hs = bkey(seed, 0, s, 0, 0); the configuration is picked byhs % sum(weights)(weights in input order);ne = (hs >> 24) % (m + 1)blocks are erased, chosen by a partial Fisher-Yates shuffle of0..k+m-1withbkey(seed, 3, s, 0, i). - Encode. Data block
jhas wordsbkey(seed, 1, s, j, w); parityiissum_j E[i][j] * data_jbytewise in GF(2^8). Hash:sum mix64(word + salt(s, i, w))over all parity words,salt(s, j, w) = ((s << 20) | (j << 13) | w) * 0x9E3779B97F4A7C15. - Repair. The received stripe is independent of the encoded one: the survivors are the first
knon-erased block indicesS_0 < ... < S_{k-1}, and survivorthas wordsbkey(seed, 2, s, S_t, w). The program inverts the k x k generator rows of the survivors by Gauss-Jordan elimination over GF(2^8) (first non-zero pivot), forms for every erased blockr(ascending) the coefficient rowR_r = G_r * inverse, and rebuilds blockrassum_t R_r[t] * survivor_t. Hashes:sum mix64(word + salt(s, 32 + r, w))over the rebuilt words, andsum mix64((s << 20) | (r << 12) | (t << 8) | R_r[t])over the coefficients (matrix hash). Stripes without erasures have no repair work.
Input format
SEED POLY
NS NC
k m B weight (NC lines)
Output format
field POLY stripes NS configs NC
config c k k m m B B stripes n erased e parity_bytes P rebuilt_bytes R (per configuration)
config c coefhash H parityhash H1 rebuilthash H2 matrixhash H3 (per configuration)
erasure_hist n0 n1 n2 n3 n4
total parityhash H1 rebuilthash H2 matrixhash H3
stripe s config c erased r1 r2 ... parity h1 rebuilt h2 (stripes 0..min(NS,6)-1)
All hashes are 64-bit sums modulo 2^64 of the per-stripe values (coefhash is a polynomial hash of
the matrix E). erasure_hist counts stripes by number of erased blocks.
Hidden inputs
0 <= NS <= 2^20,1 <= NC <= 8,1 <= k <= 16,1 <= m <= 4,8 <= B <= 65536withB % 8 == 0, weights 1..100,POLYone of the 16 primitive degree-8 polynomials.- Correctness inputs include
NS = 0, a single stripe withk = m = 1andB = 8, tiny and unusual shapes (k from 1 to 16, m from 1 to 4), thousands of stripes with tiny blocks (thousands of distinct erasure patterns), stripes of the largest shape(16, 4, 65536)and eight random configurations at once. - The timing input has about 220000 stripes over the configurations
(6,3,16384),(10,4,32768),(12,4,65536),(16,4,65536)with equal weights and a random field polynomial (about 250 GB of generated block data and 7*10^11 GF(2^8) multiply-adds).
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 220000 stripes over the shapes (6,3,16 KB), (10,4,32 KB), (12,4,64 KB) and (16,4,64 KB): about 250 GB of generated block data and 7*10^11 GF(2^8) multiply-adds.
/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.