Block LOBPCG lowest-k eigenpairs with an invented preconditioner
/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 program finds the lowest k eigenpairs of a generated sparse SPD operator with a
block LOBPCG iteration and an invented preconditioner, running a fixed number of
iterations (no convergence stop). It reports the Ritz values and residual norms.
Operator (invented, SPD). On a GX x GY grid (N = GX*GY) the operator is a
Schrodinger-like anisotropic 5-point Laplacian plus a potential:
A[i][i] = (sum of incident edge weights) + POT0 + trap(i) + hash(i), off-diagonals
A[i][j] = -w_ij. Edge weights w_ij in [0.5, 1.5] come from a symmetric SplitMix64
hash; a-direction edges are scaled by 1.25 (anisotropy). An invented anisotropic
harmonic trap trap = 6*(1.3*sa^2 + 0.7*sb^2) (with sa, sb the centred coordinates)
makes the low eigenvalues well separated. Two reflection/shift involution links
(j = N-1-i and j = (i+N/2) mod N, weak, weight scaled by 0.12) add long-range
coupling. The matrix is symmetric and diagonally dominant with a positive diagonal, hence
SPD.
Preconditioner (invented). T r is three damped-Jacobi residual-correction steps
from zero with the fixed schedule omega = {0.70, 1.10, 0.60} (a degree-3 polynomial in
the Jacobi-scaled operator).
LOBPCG. The initial block X (N x k, hashed) is orthonormalised by Cholesky-QR.
Each iteration: Ritz values lambda_c = X_c^T A X_c; residuals R = AX - X diag(lambda);
preconditioned directions W = T R, column-normalised; subspace S = [X, W, P]
([X, W] on the first iteration); Gram matrices S^T S and S^T A S; a tiny dense
Rayleigh-Ritz generalized eigenproblem (Cholesky of S^T S, then a fixed-sweep cyclic
Jacobi symmetric eigensolve) selecting the k smallest; and block updates of X and the
search direction P. All full-length reductions use a fixed order (thread-count
independent); the dense eigensolve uses a fixed sweep count.
Input format
GX GY k iters seed
One line: grid GX, GY >= 1, block size k >= 1 with 3k <= N, iteration count
iters >= 1, and a 64-bit seed.
Output format
n <N> gx <GX> gy <GY> k <k> iters <iters>
trace <sum of the k Ritz values>
frob_residual <Frobenius norm of the block residual>
ritz <c> <lambda_c> (k lines, ascending)
resid <c> <||A x_c - lambda_c x_c||> (k lines)
Floating-point fields use %.10e. Comparison is numeric with rtol = 1e-5,
atol = 1e-6.
Hidden inputs
Correctness inputs (10 files) include tiny grids (6x6, 8x8), 1D lines (1x30,
30x1), squares up to 100x90, and a random rectangle, with k in [4, 16] and
iters in [8, 16] (always 3k <= N). The timing input is a 1265 x 1265 operator
(about 1.6 million unknowns) solving for the lowest 16 eigenpairs with 18 iterations.
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-05 and atol = 1e-06; 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: The timing input is a 1265 x 1265 operator (about 1.6 million unknowns, up to 6 nonzeros per row) solving for the lowest 16 eigenpairs with 18 LOBPCG iterations.
/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.