Radio-relay siting: thousands of radial viewsheds, cumulative coverage and intervisibility network
/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 radio-relay siting study on a generated terrain, in exact integer arithmetic. The CPU source is the specification; in short:
- Terrain. An
N x Ninteger DEM (decimetres): six octaves of hashed value noise on lattices of spacing 256, 128, ..., 8 cells with amplitudes (16, 12, 8, 5, 3, 2), bilinear integer interpolation, sum>> 2, and lakes: heights below 4000 are raised to 4000. - Candidate sites. The map is cut into
TS x TStiles (M = (N/TS)^2sites). Each tile's site is its highest cell (ties: first in row-major order). The antenna height is the cell height +MAST+ a hashed 0..63. - Viewshed of each site.
8Rrays go from the site to the perimeter cells(ex, ey)of the square of Chebyshev radiusR(same perimeter order as in the source). Stepk = 1..Rof a ray visits(x0 + rdiv(ex*k, R), y0 + rdiv(ey*k, R))(rdiv= division rounded half away from zero); the ray stops at the map border. Withdrop = (k*k*(ex^2+ey^2)*KC) / (R*R*65536)(earth curvature) anddz = dem - drop - z0, the cell is visible if no horizon exists yet or(dz + TGT)/k >= horizon; then the horizon becomesdz/kif that is larger (>). All slope comparisons are exact cross-multiplications. A cell is in the site's viewshed if any ray that visits it sees it (rays overlap heavily near the site). - Cumulative viewshed. For every map cell, the number of sites whose viewshed contains it; a histogram of these counts in log2 bins and the number of cells seen by >= 1 and >= 3 sites.
- Relay network. Site
isees sitejifj's cell lies ini's viewshed (and within the square). A link needs both directions; the program counts links, one-way sightings, the connected components of the link graph and the largest one, and lists the 10 sites with the largest viewsheds.
Input format
One line: N TS R MAST TGT KC SEED (integers, SEED 64-bit unsigned).
Output format
dem min A max B sum S
sites M visible_total V (sum of the viewshed sizes)
coverage_hist c0 c1 ... c9 (cells seen by 0, 1, 2-3, 4-7, ..., 128-255, >=256 sites)
covered_ge1 X covered_ge3 Y
links L oneway O components C largest G
top i site s at x y mast z visible v (10 lines or M if fewer; by size desc, then site index)
coverage_checksum H (sum over cells c of mix64(c*0x9E3779B97F4A7C15 ^ count), mod 2^64)
The output must match exactly.
Hidden inputs
64 <= N <= 4096, 16 <= TS <= 256, N a multiple of TS, 1 <= R <= 1024,
0 <= MAST <= 600, 0 <= TGT <= 100, 0 <= KC <= 400. Correctness inputs (10) include a single
site, R = 1, rays that leave the map, no mast and no curvature, very tall masts with strong
curvature, a single site whose square covers the whole map, and random small configurations.
The timing input has N = 4096, TS = 64 (4096 sites), R 600-680, MAST 200-400, TGT = 20,
KC = 40 (about 1.4e10 ray steps).
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 source generation only. Write /app/gpu/main.cu; compilation,
execution and verification are performed later in a separate verifier environment.
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.
- 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 has a 4096 x 4096 DEM, 4096 masts (one per 64 x 64 tile) and a viewshed radius of 600-680 cells, about 1.4e10 ray 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 public input examples for understanding the input format.