First two convex layers of 1.4e7 power-law-sized integer point sets
/app/cpu/main.cpp is the source of a multicore CPU program (C++17, OpenMP).
The program takes one input-file path (PROGRAM INPUT_FILE) and writes its result to stdout.
What the program computes
A batch of S independent 2D point sets with integer coordinates is generated from a seed. For
every set the program computes its first two convex layers (onion peeling): layer 1 is the
strict convex hull of the set, layer 2 is the strict convex hull of the distinct points that are
not layer-1 vertices. It prints totals, histograms and a hash over all sets. The CPU source is the
reference for every detail; mix64 is the SplitMix64 finaliser.
Set header (set_info). hs = mix64(seed ^ mix64(s + 0x51ED270B27D3E5A1)).
- Size: with
D = 2^32andlmax = floor(D*minsize/maxsize): iflmax >= Dthenm = minsize, elsev = (hs mod 2^32) mod (D - lmax)andm = min(maxsize, floor(minsize*D / (D - v))). This is a truncated power law: each octave of sizes holds about the same number of points. h2 = mix64(hs ^ 0x6A09E667F3BCC909):type = h2 mod 5, centrecx = ((h2>>8) mod 2^29) - 2^28,cy = ((h2>>35) mod 2^29) - 2^28.h3 = mix64(hs ^ 0xBB67AE8584CAA73B):e = 4 + h3 mod 22,R = min(2^26, 2^e + ((h3>>8) mod 2^e)),g = 1,shear = ((h3>>20) mod 17) - 8; for type 4,R = 1 + ((h3>>40) mod 24)andg = 1 + ((h3>>50) mod 1000).
Point j of the set (gen_point): hp = mix64(hs ^ mix64(j + 0x2545F4914F6CDD1D)), then an offset
(dx, dy) by type: 0 square and 4 coarse lattice (hp mod (2R+1) - R, (hp>>32) mod (2R+1) - R),
1 disk (up to 8 rejection tries from mix64(hp + a*0x9E3779B97F4A7C15), else (0, 0)), 2 Gaussian-like
(sum of four 16-bit fields of hp and of mix64(hp ^ 0xD1B54A32D192ED03), scaled by R/2^17 with
floor division), 3 near-circle (a 16-bit direction scaled to length R with integer square root
and C-style truncating division, plus a jitter of up to R>>12). Finally dx, dy are multiplied
by g and the point is (cx + dx + floor(shear*dy/8), cy + dy). All coordinates lie in
[-2^29, 2^29). Duplicate points are common in small or lattice sets.
Hulls. Hulls are strict: duplicate points count once and points in the interior of a hull edge
are not vertices. A set with one distinct point has a 1-vertex hull; a set whose distinct points are
collinear has a 2-vertex hull (its two extreme points). Vertices are listed counter-clockwise
starting at the vertex with the smallest y, ties by smallest x. For a hull with vertices
v0..v(h-1) in that order:
area2=sum_{i=1}^{h-2} cross(v_i - v0, v_(i+1) - v0)(twice the area, exact; 0 whenh < 3);x(sequence hash) = fold ofx = mix64(x ^ key(v_i))fromx = 0, withkey(v) = (vx + 2^29) << 32 | (vy + 2^29).
Per-set record and global outputs. For each set, with layer results (h1, a1, x1) and
(h2, a2, x2) (all zero when a layer is empty):
sh = mix64(x1 ^ mix64(x2 ^ mix64(a1 ^ mix64(a2 ^ (h1<<32 | h2))))) and the global hash adds
mix64(sh ^ (s * 0x9E3779B97F4A7C15)) (modulo 2^64; areas as 64-bit two's complement).
Input format
One line: S SEED MINSIZE MAXSIZE (decimal integers).
Output format
sets S points TOTAL_POINTS
layer1 vertices SUM_H1 area2 SUM_A1
layer2 vertices SUM_H2 area2 SUM_A2
largest_hull H set s (largest h1; smallest set index on ties; "largest_hull 0 set -" if S = 0)
hash G
hist1 c_0 ... c_19 (number of sets with h1 in bin b: bins 0,1,2,3 exact, then [2^k, 2^(k+1)) as bin k+2, last bin open)
hist2 c_0 ... c_19 (same for h2)
octave k sets N points P h1 H1 h2 H2 (for each non-empty size octave k: minsize*2^k <= m < minsize*2^(k+1), k <= 23)
set i size m type t h1 .. a1 .. x1 .. h2 .. a2 .. x2 .. (for i = 0..3, i < S)
SUM_A1, SUM_A2 are exact decimal integers (they may exceed 64 bits).
Hidden inputs
0 <= S <= 2^25,1 <= MINSIZE <= MAXSIZE <= 131072, any 64-bit seed.- Correctness inputs include
S = 0, single-point sets, sets of 1-3 points, many tiny sets with duplicates and collinear points, sets of exactly one size, sizes around 1024, a few sets of up to 131072 points, and the full power-law range 16..100000. - The timing input has
Sin [1.3e7, 1.5e7],MINSIZE = 16andMAXSIZEin [90000, 110000] (about 1.9e9 points; the 1.6% of sets above 1024 points hold about half of them).
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.
This sandbox is for writing the source only: it has g++ and the CPU program, but no CUDA
compiler and no GPU. Compilation, execution and verification happen later on an H100 in a
separate verifier, and a port that does not compile is rejected, so check your logic against
the CPU program before you finish (for example by emulating your kernels on the host).
How your port is verified
- 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. - Verification runs on one H100 in a fresh container without network. Hidden inputs are generated with a fresh random seed at verification time.
- Correctness: every hidden input (small edge cases plus a large timing input) must pass. Your output must be identical to the CPU program's output (trailing whitespace ignored). Any mismatch, crash or timeout is rejected.
- GPU execution is checked: a port that computes its answer on the CPU is rejected even when its output is correct.
- Speed: The timing input has 1.3e7-1.5e7 sets with sizes 16..~1e5 (power law, about 1.9e9 points in total), drawn from square, disk, Gaussian, near-circle and coarse-lattice distributions.
/app/inputs/timing_example.inhas the shape and size of the hidden timing input. Your port is timed against a reference GPU port on it; the faster your port, the higher its score. /app/inputs/holds public input examples for understanding the input format.