Power iteration on D^dagger D for a twisted anisotropic Wilson-Dirac operator
/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
Power iteration on D^dagger D, where D is an anisotropic Wilson-Dirac operator with SU(3) gauge
links, twisted boundary phases and a site-dependent mass on a periodic 4D lattice
LX x LY x LZ x LT (FP64 complex throughout). The CPU source is the exact specification.
- Fields. Site
i = x + LX*(y + LY*(z + LZ*t)). A spinor has 4 spins x 3 colours (24 reals); each site has 4 linksU_mu(i)(mu = 0..3 for x, y, z, t), 3x3 complex. Withuval(key, n) = (mix64(key ^ (n * 0xD6E8FEB86659FD93)) >> 11) * 2^-52 - 1(mix64= SplitMix64 finaliser) and keysKL, KM, KV = mix64(seed ^ 0x1111111111111111 / 0x2222222222222222 / 0x3333333333333333):- link
U_mu(i)starts fromA = I + EPS * (R + i R')with entriesuval(KL, 18*(4i+mu) + 2*(3a+b))(real) and... + 1(imaginary); rows 0 and 1 are Gram-Schmidt orthonormalised and row 2 is the complex conjugate ofrow0 x row1, so every link is an exact SU(3) matrix; - mass
m_i = 1 + MASS_AMP * uval(KM, i); - start vector
x_i[s][a] = uval(KV, 24i + 2(3s+a)) + i * uval(KV, 24i + 2(3s+a) + 1), normalised.
- link
- Operator.
`(D psi)(i) = m_i psi(i) - sum_mu kappa_mu [ (1 - gamma_mu) U_mu(i) psi(i+mu) f_mu^+(i)
- (1 + gamma_mu) U_mu(i-mu)^dagger psi(i-mu) f_mu^-(i) ]
, wheref^+ = exp(+i theta_mu)when the forward hop wraps around the lattice (c_mu = L_mu - 1),f^- = exp(-i theta_mu)when the backward hop wraps (c_mu = 0), and 1 otherwise, withtheta_mu = 2 pi P_mu / 128(P = 64is antiperiodic).D^daggeris the same expression with(1 - gamma_mu)and(1 + gamma_mu)exchanged. The gamma matrices are a Euclidean chiral basis given in the source (GPERM,GPH: rowsofgamma_muhas one nonzero entry), withgamma_5 = diag(1, 1, -1, -1). Since(1 -+ gamma_mu)` has rank 2, only two spin components per hop are multiplied by the link (spin projection).
- (1 + gamma_mu) U_mu(i-mu)^dagger psi(i-mu) f_mu^-(i) ]
- Iteration.
v_0 = x / |x|; fork = 1..K:w = D v_{k-1},lambda_k = |w|^2,x = D^dagger w,nu_k = |x|,v_k = x / nu_k. - Final vector. Per time slice
t:norm_t = sum |v_K|^2andchirality_t = sum (|spins 0,1|^2 - |spins 2,3|^2)over the slice's sites. Eight sampled components: fork = 0..7,h = mix64(seed ^ ((0xC0C0A0A0 + k) * 0x9E3779B97F4A7C15)), siteh mod V, spin(h >> 40) & 3, colour(h >> 44) mod 3, printed asv_K * sqrt(12 V)(real and imaginary part).
The CPU program applies each operator as one parallel pass and sums |.|^2 over fixed
(t, z) slabs in a fixed order, so its output does not depend on the thread count.
Input format
LX LY LZ LT K SEED
KAPPA_X KAPPA_Y KAPPA_Z KAPPA_T
P_X P_Y P_Z P_T
EPS MASS_AMP
All extents are even and at least 2; SEED is an unsigned 64-bit integer; P_mu are integers.
Output format
lattice LX LY LZ LT iterations K
rq k LAMBDA_k NU_k (k = 1..K)
slice t NORM CHIRALITY (t = 0..LT-1)
comp SITE SPIN COLOUR RE IM (8 lines)
Floating-point values are printed with %.12e and compared with a relative tolerance of 1e-8
plus an absolute tolerance of 1e-10; integer tokens and words must match exactly. FP64 arithmetic
is required (any summation order or FMA use is fine; storing links or spinors in FP32/FP16 will
not meet the tolerance). Reconstructing links from two stored rows is exact up to rounding.
Hidden inputs
2 <= LX, LY, LZ <= 32, 2 <= LT <= 64 (all even), 0 <= K <= 130, KAPPA_mu in
[0.05, 0.14], P_mu in [0, 127], EPS in [0, 1.5], MASS_AMP in [0, 0.3], at most
32^3 x 64 sites. Correctness inputs include K = 0, the 2^4 lattice (both neighbours in a
direction are the same site), the free field (EPS = 0, MASS_AMP = 0, no twist), unit links
with an antiperiodic time direction, elongated lattices (4x4x4x64, 32x2x2x2, 2x32x30x4) and
lattices up to 16^4. The timing input has the shape and size of /app/inputs/timing_example.in.
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-08 and atol = 1e-10; 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:
/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.