Integer gradient boosting with histogram split finding
/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
Training of a gradient-boosted regression-tree ensemble with histogram split finding and level-wise (depth-wise) growth, entirely in integer arithmetic. The CPU source is the exact specification; in short:
- Data.
Nrows withFuint8 feature bins (0..255), a fixed-point targetY(1/256 units) and a weightWin1..4, all generated fromSEEDbygen_row(4 latent factors per row, correlated features, a nonlinear target with noise and 2% outliers). PredictionsPstart at 0. - Per tree
t(Ttrees):- gradients for every row:
e = P - Y,q = e >> 3(arithmetic),g = W * clamp(q, -63, 63),h = W * (|q| <= 63 ? 4 : 1); - row bagging: only rows with
in_bag(SEED, t, r)(about 75%) contribute to histograms and node totals; - level-wise growth to depth
D(nodes numbered heap-style: root 1, children2n,2n+1). For every open node at levelland every feature allowed at(t, l)byfeat_allowed(about 75%), the histogram of(sum g, sum h)per bin over the node's bagged rows is scanned: the candidate "bin <= bgoes left" forb = 0..254is valid if both sides have hessian sum>= MINW, and, for monotone features, if the implied leaf values are ordered (f % 16 == 3:GL*(HR+LAMBDA) >= GR*(HL+LAMBDA);f % 16 == 11:<=). Its score isS(GL,HL) + S(GR,HR)withS(G,H) = floor(G*G / (H + LAMBDA))(unsigned 64-bit). The best candidate (largest score; ties to the lowest feature, then the lowest bin) splits the node if its score is> S(G,H) + GAMMA; otherwise the node becomes a leaf. Nodes at depthDare leaves. - leaf value
v = -(G * ETA) / (H + LAMBDA)(64-bit, C division truncating toward zero); - every row (bagged or not) is routed through the tree (
bin > bgoes right) andP += v.
- gradients for every row:
Input format
One line: N F T D LAMBDA MINW GAMMA ETA SEED (integers, SEED unsigned 64-bit).
Output format
tree <t> bag=<bagged rows> splits=<internal nodes> leaves=<leaves> loss=<L_t> hash=<H_t> (t = 0..T-1)
final N=<N> F=<F> T=<T> D=<D> loss=<L> pred_hash=<PH>
feature_splits <c_0> <c_1> ... <c_{F-1}>
row <r> y=<Y[r]> pred=<P[r]> (r = 0, N/3, N-1, distinct, if they exist)
L_t/L:sum_r W[r] * |P[r] - Y[r]|after treet/ at the end (all rows).H_t: sum over the tree's nodes, modulo 2^64, ofmix64(key)withkey = (t << 32) | (node << 16) | (feature << 8) | binfor internal nodes andkey = 2^63 | (t << 43) | (node << 32) | (uint32)vfor leaves (mix64= SplitMix64 finaliser).PH = sum_r mix64((r << 32) | (uint32)P[r])modulo 2^64;c_f= number of splits on featuref.
Hidden inputs
0 <= N <= 4,194,304,1 <= F <= 64,0 <= T <= 128,1 <= D <= 10,1 <= LAMBDA <= 10^6,1 <= MINW <= 10^6,0 <= GAMMA <= 2^50,1 <= ETA <= 64, any 64-bitSEED.- Correctness inputs include
N = 0, a single row, a single feature with depth 10,T = 0,MINWorGAMMAso large that no split is ever made, depth 10 with many small nodes,LAMBDA = 1withETA = 64, and random small configurations (up to 100,000 rows). - The timing input has about 4.1 million rows,
F = 64,T = 100trees,D = 8,LAMBDA = 100,MINWin 3000..5000,GAMMA = 0andETA = 8; trees have roughly 50 to 200 internal nodes (of at most 255), so the deeper levels have tens of open nodes, each with its own 64 x 256 histogram. - All per-bin and per-node sums fit in 32-bit signed integers (
|g| <= 252,h <= 16),G*Gfits in 63 bits and the cross products of the monotone test fit in 64 bits.
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: One input with about 4.1 million rows x 64 features, 100 trees of depth 8 (about 75% of the rows bagged per tree, 75% of the features allowed per level), LAMBDA = 100, MINW in 3000..5000, GAMMA = 0, ETA = 8.
/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.