Whole-program reaching definitions and liveness with wide bit vectors
/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
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 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: Around 80 to 100 functions of 1000 to 14000 blocks for forward and backward bitvector dataflow.
/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.