Whole-program reaching definitions and liveness with wide bit vectors
/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.
What the program computes
A whole-program bit-vector dataflow job, as a compiler middle end runs it over every function of a
large code base. For each of F generated functions the program:
- Generates the function. Function
fusesfseed = mix64(SEED ^ (f+1) * 0xD6E8FEB86659FD93)(mix64= SplitMix64 finaliser, all arithmetic mod 2^64). Its size isB = BMIN + (BMAX-BMIN) * x*x / 1023^2withx = mix64(fseed ^ 0x5151) % 1024(skewed towards small functions) and it hasR = 16 * max(4, B/20)virtual registers. A sequential generator driven by a SplitMix64 stream builds a structured CFG of exactlyBblocks (entry 0, exitB-1) with while / do-while loops, if / if-else, switches with fall-through, and occasional break, continue, early-return and backward goto edges (loop nesting at mostMAXD); every edge that is not a back edge goes from a lower to a higher block index. Every block gets 3..14 instructions from a counter-based hash:op(strong definition + 2 uses), predicated definition (weak: defines without killing, 2 uses),use(2 uses),clobberof one of 16 register classes (class(r) = r & 15, 1 use) andcopy(strong definition + 1 use). The entry block defines registers 0..15, the exit block uses 0, 16, 32, 48. Register choice has a sliding locality window plus 32 hot registers. The exact rules are in the CPU source and are part of the specification. - Numbers definitions. Only downward-exposed definitions of a block (the last strong
definition of a register plus later predicated ones, minus those clobbered afterwards) are
definition points. They are numbered in the order (register rank, block, position), where the
rank of register
ris(r & 15) * (R/16) + (r >> 4); so all definitions of one register, and of one register class, occupy contiguous bit ranges. - Reaching definitions (forward, union):
OUT = GEN ∪ (IN − KILL), where KILL holds every definition point of each register strongly defined in the block and of each clobbered class. - Liveness (backward, union, over register ranks):
LIVEIN = UE ∪ (LIVEOUT − DEF), where DEF holds the strongly defined registers and every register of a clobbered class and UE the registers read before being killed in the block. Both problems are solved to their least fixpoint (the CPU uses an ordered worklist; any iteration order gives the same fixpoint). - Derives statistics per block: for every register use, the number of definitions that may
reach it (local ones found by walking the block, otherwise the reaching definition points of that
register in
IN), histogrammed into buckets 0,1,2,3,4-7,8-15,16+, summed and maximised; dead strong / predicated definitions and register pressure (live-set size at every point, walking backwards fromLIVEOUT); and digests of every block'sINandLIVEINvectors:fold = Σ_w word[w] * (2w+1)over the 64-bit words of the vector, thenhr += mix64(fold + b * 0x9E3779B97F4A7C15)andhl += mix64(fold + b * 0xC2B2AE3D27D4EB4F).
Input format
One line: F BMIN BMAX MAXD SEED (SEED is an unsigned 64-bit integer).
Output format
For each of the first 16 functions:
fn f B= E= D= R= reach= live= ud=h0,...,h6 usum= umax= dead=S/P pmax= psum= h=HR/HL
(E edges, D definition points, reach / live total set bits of all IN / LIVEIN vectors,
pmax / psum the maximum / the sum over blocks of the per-block maximum pressure, hashes in 16 hex
digits). Then a total line with the sums (maxima for umax, pmax) over all functions and
digest = Σ_f mix64(HR_f ^ rotl(HL_f, 17) ^ f * 0xD1B54A32D192ED03), and up to 8 top lines: the
functions with the highest pmax (ties: lower index first).
Hidden inputs
0 <= F <= 4096, 4 <= BMIN <= BMAX <= 16000, 0 <= MAXD <= 12. Correctness inputs: F = 0,
a single 4-block function, tiny functions with MAXD = 12 and SEED = 2^64-1, MAXD = 0
(straight-line code with jumps), up to 20 functions of up to 2500 blocks, and random mixes. The timing
input has F = 2300..2500 functions with BMIN = 1000, BMAX = 14000 and MAXD = 8..12
(about 13 million blocks; the largest functions have about 90 000 definition points).
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: Around 80 to 100 functions of 1000 to 14000 blocks for forward and backward bitvector dataflow. 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.