Per-frame BVH over moving soft blobs for FP32 X-ray line integrals
/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
M soft blobs move linearly through 3D space; a camera orbits the scene; for each of F
frames every pixel of a W x H image accumulates X-ray style line integrals through the
blobs. The CPU program rebuilds a bounding-volume hierarchy over the blobs' screen-space
footprints every frame to find the blobs that touch each pixel, but the result is defined
as a sum over all blobs: any acceleration structure (or none) is acceptable.
Blob j (see make_blob in the CPU source) has a base center and velocity (double), a
radius R, density rho and channel weights c0, c1, c2 (floats). For frame f, in double
precision: center p0 + f*v, camera-space coordinates (X, Y, Z) with the camera basis
defined in the CPU source; blobs with Z <= 0.05 are skipped; otherwise they are rounded to
floats su = X/Z, sv = Y/Z, sr = R/Z, a = (16/15)*R*rho. Pixel (px, py) has float
screen coordinates u = (2(px+0.5)/W - 1) * 0.45 * W/H, v = (1 - 2(py+0.5)/H) * 0.45
(computed in double, then rounded). In FP32:
q = 1 - ((su-u)^2 + (sv-v)^2) / sr^2
if q > 0: K = a * q^2 * sqrt(q); I_ch += K * c_ch (ch = 0, 1, 2)
T_ch = exp(-I_ch)
(K is the integral of rho (1 - r^2/R^2)^2 along a line through a sphere in the
weak-perspective approximation; it vanishes smoothly at the footprint edge, so which blobs
are near-tangent to a pixel does not matter.)
Input format
One line: M F W H NC SEED (blobs, frames, image width and height, number of blob
clusters, seed).
Output format
Two lines per frame:
frame f T sumT0 sumT1 sumT2 I sumI0 sumI1 sumI2
tiles f t00 t01 ... t33
sumT_ch and sumI_ch are sums over all pixels; t_ab is the sum of I0+I1+I2 over the
pixels of tile row a = py*4/H, tile column b = px*4/W. Values are printed with %.9e.
The comparison is numeric with rtol = 1e-5, atol = 1e-6: any summation order, FMA
contraction and fast-math intrinsics (__expf, approximate sqrt) are fine; FP16/BF16
accumulation is not. Per-pixel arithmetic must stay FP32-or-better.
Hidden inputs
0 <= M <= 3,000,000, 0 <= F <= 64, 1 <= W, H <= 1024, 1 <= NC <= 100000.
Correctness inputs include no blobs, one and two blobs, a single pixel, one dense cluster,
every blob in its own cluster (spread out), wide and tall images, and random mid-sized
scenes.
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-05 and atol = 1e-06; every other token must be identical. Any mismatch, crash or timeout gives reward 0. - Speed: The timing input has 1.9-2.1M blobs in 300-500 clusters and 30 frames of 768 x 768 pixels. 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.