Port an OpenMP O(n^3) interval DP (optimal recursive splitting with a non-monotone split penalty) to CUDA and make it fast
harbor run -t elfsong/cpu2gpu-dp-interval-splitharbor download elfsong/cpu2gpu-dp-interval-split/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.
For each of T independent instances, a sequence a[0..n-1] of integers in [1, 100] and a
6-bit tag u[k] per position are generated from the seed. The program solves the interval
recursion
dp[i][i] = a[i] % 7
dp[i][j] = (a[i] + ... + a[j]) + min over i <= k < j of
dp[i][k] + dp[k+1][j] + ((u[k] XOR (j - i)) AND 63) + |a[k] - a[k+1]|
for all 0 <= i <= j < n (O(n^3) work). The split penalty mixes the split point and the
interval length bitwise, so monotone-split shortcuts (Knuth / quadrangle inequality) do not
hold; the full minimum over k is required. All values fit in 32-bit signed integers.
T SEED
n_1
...
n_T
SEED is an unsigned 64-bit integer, 1 <= n <= 4500. Instance t (0-based) derives its data
from mix64(SEED + (t+1) * 0xD1B54A32D192ED03) as in the CPU source.
One line per instance: t n DP[0][n-1] ROOT DP[n/3][2n/3] HASH, where ROOT is the
smallest optimal split point k of the whole interval (-1 when n = 1) and HASH is the
sum over all i <= j of mix64(((i*n + j) * 0xD1B54A32D192ED03) XOR (uint32)dp[i][j])
modulo 2^64.
Correctness inputs use n from 1 to 1600 (including n = 1, 2, 3 and sizes around 64),
seeds 0 and 2^64-1, and 1 to 6 instances per input. The timing input has 32 instances with
n uniform in [3000, 4500].
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.