Skewed equi-join with an opaque residual predicate and group-by
/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
text
cpu_baseline INPUT_FILE
It reads one input file and writes its result to stdout.
What the program computes
A relational query over two tables that the program generates from the seed:
text
SELECT a.g, b.h, COUNT(*), SUM(a.v * b.w + (z >> 32)), XOR(z)
FROM build a JOIN probe b ON a.key = b.key
WHERE z mod 7 < 3 -- z = mix64(a.x XOR b.y)
GROUP BY a.g, b.h
- Build rows
i = 0..NB-1and probe rowsi = 0..NP-1are produced by counter-based hashing (mix64is the SplitMix64 finaliser; the exact formulas are in the CPU source). A build row has a 32-bitkey, a 64-bit attributex, a 32-bit valuevand a group codegin 0..3. A probe row haskey, a 64-bit attributey, a 32-bit valuewand a group codehin 0..15. - Keys are extremely skewed. A row is a heavy-hitter row with probability
HBPM/10^6(build) orHPPM/10^6(probe); it then takes one ofHheavy keys, chosen with a further skew (the first heavy key gets about1/sqrt(H)of them). Every other row takes a light key id whose frequency falls off like1/sqrt(id): build rows useNKlight ids, probe rows use2*NKids, so many probe rows find no partner. A probe row may therefore match anything from zero to hundreds of thousands of build rows. - For every pair of rows with equal keys, the residual predicate
z mod 7 < 3withz = mix64(a.x ^ b.y)is evaluated; it is opaque, so every pair has to be visited. Passing pairs are aggregated into the 64 groups(a.g, b.h): their count, the sum ofa.v * b.w + (z >> 32)modulo 2^64, and the XOR ofz.
The joined pairs are never materialised.
Input format
One line:
text
NB NP NK H HBPM HPPM SEED
NB build rows, NP probe rows, NK light key ids, H heavy keys, heavy shares HBPM/HPPM
in rows per million, and a 64-bit unsigned SEED.
Output format
text
rows NB NP keys K
joinpairs J
passing P
misses M
group G H COUNT SUM XOR (64 lines, G = 0..3, H = 0..15)
K: number of distinct keys in the build table.J: number of equal-key (build, probe) pairs before the residual predicate;P: pairs that pass it (the sum of all group counts);M: probe rows whose key does not occur in the build table.SUMis printed as a signed 64-bit integer (two's complement of the sum modulo 2^64),XORas 16 lowercase hex digits.
Hidden inputs
0 <= NB <= 2*10^7,0 <= NP <= 2*10^8,1 <= NK <= 2^24,0 <= H <= 64,0 <= HBPM, HPPM <= 10^6.- Correctness inputs include an empty build table, an empty probe table, a single build row, a single light key, every row heavy (64 heavy keys), one huge key holding half of both tables, no heavy keys, the largest key domain (almost all probes miss), the largest build table, and random mixes.
- The timing input has
NBin [9.5M, 10.5M],NKin [0.8M, 1.2M],Hin [6, 10],HBPMandHPPMin [10000, 13000], andNP(about 80M-170M) chosen so that the join has about 3.410^10 equal-key pairs, almost 90% of them on the heavy keys; about 1.510^10 pairs pass the predicate.
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 about 10M build rows, 6-10 heavy keys holding 1.0-1.3% of each table, about 1M light keys, and as many probe rows (80M-170M) as give about 3.4e10 equal-key pairs, almost 90% of them on the heavy keys. 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.