Lane and edge line detection on a synthetic dashcam clip with gradient-windowed Hough voting
/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
A line-detection job on a synthetic dashcam clip of NF grey frames of W x H pixels. Every frame
is processed independently; all arithmetic that reaches the output is integer. cpu.cpp is the
exact specification (hash constants, scene formulas, tie rules).
- Frame synthesis. A per-frame scene (hashed from
SEEDand the frame index) has 6-12 painted segments (lane markings from near a vanishing point to below the frame, or free segments; some dashed; Q4 coordinates, half thickness 1-4 px, positive or negative contrast) and 3-6 textured clutter rectangles. A pixel value is a vertical ramp plus bilinear value noise on a 32-pixel lattice; the highest-index rectangle covering the pixel replaces it with its stripe texture; otherwise every segment containing the pixel centre (16x+8, 16y+8, exact integer distance-to-segment and dash tests) adds its contrast. Hashed per-pixel noise is added and the value clamped to[0, 255]. - Edges. 3x3 binomial blur
(sum + 8) >> 4and 3x3 Sobelgx, gy, both with replicated borders;m = gx^2 + gy^2. An interior pixel is an edge ifm >= TMAGand it beats its two neighbours along the gradient direction quantised to 4 directions (m > m(forward)andm >= m(backward)). Its theta bintein[0, NT)is the bin of the integer trig table (C[t] = llround(16384 cos(pi t / NT)),S[t]likewise) nearest to the gradient direction folded into[0, pi)(binary search, then the better of the two neighbouring bins; binNTwraps to 0). Its weight class ismc = min(7, m >> 14). - Voting. With centred doubled coordinates
xc = 2x - (W-1),yc = 2y - (H-1), every edge votes fort = te + d (mod NT),|d| <= WIN, atrho = ((xc*C[t] + yc*S[t] + 16384) >> 15)(floor) with weight(1 + mc) * (WIN + 1 - |d|)into anNT x NRaccumulator,R = (W+H)/2 + 2,NR = 2R + 1, cellt*NR + rho + R. - Peaks. A cell with
a >= TVOTEvotes is a peak if it beats every other cell of its(2PT+1) x (2PR+1)window by votes, ties going to the smaller cell index. Theta wraps: a neighbour row outside[0, NT)is taken moduloNTwith the rho index mirrored to2R - r; neighbours with rho index outside[0, NR)are skipped. TheKstrongest peaks (votes descending, then cell index ascending) are the frame's lines. - Line support. For every line
(t, r), the edges with|xc*C[t] + yc*S[t] - (r-R)*32768| <= 2048*BANDand circular theta distance|te - t| <= WINsupport it; the program reports their countnand the minimum, maximum and sum of their position along the lines = -xc*S[t] + yc*C[t](0 whenn = 0). - Hashes. Per frame,
hashEsums a hash of every edge(p, te, mc)andhashAsums a hash of every non-zero accumulator cell(index, votes)(both mod 2^64, so order independent).
Input format
One line: W H NF NT WIN TMAG TVOTE PT PR K BAND SEED (integers, TMAG and TVOTE 64-bit,
SEED unsigned 64-bit).
Output format
hough W W H H frames NF NT NT NR NR
totals edges E peaks P lines L
frame f edges E_f peaks P_f lines n_f hashE HE_f hashA HA_f (for the first 3 frames)
line k t T r R votes V n N smin A smax B ssum S (n_f lines of that frame)
theta_hist h0 ... h15 (frames by 16*t/NT of their strongest line)
nlines_hist c0 ... cK (frames by number of lines)
hash edges HE acc HA lines HL
HE and HA are sums of the per-frame hashes and HL a sum of per-frame hashes of all lines of
all frames (see the source), all mod 2^64.
Hidden inputs
3 <= W, H <= 4096,0 <= NF <= 1850,4 <= NT <= 4096,0 <= WIN,2*WIN + 1 <= NT,0 <= PT <= 32,2*PT + 1 <= NT,0 <= PR <= 32,1 <= K <= 16,0 <= BAND <= 64,0 <= TMAG <= 6000,0 <= TVOTE <= 10^12.- Correctness inputs include a 3x3 frame, no frames,
2*WIN+1and2*PT+1equal toNT,TMAG = TVOTE = 0(every non-zero cell may be a peak), a vote threshold above every cell,NT = 4096, strips of width or height 5-16, a 4096-wide frame, one 1920x1080 frame and random small clips. - The timing input is 1920x1080 with 1650-1850 frames,
NTin {720, 900, 1024},WINin[NT/5, NT/4],TMAGin[2000, 4000],TVOTE = (250..350) * (WIN+1),PT, PRin[2, 4],Kin[8, 16],BANDin[16, 40].
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 is a 1650-1850 frame clip of 1920x1080 frames, NT in {720, 900, 1024} theta bins and a voting half-window WIN between NT/5 and NT/4, so each of the roughly 5e4 edge pixels per frame casts 289-513 votes. 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.