Port an OpenMP multi-scale detector (wrap-around 32-bit integral image, nine-box cross-ring response per scale, strict 3x3x3 scale-space non-maximum suppression, top-10 and hashed statistics) to CUDA and make it fast
harbor run -t elfsong/cpu2gpu-image-boxfeat-nmsharbor download elfsong/cpu2gpu-image-boxfeat-nms/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.
For each image description an 8-bit synthetic image I is built from the seed (see
pixel()) and its integral image is formed in wrap-around 32-bit arithmetic (box sums are
exact because every box sum is far below 2^32).
For scales s = 0..S-1 let h = s + 1, box side b = 2h + 1, and let box(cy, cx) be the sum
of I over the b x b box centred at (cy, cx). At centre (y, x):
C = box(y, x)
N = box(y-b, x) S = box(y+b, x) E = box(y, x+b) W = box(y, x-b)
NE, NW, SE, SW = the four diagonal boxes at (y -/+ b, x +/- b)
A = 4C - (N + S + E + W)
B = 4C - (NE + NW + SE + SW)
Dd = (N + S) - (E + W)
R = (A*B - ((Dd*Dd) >> 1)) / b^4 (64-bit, division truncates toward zero)
R is defined only where all nine boxes lie inside the image, i.e. 3h+1 <= y < H-3h-1 and
the same for x. A detection is a defined R > THR that is strictly greater than every
defined R among its 26 neighbours in (scale, y, x) (neighbours outside the image, outside
[0, S) or undefined are ignored).
Q
H_1 W_1 S_1 THR_1 SEED_1
...
1 <= H, W <= 8192, 1 <= S <= 12, 0 <= THR <= 10^7, SEED unsigned 64-bit; H*W*S stays
below 2.2e8 in every hidden input.
Three lines per image, in input order:
image i H W scales S valid NVALID sumR SUMR detections NDET hash HASH
perscale D_0 ... D_{S-1}
top R:s,y,x R:s,y,x ...
NVALID counts defined responses, SUMR is their signed sum, D_s counts detections at scale
s, HASH = sum mod 2^64 over detections of
mix64(((s << 52) | (y << 26) | x) + (uint32)R * 0x9E3779B97F4A7C15), and top lists up to 10
detections ordered by R descending, then s, y, x ascending.
Correctness inputs include 1x1 images and images too small for any defined response, single
rows and columns, all scale counts from 1 to 12, THR = 0 and very large THR (no detections),
strips 8192 long, and random images up to about 1300x1300. The timing input holds 18 images with
sides in [3600, 4400], S in [6, 10] and THR in [20000, 120000].
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.
/app/gpu/main.cu is collected. It is compiled with
nvcc -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.system(, popen(, fork(, exec*, dlopen(, getenv(,
#include <filesystem>, /tests/, /proc/. The program may read only the input file it is given.reward = min(2, t_reference / t_yours) using the medians./app/inputs/ holds a few public inputs. /app/bin/run_public.sh compiles your port with the
flags above and compares it against the CPU baseline on each of them.