Exact fixed-point filtered backprojection of a 600-slice parallel-beam CT scan
/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
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 = 1andN = 2(no reconstructed voxel), 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 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. - This sandbox has no GPU.
nvccworks here for compiling. To run on the GPU, use/app/bin/gpu_run [--repeat N] [--quiet] SOURCE.cu INPUT_FILE...: it compiles the file with the flags above on a remote H100 worker, runs it on each input, and prints stdout, exit code and wall-clock time. Grading also runs your code on an H100 worker, one job per GPU at a time. 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 be identical to the CPU program's output (trailing whitespace ignored). Any mismatch, crash or timeout gives reward 0.
- 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). 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.