3D periodic filter-bank energy with a custom FFT
/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 3D periodic grid of NX x NY x NZ voxels (each side a power of two; voxel (x, y, z) has
linear index i = (z*NY + y)*NX + x) carries a white-noise field
f_i = 2*unit(mix64(SEED ^ (i * 0xD1B54A32D192ED03))) - 1, where mix64 is the SplitMix64
finaliser and unit(h) = (h >> 11) / 2^53.
The program builds a bank of J filters. Filter j is a truncated, anisotropic, modulated
"ring" kernel whose parameters (three widths, an Euler-angle frame, a modulation frequency and
phase, a ring coefficient, a truncation radius and an energy weight w_j) are derived from
SEED and j by make_kernel in the CPU source. The kernel lives on the periodic grid: for each
voxel the minimal-image displacement (dx, dy, dz) is used (dx = x if x <= NX/2, else x - NX),
and the kernel is zero outside the integer ball dx^2 + dy^2 + dz^2 <= r2max_j.
Then, all in double precision:
R_j = f (*) K_j(circular 3D convolution) for every filter, done with FFTs; report the mean ofR_j^2and ofR_j^4over the grid.- Local energy
E = sqrt(sum_j w_j R_j^2 + 0.01)per voxel; report the mean ofEandE^2. - Smoothed energy
S = (G (*) E) / sum(G)with the untruncated periodic GaussianG = exp(-(dx^2+dy^2+dz^2) / (2 SIGMA_G^2))(minimal-image displacement as above); report the mean ofS^2andS^4. EandSat 16 voxels chosen by hashing the seed.
The CPU program uses its own radix-2 complex FFT (no libraries). Any correct method is fine (real-to-complex transforms, different factorisations, direct evaluation of anything you can prove equal, ...), as long as the printed numbers agree within the tolerance below.
Input format
One line: NX NY NZ J SIGMA_G SEED — three powers of two, the filter count J, a decimal
SIGMA_G and an unsigned 64-bit SEED.
Output format
grid NX NY NZ filters J
filter j msq MEAN(R_j^2) m4 MEAN(R_j^4) (J lines, j = 0..J-1)
energy mean MEAN(E) msq MEAN(E^2)
smooth msq MEAN(S^2) m4 MEAN(S^4)
sample i E E_i S S_i (16 lines)
Values are printed with %.12e. Outputs are compared numerically with rtol = 1e-9,
atol = 1e-12: every printed value is positive and O(1e-2..1e4), so double precision is
required throughout (FP32 or mixed-precision FFTs will not pass); summation order is free.
Hidden inputs
- Each side is a power of two between 1 and 1024;
1 <= J <= 30;1.0 <= SIGMA_G <= 3.0. - Correctness inputs include a
1 x 1 x 1grid, degenerate sides of length 1 and 2, very elongated grids (e.g.4 x 4 x 1024,256 x 2 x 2) where the kernel ball wraps around the periodic box,J = 30on a small grid, and grids up to 2^19 voxels. - The timing input has 2^25 voxels (sides 256, 256 and 512 in random order) and
Jin[22, 30].
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. - Grading runs on one H100 in a fresh container without network. 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 2^25-voxel grid (sides 256, 256, 512 in random order) with 22 to 30 filters, i.e. about 50 to 65 double-precision 3D FFTs. 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.