Concurrent open-addressing hash ledger with TTL expiry under skewed batches
/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
A hash ledger (a key -> (value, birth, last-touch) map with a time-to-live) is driven by R
rounds of B generated operations. Operation id = r*B + j is decoded from
h = mix64(seed ^ mix64(id)) (mix64 is the SplitMix64 finaliser in the CPU source):
- type from
h & 1023:< 600upsert,< 760delete, otherwise lookup; - key rank:
x = (h >> 10) & 0xFFFFFFFF,p = xthenS-1timesp = (p*x) >> 32,rank = (p*U) >> 32(so ranks are skewed towards 0 forS > 1); key= mix64(rank ^ 0x6A09E667F3BCC909) | 1; - upsert delta
= ((h >> 42) & 0xFFFF) + 1.
An entry is live at round r iff its alive flag is set and r - last <= A. Each round runs
three phases, and each phase is defined independently of the order of its operations:
- Deletes clear the alive flag of their key.
killscounts the entries that were live and became dead (an entry deleted twice in a round counts once). - Upserts: for each distinct upserted key,
sum= total of its deltas this round andminid= its smallest op id this round. If the entry is live it keeps its birth and its value grows bysum; otherwise it is (re)born:value = sum,birth = minid, counted inbirths. Either waylast = rand it becomes alive. - Lookups find their key; a lookup is found if the entry is live, and then adds
mix64(key ^ mix64(value * 0x9E3779B97F4A7C15 + birth))to the checksum.
Storage semantics matter for two printed columns (cap and rebuilds). In the CPU table
(open addressing, capacity cap, a power of two) a key keeps its slot from its first upsert
until the next rebuild, even after it is deleted or expires; deletes and lookups never
insert keys. occupied is the number of keys holding a slot: the survivors of the last
rebuild plus the distinct other keys upserted since then. Before each round, if
(occupied + B) * 4 > cap * 3, the table is rebuilt: only the entries live at round r
survive, occupied becomes their number, and cap becomes the smallest power of two
>= max(1024, 2 * (live + B)). Initially occupied = 0 and cap is the smallest power of
two >= max(1024, 2B). This schedule depends only on counts, so your table layout and
probing scheme are up to you, but the printed cap and rebuilds must follow it.
Input format
One line: R B U S A SEED (all unsigned integers).
Output format
Every max(1, ceil(R/50)) rounds, and after the last round, a line with cumulative totals:
round r lookups L found F chk C births N kills K live V cap P rebuilds X
L, F, N, K count lookups, found lookups, births and kills from round 0 through r; C is
the sum of the checksum terms modulo 2^64; V is the number of entries live at round r;
P is the current capacity and X the number of rebuilds so far. Then one final line:
final live V valsum S digest D
over the entries live at round R-1 (round 0 when R = 0): S is the sum of their values
and D = sum of mix64(key + mix64(value ^ (birth << 32) ^ last)), both modulo 2^64.
Hidden inputs
0 <= R <= 5000, 1 <= B <= 2^20, 1 <= U <= 2^23, 1 <= S <= 4, 0 <= A <= 1000, and
R * B < 2^32 (op ids fit in 32 bits). Correctness inputs include R = 0, a single op, a universe of one key
(extreme contention) and of three keys, TTL 0 and TTL larger than R, uniform keys
(S = 1, many rebuilds), the largest universe and the largest batch.
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: The timing input runs about 1000-1200 rounds of 2^19 operations each over a universe of 2^22 keys with cubic skew (S = 3) and a TTL of 6-12 rounds. 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.