3D periodic filter-bank energy with a custom FFT
/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
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 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-09 and atol = 1e-12; 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 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.
/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.