Concurrent open-addressing hash ledger with TTL expiry under skewed batches
/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
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 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: 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.
/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.