Reduced row-echelon form of one huge GF(2) bit matrix with nullspace digests
/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
The reduced row-echelon form (RREF) over GF(2) of one large dense M x N bit matrix, and
digests of its rank, pivot columns, RREF rows and the canonical nullspace basis. The CPU uses
Gauss-Jordan elimination in 64-column panels: for each panel it finds the pivots on the 64-bit
strip words of the not-yet-pivot rows (smallest row index first), forms the panel's reduced
pivot rows, and XORs them into every other row. The RREF is unique, so any elimination order,
panel width or pivot-row choice that produces the same RREF is fine.
Matrix (all generated in the program; mix64 is the SplitMix64 finaliser of the CPU
source, arithmetic mod 2^64). Column c of a row is bit c mod 64 of word c / 64; there are
W = ceil(N/64) words per row. Let rh(i, t, j) = mix64(SEED ^ mix64((i << 8) + t) ^ (j * 0xD6E8FEB86659FD93)).
- Segments:
start_s = floor(N*s/S)fors = 0..S; weightw_s = 2^(mix64(SEED ^ (0xABCDEF12345 + s)) mod 4)and cumulative weightscum_s = w_0 + ... + w_s. - Row kind:
t = rh(i, 0, 0) mod 1000; dependent ift < DEP_PM, else sparse ift < DEP_PM + SPARSE_PM, else staircase. - Staircase row
i:u = rh(i, 1, 0) mod cum_{S-1},s= the smallest index withcum_s > u,b = start_s; wordwisrh(i, 2, w)with the bits of columns< band>= Ncleared. - Sparse row
i:t = 2 + rh(i, 3, 0) mod 7; fork < ttoggle columnrh(i, 3, k+1) mod N(repeats cancel). - Dependent row
i: XOR of2 + rh(i, 4, 0) mod 2staircase rows; thek-th starts atj = rh(i, 4, k+1) mod Mand movesj = (j+1) mod Muntil rowjis a staircase row. If the matrix has no staircase row at all, dependent rows are zero.
RREF. Rank r, pivot columns p_0 < ... < p_{r-1}, RREF rows R_0 .. R_{r-1} (R_k has its
leading 1 in column p_k and 0 in every other pivot column). The other N - r columns are free.
For a free column f the nullspace basis vector v_f has v_f[f] = 1, v_f[p_k] = R_k[f], and 0
elsewhere.
Input format
One line: M N SEED S DEP_PM SPARSE_PM with 1 <= M, N <= 200000, SEED unsigned 64-bit,
1 <= S <= 4096, DEP_PM, SPARSE_PM >= 0, DEP_PM + SPARSE_PM <= 1000.
Output format
matrix M x N segments S
rank r nullity N-r zero_rows M-r
pivot_hash PH
first_free c_1 ... c_t
last_pivot P
rref_hash RH
nullspace_weight NW
nullspace_tests o_0 o_1 o_2 o_3 hash NH
PH= sum overkofmix64((k << 32) ^ p_k ^ 0x51ED270B27)mod 2^64.first_free: the firstmin(8, N-r)free columns in increasing order (the line is justfirst_freewhen there are none).P = p_{r-1}, or-1whenr = 0.RH= sum overkofh_kmod 2^64, whereh = mix64(k + 0x2545F4914F6CDD1D)and then, forw = 0 .. W-1,h = mix64(h ^ word_w(R_k) ^ (w << 40)).NW= total number of ones in all nullspace basis vectorsv_f.- Test vectors
s_t[c] = mix64(SEED ^ (0x7F4A7C15 * (t+1)) ^ c) & 1,t = 0..3. For each freef,b_t(f) = <v_f, s_t> mod 2;o_t= number of freefwithb_t(f) = 1.h_tstarts at0x9E3779B97F4A7C15 * (t+1)and becomesmix64(h_t ^ f)for each suchfin increasing order;NH = sum_t h_t * (2t+1)mod 2^64.
Hex values are 16 lowercase digits.
Hidden inputs
Correctness inputs (17): 1 x 1, a single row, a single column, a dense 64 x 64 matrix, 200 x 65,
65 x 200, one column per segment (S = N = 300), all rows dependent (zero matrix), 99%
dependent rows, only sparse rows, S = 4096, sizes up to 12000 x 11500, and four random
inputs with M, N <= 5000, S <= min(4096, N), DEP_PM <= 300 and any SPARSE_PM.
The timing input has N from 60,000 to 68,000 columns, M = N * (1.00 .. 1.06) rows (about
0.45-0.6 GB of bits), S 64-512, DEP_PM 60-140 and SPARSE_PM 20-60.
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. - Grading runs on one H100 in a fresh container without network. 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: One matrix with 60,000 to 68,000 columns and 0-6% more rows (about 0.45-0.6 GB of bits) built from staircase rows that start at segment boundaries, 6-14% dependent rows and 2-6% sparse rows. 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.