Discrete-ordinates (Sn) transport source iteration with an invented kernel
/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 program solves a 2D steady radiation-transport problem with the discrete-ordinates (Sn) method and source iteration, for a fixed number of outer iterations (no convergence stop). It reports summary statistics of the scalar flux.
Quadrature (invented). M ordinates are placed on the unit circle at angles
theta_k = 2*pi*(k + 0.5)/M with direction cosines (mu_k, eta_k) = (cos, sin) and
weights w_k = (1 + 0.3*cos(2*theta_k + 0.7)) normalised to unit total weight.
Material (invented). Each cell has a total cross-section sigma_t in [0.6, 1.4], a
scattering cross-section sigma_s0 = c*sigma_t with c in [0.35, 0.70], a linearly
anisotropic moment sigma_s1 = a*sigma_s0 with a in [-0.25, 0.25], and a distributed
external source q in [0, 1], all from a SplitMix64 counter hash of the seed.
Scattering kernel (invented, P1). The per-ordinate source is
Q_k = q + sigma_s0*phi0 + 3*sigma_s1*(mu_k*phi1x + eta_k*phi1y)
with flux moments phi0 = sum_k w_k psi_k, phi1x = sum_k w_k mu_k psi_k,
phi1y = sum_k w_k eta_k psi_k.
Sweep (step differencing). On the unit grid, each ordinate's angular flux is solved cell by cell in upwind order:
psi_k(i,j) = ( Q_k(i,j) + |mu_k|*psi_x_up + |eta_k|*psi_y_up )
/ ( sigma_t(i,j) + |mu_k| + |eta_k| )
with vacuum inflow (0) on the boundary. The upwind neighbours are the already-swept
cells in the ordinate's travel direction. Each outer iteration sweeps all ordinates and
recombines the moments in a fixed ordinate order. All reductions use a fixed order
(thread-count independent).
Input format
NX NY M SI seed
One line: grid NX, NY >= 1, ordinate count M >= 8, source iterations SI >= 1, and a
64-bit seed.
Output format
nx <NX> ny <NY> ordinates <M> source_iters <SI>
sum_phi0 <sum of scalar flux>
sum_phi0_sq <sum of squared scalar flux>
max_phi0 <max scalar flux>
phi0 <i> <j> <phi0(i,j)> (8 sampled cells)
Floating-point fields use %.10e. Comparison is numeric with rtol = 1e-6,
atol = 1e-8.
Hidden inputs
Correctness inputs (10 files) include 1 x 1, the 1D lines 1 x 40 and 40 x 1,
2 x 2, squares 16, 64, 200, a random rectangle with sides in [80, 200], and
128 x 96, 160 x 240, with M in [16, 64] and SI in [8, 20]. The timing input
is a 1600 x 1600 grid with 64 ordinates and 70 source 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 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. - This sandbox has no GPU.
nvccworks here for compiling. To run on the GPU, use/app/bin/gpu_run [--repeat N] [--quiet] SOURCE.cu INPUT_FILE...: it compiles the file with the flags above on a remote H100 worker, runs it on each input, and prints stdout, exit code and wall-clock time. Grading also runs your code on an H100 worker, one job per GPU at a time. 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 have the same tokens as the CPU program's output. Numeric tokens may differ by at most
atol + rtol*|expected|with rtol = 1e-06 and atol = 1e-08; every other token must be identical. Any mismatch, crash or timeout gives reward 0. - Speed: The timing input is a 1600 x 1600 grid with 64 ordinates and 70 source iterations (the invented P1-anisotropic scattering kernel and a distributed external source). 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.