Batch max-flow and minimal sink-side cuts
/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
For a batch of generated flow networks the program computes the maximum s-t flow value and the minimal sink side of the minimum cut: the set of vertices that can still reach the sink in the residual graph of a maximum flow. That set is the same for every maximum flow (and equals the one obtained from any maximum preflow), so it is well defined.
All capacities are integers produced by the counter-based hash mix64 (SplitMix64 finaliser in the
CPU source); the exact formulas and hash keys are in the CPU source and must be reproduced bit for
bit. Every network has n vertices with the source s = n-2 and the sink t = n-1. An edge slot
(u, v, c_uv, c_vu) gives an arc u -> v with capacity c_uv and an arc v -> u with capacity
c_vu (often 0); parallel edges are allowed.
Grid networks (type 0, parameters W H LAMBDA, segmentation style): W*H pixels plus s and
t. Pixel intensities are 170 inside 3-6 random discs and 80 outside, plus noise in [-32, 31].
Every pixel has one terminal edge: the disc centres are hard foreground (s -> p, capacity 100000),
the four corners hard background (p -> t, 100000), any other pixel is joined to s (bright) or to
t (dark) with a capacity that grows with its distance from 128. Horizontal and vertical neighbours
are joined by contrast-dependent capacities LAMBDA * 64 / (1 + |I_p - I_q|) plus LAMBDA in the
bright-to-dark direction (vertical neighbours use LAMBDA + LAMBDA/2).
Layered networks (type 1, parameters K WD D): K layers of WD vertices plus s and t.
s feeds every vertex of layer 0 and every vertex of layer K-1 drains into t (capacities
500..4999). Every vertex of layers 0..K-2 has D arcs to random vertices of the next layer
(capacity 1..1000), with probability 1/8 a skip arc two layers ahead (1..500) and, outside layer 0,
with probability 1/16 a back arc one layer behind (1..300).
Input format
B
TYPE A B C SEED (one line per network: TYPE 0 -> A B C = W H LAMBDA, TYPE 1 -> A B C = K WD D)
Output format
graph i type T n N arcs A flow F sinkside S cutarcs C hash H (one line per network)
total flow X
Ais the number of arcs,2 *the number of edge slots that are present (zero-capacity arcs included).Fis the maximum flow value,Xthe sum over all networks.Sis the number of vertices other thantthat can reachtin the residual graph.Ccounts the arcsu -> vwith positive capacity,uoutside andvinside that sink side.His the sum over thoseSverticesvofmix64(SEED ^ (v * 0xA24BAED4963EE407))modulo 2^64.
Hidden inputs
- Correctness inputs: 1 to 8 networks per input; grids with
1 <= W, H <= 128and0 <= LAMBDA <= 1000, layered networks with1 <= K <= 120,1 <= WD <= 128,1 <= D <= 8. They include 3-vertex networks (W = H = 1,K = WD = 1), single rows and columns,LAMBDA = 0(no smoothing, flow 0),LAMBDA = 1000, a single layer, width-1 layers and deep narrow networks. - Timing input: 800 networks; each is a grid with probability 0.45 (
W, Hin[256, 1024],LAMBDAin[5, 60]), otherwise a layered network (Kin[20, 200],WDin[64, 4096]withK * WD <= 250000,Din[2, 5]). About 215 million vertices and 1.4 billion arcs in total. SEED < 2^63. AlwaysW, H <= 1024,K * WD <= 2^20.
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. - Grading runs on one H100 in a fresh container without network. 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: 800 networks: about 45% grids of 256..1024 x 256..1024 pixels (4-neighbour, directed contrast capacities, hard seeds) and 55% layered random networks of 20-200 layers with up to 250000 vertices; about 215 million vertices and 1.4 billion arcs in total. 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.