Cauchy Reed-Solomon encode and erasure repair over GF(2^8)
/app/cpu/main.cpp is a multicore CPU program (C++17, OpenMP). It is built as
/app/bin/cpu_baseline with g++ -O3 -march=native -fopenmp -std=c++17 and run as
cpu_baseline INPUT_FILE
It reads one 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 CPU source is the specification: when this text and the code disagree, the code wins.
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. - This sandbox has no GPU.
nvccworks here for compiling. To run on the GPU, use/app/bin/gpu_run [--repeat N] [--quiet] SOURCE.cu INPUT_FILE...: it compiles the file with the flags above on a remote H100 worker, runs it on each input, and prints stdout, exit code and wall-clock time. Grading also runs your code on an H100 worker, one job per GPU at a time. Inputs are generated with a new random seed at grading time, so they cannot be known in advance. - 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.
- 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. 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 a few public inputs./app/bin/run_public.shcompiles your port with the flags above and compares it against the CPU baseline on each of them.