Batched integer particle filters with exact systematic resampling every step
/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
F independent bootstrap particle filters (sequential importance resampling), each with
N particles, track a hidden object for T steps. Everything is integer arithmetic.
Model (see dyn in the CPU source). A state is (x, y, vx, vy) (int32); positions live
on a 2^20 x 2^20 torus. One step with a 64-bit hash h:
ax = (SINT[(y >> 10) & 1023] * 3) >> 2, ay = (SINT[((x >> 10) + 256) & 1023] * 3) >> 2
vx' = vx + ax - (vx >> 4) + noise4(h, 0, QP), vy' = vy + ay - (vy >> 4) + noise4(h, 1, QP)
x' = (x + (vx' >> 2)) & (2^20 - 1), y' = (y + (vy' >> 2)) & (2^20 - 1)
SINT is a table of two parabolic arcs (peak 4096), noise4(h, half, s) sums the four bytes of
one 32-bit half of h, subtracts 510 and returns (sum * s) >> 6; >> on negative values is
an arithmetic shift. Filter f has a seed hash hf, two beacons and a hidden truth that follows
the same model. At step t the truth emits two range observations
o_b = floor(sqrt(dx_b^2 + dy_b^2)) + noise (exact integer square root, plain differences,
no wrap-around).
Filter step t = 1..T: every particle i is propagated with its own hash of (hf, t, i);
its weight is
e_b = |o_b - range_b(particle)| >> SH
w_i = ((LUT[min(e_0, 255)] * LUT[min(e_1, 255)]) >> 16) + 1, LUT[k] = floor(65535 * 64 / (64 + k^2))
so 1 <= w_i <= 65535. With C_i = w_0 + ... + w_i and W = C_{N-1}, the estimate is
est_d = floor(sum_i w_i s_{i,d} / W) for the four state components (before resampling).
Resampling is exact systematic resampling: with U = mix64(...) mod W (hashed per filter and
step), new particle k is a copy of the propagated particle a(k), the smallest i with
N * C_i > U + k * W. Per filter the program accumulates a hash chain over the step estimates,
llp = sum_t lg8(W_t) (8.8 fixed-point log2: integer part from the leading bit plus the next
8 bits), the tracking error err = sum_t |est_x - truth_x| + |est_y - truth_y| and the
diversity div = sum_t (number of distinct ancestors a(k)).
Input format
One line: F N T QP QO SH SEED (SEED is an unsigned 64-bit integer).
Output format
filters F particles N steps T
total llp L err E div D hash H
filter f est x y vx vy hash h llp l err e div d (for f < min(F, 10))
est is the estimate of the last step (all zero when T = 0), h the filter's hash chain,
L, E, D sums over filters and H = sum_f mix64(h_f ^ (f * 0x9E3779B97F4A7C15)) modulo 2^64.
Hidden inputs
0 <= F <= 4000, 1 <= N <= 4096, 0 <= T <= 1000, 0 <= QP <= 4096, 0 <= QO <= 65536,
0 <= SH <= 16. Correctness inputs include F = 0, N = 1, T = 0, N = 4096, N not a
power of two, noise-free observations with SH = 0 (most weights are 1), QO = 65536, SH = 16
(all weights equal), QP = 0 (particle degeneracy) and QP = 4096. The timing input has
2300-2500 filters with N = 4096, T = 1000, 400 <= QP <= 900, 1500 <= QO <= 5000,
5 <= SH <= 7.
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 be identical to the CPU program's output (trailing whitespace ignored). Any mismatch, crash or timeout gives reward 0.
- Speed: The timing input has 2300-2500 filters with 4096 particles each, run for 1000 steps. 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.