Port construction of a bit-level wavelet matrix and batches of range quantile, rank, and count-less queries to CUDA.
harbor run -t elfsong/cpu2gpu-struct-wavelet-quantileharbor download elfsong/cpu2gpu-struct-wavelet-quantile/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.
Port the CPU program to CUDA. The program accepts one input-file path and must produce exactly the CPU output.
Each input job specifies a value count, query count, bit width, and seed. Values are generated deterministically with a mixture of low-range and full-range integers. The program builds a wavelet matrix, using stable partition and a prefix count of one-bits at each level. Deterministic queries then request one of three operations on a half-open range: the zero-indexed quantile, the count of a given value (rank), or the count of values less than that value. The output includes the first eight answers, per-operation sums, a value checksum, a query checksum, and a final checksum.
All answers are exact integers. The reference CUDA implementation performs the query batch on the GPU; optimizing the level construction, query memory access, and host transfers is part of the 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.
/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 a few public inputs. /app/bin/run_public.sh compiles your port with the
flags above and compares it against the CPU baseline on each of them.