Bit-sliced index analytics: range filters, weighted-popcount aggregates and slice-descent quantiles
/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
An analytics engine that keeps a numeric table only as a bit-sliced index (one bit-plane
per value bit) and answers a batch of filtered aggregate queries directly on the bit-planes.
/app/cpu/main.cpp is the specification; this text summarises it.
Stage 1 – ingest. C columns (1 <= C <= 16) over N rows. Column c has width
B_c = 8 + mix64(seed ^ (0xB5AD4ECEDA1CE2A9 * (c+1))) % 17 bits (8..24) and a column seed
S_c = mix64(seed ^ (0xA24BAED4963EE407 * (c+1))) (mix64 = SplitMix64 finaliser, all
arithmetic 64-bit unsigned). With h = mix64(S_c ^ (r * 0x9FB21C651E98DF25)) and
M = 2^B_c - 1, the value in row r depends on the column kind c % 4:
uniform h & M; skewed (h & M) >> ((h >> 58) % B_c); correlated with column 0
(5*v0 + ((h >> 20) & 1023)) & M; clustered by 1024-row blocks
(mix64(S_c ^ 0x5851F42D4C957F2D ^ (r >> 10)) + (h & 255)) & M.
Every column is stored as B_c slices of W = ceil(N/64) 64-bit words: bit r % 64 of word
r / 64 of slice j is bit j of the value of row r; padding rows >= N are 0 in every
slice. The ingest checksum is sum over all slice words of mix64(word ^ ((sid << 40) + w))
(mod 2^64), where sid is the global slice index (slices of column 0 first, low bit first).
Stage 2 – query batch. Query q is drawn from a SplitMix64 stream seeded by
mix64(seed ^ 0x7F4A7C15F39CC060) ^ ((q+1) * 0xD6E8FEB86659FD93) (exact draw order in
make_query). Its filter is an OR of 1..2 conjuncts, each an AND of 1..3 predicates on random
columns: v < k, v >= k, lo <= v <= hi, or (v & m) == p, with constants covering the
empty and full cases. Predicates are evaluated 64 rows at a time with the bit-sliced
comparison circuit (most significant slice first). For the qualifying row set F the query
reports
CNT = |F|,SUM= sum of columnaoverF(weighted popcounts of the slices),G0..G3= number of rows ofFwhose top two bits of columndare00, 01, 10, 11,PROD= sum overFofv_a * v_emod 2^64 (only for queries whose flag is set, else-),QV= the value of rankrho = ((CNT-1) * phi) >> 10(0-based, ascending,phiin 0..1024) of columnbamong the rows ofF, found by a most-significant-bit-first descent over the slices ofb(-1ifCNT = 0).
A per-query digest th (sequence of mix64 folds in the source) is summed as
HASH += mix64(th + q * 0x9E3779B97F4A7C15).
Input format
One line: N C Q seed (seed is a 64-bit unsigned integer).
Output format
INGEST N C W CHECKSUM
WIDTHS B_0 ... B_{C-1}
Q q CNT SUM QV G0 G1 G2 G3 PROD (for q < min(Q, 32); PROD is "-" when not requested)
TOTAL Q sum(CNT) sum(SUM) #queries-with-CNT=0 HASH
All values are exact integers (sums mod 2^64 where noted); the comparison is exact.
Hidden inputs
Correctness inputs (15 files): N = 0, N = 1, N = 63, 64, 65 (word boundaries),
N = 4097, N = 65536, an ingest-only input (Q = 0), random inputs with N <= 250000,
C in 1..16 and Q <= 40, and one input with N in [400000, 500000], C = 16. The timing
input (scale 1.0) has N uniform in [0.92 * 2^25, 2^25], C in 14..16 and Q in 1100..1300
queries; smaller timing scales shrink N and Q both by sqrt(scale). Memory: the slices of
the timing input take about 1 GB. All inputs satisfy 0 <= N < 2^26, 1 <= C <= 16,
0 <= Q <= 2000.
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 (scale 1.0) has about 3.2e7 rows in 14-16 columns of 8-24 bits (about 1 GB of bit slices) and runs about 1200 generated queries; ingest is a few percent of the CPU time, the query batch dominates.
/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.