Exact fixed-point filtered backprojection of a 600-slice parallel-beam CT scan
/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
Filtered backprojection of a synthetic parallel-beam CT scan, entirely in exact integer arithmetic.
- Angles.
theta_k = k*pi/NA(k < NA,pias the Q30 integer 3373259426).cosandsinare Q30 integers from a 30-step integer CORDIC (table and gain in the source; angles abovepi/2usepi - thetaand a negated cosine). - Sinogram.
p[k][z][j]for anglek, slicez < NZ, detectorj < NDET: 6-bit hash noise plus the parabolic profiles ofNOBJdrifting objects whose projected centre is computed with the CORDIC table, clamped to 4095 (see the generation loop). - Ramp filter. Apodised Shepp-Logan kernel
H[m] = B_m * ((KH+1)^2 - m^2) / (KH+1)^2for|m| <= KH(C division),B_0 = 26561,B_m = -(26561 / (4m^2 - 1));q[k][z][j] = (sum_m H[m] * p[k][z][j-m]) >> 4(arithmetic shift,p = 0outside the detector). - Backprojection. Voxel
(x, y)of anN x Nslice has doubled centred coordinatesX2 = 2x-(N-1),Y2 = 2y-(N-1); only voxels withX2^2 + Y2^2 <= (N-1)^2are reconstructed. For every angle:u = ((X2*cos_k + Y2*sin_k) >> 15) + ((NDET-1) << 15) + off_k(Q16 detector position,off_k = +16384for oddk,-16384for evenk: a flying focal spot),i = u >> 16,w1 = u & 65535,w0 = 65536 - w1, andacc += q[k][z][i]*w0 + q[k][z][i+1]*w1(int64; a term whose detector index is outside[0, NDET)is skipped). The voxel value isv = acc >> 16.
Input format
One line: N NZ NA NDET KH NOBJ SEED (integers, SEED unsigned 64-bit).
Output format
ct n N nz NZ na NA ndet NDET fov_voxels V
total sum S hash H min MN max MX
slice z sum S hash H min MN max MX (z = 0, step, 2*step, ... with step = max(1, NZ/16))
probe P0 P1 ... P7
Sums, minima and maxima run over reconstructed voxels (min/max print the int64 extremes
9223372036854775807 / -9223372036854775808 when a slice has none). H = sum mod 2^64 of
mix64(((z*N + y)*N + x) * 0x9E3779B97F4A7C15 + v). P_p is v of voxel (N/2, N/2) in slice
p*NZ/8 (0 if that voxel is not reconstructed).
Hidden inputs
1 <= N <= 768,1 <= NZ <= 1024,1 <= NA <= 1440,1 <= NDET <= 1100,1 <= KH <= 128,0 <= NOBJ <= 32,NA * NZ * NDET <= 4.2e8.- Correctness inputs include
N = 1(its single voxel is reconstructed) andN = 2(no voxel lies in the inscribed circle), detectors narrower and much wider than the image, 3 angles and 1440 angles,KH = 128, 32 objects, 1024 slices,N = 768withNDET = 1100, and random cases withNin[50, 200]. - The timing input has
N = 512, 560-620 slices, 1080-1200 angles,NDET = N + 6 .. N + 24,KHin[48, 96]and 12-24 objects (about 1.4e11 voxel-angle-slice updates).
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 be identical to the CPU program's output (trailing whitespace ignored). 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 reconstructs a 512 x 512 x 560-620 voxel volume from 1080-1200 angles with 518-536 detectors and a 97-193 tap filter (about 1.4e11 voxel-angle-slice updates).
/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.