Per-frame BVH over moving soft blobs for FP32 X-ray line integrals
/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
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 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-05 and atol = 1e-06; 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 has 1.9-2.1M blobs in 300-500 clusters and 30 frames of 768 x 768 pixels.
/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.