Exact best-first branch-and-bound for multidimensional 0-1 knapsack with surrogate bounds
/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
The program solves a batch of multidimensional 0-1 knapsack instances exactly: maximise
sum p_i x_i subject to sum_i a_ki x_i <= b_k for every constraint k < m, x_i in {0, 1}.
Instances are generated from (n, m, tight, noise, seed) with a counter-based hash
(mix64, see the CPU source for every constant): weights a_ki in [1, 1000], profit
p_i = (sum_k a_ki) / m + h_i % (noise + 1) (small noise = strongly correlated = hard),
capacity b_k = floor(sum_i a_ki * tight / 1000).
Surrogate multipliers. 32 hashed candidate vectors U_c[k] (perturbations of 2^20 / b_k) are
scored by their root bound; the 4 with the smallest root bound (ties to the lower candidate index)
are kept, best first. Items are then put into branching order: decreasing p_i / sw_0(i) with
sw_s(i) = sum_k U_s[k] a_ki, ties to the lower original index.
Upper bound of a partial assignment (first d items decided, profit P, residual capacities
r_k): for each kept surrogate s, the Dantzig bound of the free items (positions >= d) that
individually fit (a_kj <= r_k for all k), scanned in decreasing p / sw_s order (ties to the
lower position) against the capacity sum_k U_s[k] r_k, whole items while they fit and then
floor(p * remaining / sw) of the first item that does not; the bound is P + the minimum over
the 4 surrogates. All arithmetic is exact integer arithmetic.
Greedy solution: take the items in branching order whenever they fit in every dimension.
The CPU program runs a bulk-synchronous best-first branch-and-bound (rounds of the 4096 open nodes with the highest bounds, branching on the next item in branching order, greedy completion of every child as a candidate incumbent, pruning by the incumbent) and prints the optimum. Any exact search is acceptable: only the printed values must match.
Input format
T
n m tight noise seed (T lines, one per instance; seed is an unsigned 64-bit integer)
Output format
One line per instance, then the sum of the optima:
inst t n N m M greedy G root_bound UB optimum OPT
total X
G is the greedy value, UB the upper bound of the empty assignment (the root), OPT the
optimum.
Hidden inputs
0 <= T <= 64, 1 <= n <= 192, 1 <= m <= 12, 0 <= tight <= 1000, 0 <= noise <= 100000.
Correctness inputs have at most 12 instances each and include T = 0, n = 1, tight = 0
(nothing fits), tight = 1000 (everything fits), n at the 64-bit word boundaries (64, 65, 129,
130), long uncorrelated instances (n up to 192 with m <= 3), m up to 12, noise = 0;
every correctness instance is small enough for the CPU program to solve in well under a second.
The timing input has T = 32 strongly correlated instances with 46 <= n <= 50, m = 5,
tight = 500, noise = 100 (the hardness knob is n with noise fixed); each needs millions of
search nodes (about 2-11M for the CPU program), varying by about an order of magnitude between
instances.
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: The timing input has 32 strongly correlated instances (n = 46-50 items, m = 5 constraints, half-tight capacities); the CPU search opens about 1.6e8 nodes in total (2-11M per instance). 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.