Reduced row-echelon form of one huge GF(2) bit matrix with nullspace digests
/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
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 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: 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.
/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.