Second-order biased walks with rejection and teleports
/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
The program builds an undirected weighted power-law graph from a seed and runs second-order (node2vec-style) biased random walks on it with rejection sampling, then reports statistics of the walks.
Graph. n = 2^L vertices. For each candidate edge e = 0 .. D*n-1 the two endpoints are drawn
from a power law (internal id floor(n * x^3) for a uniform 32-bit x, then scrambled by a
bijection on [0, n)), all from the counter-based hash mix64 (SplitMix64 finaliser) in the CPU
source. Self-loops are dropped, both directions are stored, and duplicate edges are merged, so each
adjacency list is a sorted set of neighbour ids. The undirected edge {a, b} has weight
w = 1 + mix64(SEED ^ C ^ (min << 32 | max)) mod W. Each list also stores the inclusive prefix
sums of its weights.
Walks. Every vertex s with at least one neighbour starts R walks; walker s*R + r makes
T steps. All randomness comes from mix64(KW + key * GAMMA) with key = walker << 12 | t << 4 | trial:
the high 32 bits pick a proposal by inverse CDF over the current vertex's weights (first position
whose prefix sum exceeds hi32 * Wtotal >> 32), the low 32 bits make the acceptance test.
- A step that has no previous vertex (the first step, or the step after a teleport) moves to the proposal of trial 0 directly.
- Otherwise up to
TMAXtrials are made. A proposalyhas acceptance weightA_RETifyis the previous vertex,A_TRIifyis a neighbour of the previous vertex (binary search in its sorted list), elseA_HUBifdeg(y) >= H, elseA_OUT. It is accepted whenlo32 * Amax >> 32 < weight, withAmaxthe largest of the four weights. - If all
TMAXtrials are rejected, the walker teleports back to its start vertexs.
For every walk the program counts visits (all T + 1 positions, the start included), folds the
positions into a walk hash, and counts ordered co-occurrences of tracked vertices: for every
position j and every earlier position i with j - i <= WIN, if both vertices are tracked and
different, the pair (x_i, x_j) is counted. The NTRACK tracked vertices are given by internal
ids 0 .. NTRACK/2-1 (the heaviest hubs) and n/2 + j for the rest, scrambled like all ids.
Input format
L D W SEED
R T
A_RET A_TRI A_OUT A_HUB H
TMAX WIN NTRACK
Output format
graph n N edges E maxdeg M wsum S (undirected edges after merging, total weight)
walkers K steps K*T
first F teleport X trials c_1 ... c_TMAX (steps taken without a previous vertex, teleports,
steps accepted at trial 1..TMAX)
visits hash H top v:c v:c v:c v:c v:c (sum over visited v of mix64(v << 32 ^ count),
5 most visited, ties by smaller id)
walks hash H (sum over walkers of the final walk hash)
cooc total N hash H (all co-occurrences; order-independent hash)
pair a b count (up to 10 lines, by count desc, then tracked index)
All sums are modulo 2^64.
Hidden inputs
- Correctness inputs:
2 <= L <= 15,0 <= D <= 16,1 <= W <= 15,0 <= R <= 8,0 <= T <= 200, acceptance weights in1..64,1 <= H <= 2^20,1 <= TMAX <= 16,1 <= WIN <= 8,0 <= NTRACK <= min(64, n/2). They include a graph without edges,R = 0,T = 0,TMAX = 1, all weights equal (every proposal accepted), mostly-rejecting weights (many teleports),H = 1(every vertex is a hub) and unit edge weights. - Timing input:
L = 21,Din[7, 9],Win[8, 15],R = 3,Tin[56, 72],A_TRI = Amaxin[12, 20], the other weights below it,Hin[128, 512],TMAXin[4, 8],WINin[3, 6],NTRACK = 64. SEED < 2^63.
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 2^21 vertices with 7-9 candidate edges per vertex (power-law, the largest hubs have tens of thousands of neighbours), 3 walks per vertex of 56-72 steps (about 4e8 steps), and acceptance weights under which roughly a third to two thirds of the non-triangle proposals are rejected. 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.