Second-order biased walks with rejection and teleports
/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
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 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. - This sandbox has no GPU.
nvccworks here for compiling. To run on the GPU, use/app/bin/gpu_run [--repeat N] [--quiet] SOURCE.cu INPUT_FILE...: it compiles the file with the flags above on a remote H100 worker, runs it on each input, and prints stdout, exit code and wall-clock time. Grading also runs your code on an H100 worker, one job per GPU at a time. 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: 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 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.