Pseudo-spectral forced viscous 2D Burgers with integrating-factor RK2
/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
A pseudo-spectral simulation of a forced, damped, viscous 2D Burgers (scalar conservation law)
equation on the periodic square [0, 2pi)^2, sampled on an N x N grid (N a power of two;
x runs along the row index c, y along the row number r, element (r, c) at r*N + c):
u_t + CX * d/dx(u^2/2) + CY * d/dy(u^2/2) = NU * Laplacian(u) - KAPPA * u + s(x, y)
- Initial field
u_0and forcingsare sums of cosine modesa * cos(kx*x + ky*y + phi)(12 modes with|kx|, |ky| <= 6, 6 modes with|kx|, |ky| <= 4scaled byFAMP), whose parameters come fromSEEDviamake_modesin the CPU source; both are evaluated on the grid and Fourier transformed. - Wavenumbers: index
imaps toiifi < (N+1)/2, elsei - N. The quadratic term is dealiased with the 2/3 rule (modes with3|kx| > Nor3|ky| > Nare zeroed). - Time stepping is integrating-factor RK2 (Heun) in spectral space with step
DT. WithE = exp((-NU |k|^2 - KAPPA) DT)andNL(v) = -i (CX kx + CY ky) mask * FFT(Re(IFFT(v))^2 / 2) + FFT(s):(FFT unnormalised forward, IFFT with thetextn1 = NL(u_hat); a = E (u_hat + DT n1); n2 = NL(a) u_hat <- E u_hat + DT/2 (E n1 + n2)1/N^2factor; see the CPU source for the exact form.)
All arithmetic is double precision. The CPU program uses its own radix-2 complex FFT; any correct spectral method (real-to-complex transforms, other radices, fused kernels, ...) is fine as long as the printed numbers agree within the tolerance below. The equation is dissipative and not chaotic (viscous scalar Burgers is L1-contractive), so rounding differences stay at rounding level over the whole run.
Input format
One line: N STEPS DT NU KAPPA CX CY FAMP SEED (N, STEPS integers, the next six decimals,
SEED unsigned 64-bit).
Output format
step S energy MEAN(u^2) gradient MEAN(|grad u|^2) (8 lines, checkpoints)
spectrum E_0 E_1 ... E_15
sample c r u U(c, r) (16 lines)
- Checkpoint
j = 1..8is printed after stepceil(j * STEPS / 8)(a step can be printed twice whenSTEPS < 8). The two values are computed from the spectrum by Parseval:sum |u_hat|^2 / N^4andsum |k|^2 |u_hat|^2 / N^4. E_Kis the finalsum |u_hat|^2 / N^4over modes withK^2 <= kx^2 + ky^2 < (K+1)^2.- Samples are the final field at 16 grid points chosen by hashing the seed.
Numbers are printed with %.12e (spectrum %.10e) and compared numerically with
rtol = 1e-9, atol = 1e-12. Double precision is required (FP32 transforms will not pass);
summation order is free.
Hidden inputs
Nis a power of two in[1, 1024],1 <= STEPS <= 4500,0 <= KAPPA <= 0.5,|(CX, CY)|in[0.5, 1.5](some correctness cases useCX = 0orCY = 0),0 <= FAMP <= 0.8.DT = 0.0625 / (|c| * max(1, sqrt(2) * N / 3))andNU = 18 |c| / max(N, 4).- Correctness inputs include
N = 1, 2, 4,STEPS < 8,FAMP = 0,KAPPA = 0, oneN = 1024case with two steps, and runs of up to 300 steps on grids up to 256. - The timing input has
N = 512andSTEPSin[3500, 4500].
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-09 and atol = 1e-12; every other token must be identical. Any mismatch, crash or timeout gives reward 0. - Speed: The timing input is a 512x512 grid integrated for 3500 to 4500 IF-RK2 steps (four complex 2D FFTs per step). 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.