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. - The timing input has the shape and size of
/app/inputs/timing_example.in. 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 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:
/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.