Port an OpenMP partial-collision census (top-t-bit bucket occupancy over a key range, collision statistics, then a second pass for the minimum key in the fullest bucket) to CUDA
harbor run -t elfsong/cpu2gpu-bits-arx-collideharbor download elfsong/cpu2gpu-bits-arx-collide/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.
For each query, every key k in [lo, lo+N) is hashed with a keyed ARX hash G
(two 64-bit lanes, R rounds of add / rotate / xor; keys k0 = mix64(seed),
k1 = mix64(seed+1); exact round function in the CPU source). The top t bits of
G(k) select one of 2^t buckets. From the bucket occupancy c_b the program reports
partial-collision statistics, then runs a second pass over the keys to find the
smallest key that falls in the fullest bucket.
Q
lo N t R seed
... (Q lines)
All values are unsigned decimal integers.
One line per query, in input order:
qi PAIRS EMPTY TRIPLE PROFILE CMAX BMAX KMIN
PAIRS: sum over buckets of c_b*(c_b-1)/2 (number of colliding key pairs).EMPTY: number of buckets with c_b = 0; TRIPLE: number of buckets with c_b >= 3.PROFILE: sum over non-empty buckets of mix64((b << 20) ^ c_b) modulo 2^64
(mix64 = SplitMix64 finaliser in the CPU source).CMAX: the largest c_b; BMAX: the smallest bucket index with c_b = CMAX;
KMIN: the smallest key in bucket BMAX.N = 0 the line is qi 0 EMPTY 0 0 0 - -.0 <= lo < 2^63, 0 <= N <= 3.0e8, 16 <= t <= 28, 1 <= R <= 12, seed any 64-bit value.N = 0, N = 1, R = 1, t = 16 with dense buckets, t = 28
with a sparse table, and ranges ending at 2^63.N in [2.2e8, 3.0e8], t in [22, 28], R in [6, 12].
Up to 2^28 32-bit counters (1 GiB) are needed.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.
/app/gpu/main.cu is collected. It is compiled with
nvcc -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.system(, popen(, fork(, exec*, dlopen(, getenv(,
#include <filesystem>, /tests/, /proc/. The program may read only the input file it is given.reward = min(2, t_reference / t_yours) using the medians./app/inputs/ holds public input examples for understanding the input format.