Dense nonsymmetric solve by FP32 blocked LU with partial pivoting and FP64 iterative refinement
/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
One dense nonsymmetric linear system A X = B with N unknowns and NRHS right-hand sides,
solved to FP64 accuracy by mixed-precision iterative refinement: an FP32 LU factorisation with
partial pivoting (blocked, right-looking, 64-column panels, full row interchanges), then 8
refinement steps, each R = B - A X in FP64 with the exact matrix, a correction from the FP32
LU factors, and X += correction. The program prints norms, a signed sum and sampled entries
of each solution column.
Matrix and right-hand sides (mix64 is the SplitMix64 finaliser of the CPU source,
arithmetic mod 2^64). A = D + K, all entries integers and exact in FP32:
A[i][i] = D0 + (mix64(SEED ^ 0x1234567 ^ i) mod D0);- for
i != j, withlo = min(i, j),hi = max(i, j):v = (mix64(SEED ^ (lo*N + hi)) mod (2R+1)) - RandA[i][j] = vifi < j,-vifi > j(soKis skew-symmetric). B[i][r] = 64 * D0 * (2 * (mix64(SEED ^ 0xB0B0B0B0 ^ (r << 40) ^ i) >> 11) * 2^-53 - 1)in FP64.
The symmetric part of A is D, so sigma_min(A) >= D0 and A is nonsingular; its condition
number is about 2*sqrt(N/3)*R/D0. The hidden inputs keep it between 1,000 and 8,000 (except the
trivially conditioned edge cases), where FP32 alone gives only 3-4 correct digits and the
refined solution is accurate to about 1e-12 relative.
Refinement as done by the CPU. X = 0. Each of the 8 steps computes R = B - A X in FP64
(FP32 entries of A widened to FP64), then per column r: e = binary exponent of
max_i |R[i][r]| (frexp), y = float(R[:, r] * 2^-e), apply the row interchanges, solve
L y = y and U z = y in FP32, and add z * 2^e to X[:, r] in FP64 (a column with
R = 0 is left unchanged). The refinement has converged to FP64 accuracy (corrections around
1e-13 relative) after 3-5 steps.
Any method that reaches the same solution within the tolerance below is fine: other blockings and pivot orders, FP64 or tensor-core (TF32/FP16/BF16, with scaling or split-precision tricks) factorisations, other refinement schemes (e.g. GMRES-based), or stopping early once converged. FP32 accuracy alone, or a single refinement step, is not enough.
Input format
One line: N NRHS SEED D0 R with 1 <= N <= 32768, 1 <= NRHS <= 8, SEED unsigned 64-bit,
1 <= D0 <= 2^22, 0 <= R <= 2^22.
Output format
n N nrhs NRHS D0 D0 R R
rhs r norm2 S wsum T maxabs M (two lines per right-hand side r = 0..NRHS-1)
rhs r x x_0 x_1 x_2 x_3 x_4 x_5
S = sqrt(sum_i X[i][r]^2), T = sum_i sign_i * X[i][r] with sign_i = +1 if
mix64(SEED ^ 0x5EED5EED ^ i) is odd and -1 otherwise, M = max_i |X[i][r]|, and the six
sampled entries are X[idx_s][r] with idx_s = floor(N*s/6) + (7s mod (N - floor(N*s/6))),
s = 0..5. All values are printed with %.12e. Outputs are compared numerically with
rtol = 1e-9 and atol = 1e-9 per value (solution entries are mostly of order 0.01-10 and at
most about 64 in absolute value).
Hidden inputs
Correctness inputs (17): N = 1 and a 3x3 diagonal system (R = 0), N = 2 with 8 right-hand
sides, N = 17, 63, 64, 65, 129, 300, 500, 777, 1024, 2000 with condition numbers 50-8,000,
R = 2^22 (largest entries), D0 = 1 with R = 3, and three random systems with
2 <= N <= 1500, 1-8 right-hand sides and condition number 1,000-8,000. R is between 2^19
and 2^21 unless stated. The timing input has N from 15,000 to 16,384 (about 2 GB for A and
its FP32 LU), 4-8 right-hand sides, R in [2^19, 2^21] and condition number 2,000-6,000.
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 have the same tokens as the CPU program's output. Numeric tokens may differ by at most
atol + rtol*|expected|with rtol = 1e-09 and atol = 1e-09; every other token must be identical. 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 system with 15,000 to 16,384 unknowns (about 2 GB for A and its FP32 factors), 4-8 right-hand sides and condition number 2,000-6,000; the FP32 factorisation (about 2.5e12 flops) dominates.
/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.