Port a meet-in-the-middle OpenMP search (sorted x^4+z^4 table, binary search per (y,w)) for x^4+3y^4+z^4 = k*w^4 to CUDA and make it fast
harbor run -t elfsong/cpu2gpu-dioph-quartic-3y4-kw4harbor download elfsong/cpu2gpu-dioph-quartic-3y4-kw4/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 a bound N and several values of k, it finds every integer quadruple (x, y, z, w) with
x^4 + 3*y^4 + z^4 = k * w^4, 0 <= x <= z <= N, 0 <= y <= N, 1 <= w <= N
(x and z play symmetric roles, so only x <= z is counted). The CPU program builds a
sorted table of all x^4 + z^4 with 0 <= x <= z <= N once, then for each k and each
(w, y) with 0 <= k*w^4 - 3*y^4 <= 2*N^4 it looks the difference up in the table
(w only runs while k*w^4 <= 5*N^4, which loses no solutions).
For each k it reports the number of solutions, how many are primitive
(gcd(x, y, z, w) = 1), an order-independent hash, and one extreme solution.
N Q
k_1
...
k_Q
0 <= N <= 6000, 1 <= Q, each 1 <= k <= 20000. All values fit comfortably in unsigned
64-bit arithmetic (5*N^4 < 2^53).
One line per k, in input order:
k COUNT PRIM HASH x,y,z,w
COUNT: number of solutions; PRIM: number with gcd(x, y, z, w) = 1.HASH: sum over all solutions of mix64(x | y<<16 | z<<32 | w<<48) modulo 2^64, with
mix64 the SplitMix64 finaliser in the CPU source.x,y,z,w: the solution with the largest w; ties broken by smallest x, then smallest y
(then smallest z).COUNT is 0 the line is k 0 0 0 -.Correctness inputs include N = 0, N = 1, small N with every k from 1 to 40,
N up to 1500 with a dozen k, and one input with N = 6000 and two k. About half of all
k are planted as x^4 + 3y^4 + z^4 with 0 <= x, y, z <= 7 (so they have solutions with
w = 1 and all their multiples); the others are uniform in [1, 20000]. The timing input has
N in [5500, 6000] and 400 values of k.
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.
/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./app/bin/gpu_run [--backend auto|local|remote] [--repeat N] [--quiet] SOURCE.cu INPUT_FILE.... The default uses GPU_RUNNER_URL
when configured, otherwise a GPU attached to this sandbox. Sandbox GPU access is
configured independently from verification; a CPU-only sandbox needs a runner URL.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.