Multi-reference full-search motion estimation with temporal predictors and 8x8 splits
/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
Full-search block-matching motion estimation on a synthetic video, as in a video encoder.
- Video.
Fframes ofW x Huint8 pixels: a value-noise background texture under global pan plus per-frame camera shake,NOBJtextured rectangles moving linearly (later objects on top), a small per-frame gain change and per-pixel noise. Textures are sampled with Q8 bilinear interpolation (seemake_texture,bilinearandgen_framein the source). - Search. Frame
t >= 1is split into 16x16 macroblocks (MBs). Each MB is matched against themin(R, t)previous frames (referenceris framet-1-r) at every integer vector(mvx, mvy)in[-S, S]^2; reference pixels outside the frame are edge-replicated. For each candidate the SADs of the four 8x8 quadrants are computed; the 16x16 SAD is their sum. - Predictor. The previous frame's motion field is kept per 8x8 sub-block as normalised
vectors
n = trunc(16*mv / (r+1)). For an MB the predictor is the component-wise median of the top-left sub-block vectors of the 3x3 MB neighbourhood (clamped at the borders) in that field (all zero fort = 1), scaled to referencerastrunc((med*(r+1) +- 8) / 16)(sign ofmed) and clamped to[-S, S]. - Cost.
cost = SAD + LAMBDA * (se(mvx - px) + se(mvy - py) + r),se= signed Exp-Golomb length. Each of the five partitions (16x16 and the four 8x8 quadrants) keeps the candidate with the smallest key(cost, r, |mvx|+|mvy|, mvy, mvx)over all references. - Mode decision. The MB is split iff
sum of the four 8x8 best costs + SPLITis smaller than the best 16x16 cost. The chosen vectors form the frame's motion field (a non-split MB copies its vector into its four sub-blocks).
Input format
One line: W H F R S LAMBDA SPLIT NOBJ SEED (integers, SEED unsigned 64-bit).
Output format
frame t cost C sad D split K refs N0 N1 N2 N3 hash HF (one line per frame t = 1 .. F-1)
total frames F mbs NMB cost C sad D split K hash HT
C and D sum the chosen cost and SAD over all MBs, K counts split MBs, Nr counts 8x8
sub-blocks predicted from reference r. HF = sum mod 2^64 over sub-blocks sb (row-major on
the 8x8 grid) of mix64((t << 48) ^ (sb << 20) ^ ((mvx+32) << 10) ^ ((mvy+32) << 2) ^ r);
HT = sum of mix64(HF ^ t) over frames.
Hidden inputs
W, Hmultiples of 16 with16 <= W, H <= 2048,1 <= F <= 200,1 <= R <= 4,0 <= S <= 32,0 <= LAMBDA <= 64,0 <= SPLIT <= 4096,0 <= NOBJ <= 32.- Correctness inputs include a single MB with
S = 0,S = 32,R = 4, no split penalty and a prohibitive one,LAMBDA = 64, 2048-wide and 2048-tall strips, 60 frames, 32 objects, a full 1920x1088 frame, and random small videos. - The timing input is 1920x1088 with about 45 frames,
R = 2,S = 32,LAMBDAin[3, 8],SPLITin[40, 160]and 6-16 objects (about 8e11 pixel differences).
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.
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. - GPU verification uses the backend selected for this run: an H100 attached to the separate verifier, or a remote H100 worker. Hidden inputs use a fresh random seed.
- For public GPU experiments, use
/app/bin/gpu_run [--backend auto|local|remote] [--repeat N] [--quiet] SOURCE.cu INPUT_FILE.... The default usesGPU_RUNNER_URLwhen configured, otherwise a GPU attached to this sandbox. Sandbox GPU access is configured independently from verification; a CPU-only sandbox needs a runner URL. - 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.
- GPU execution: a separate, untimed CUPTI check must observe completed GPU kernel activity on the hidden timing input. A CPU-only submission receives reward 0 even if its output is correct.
- Speed: The timing input is a 1920x1088 video of about 45 frames searched against 2 reference frames with a +-32 full search (about 8e11 pixel differences). 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.