Representation numbers of mixed-power diagonal forms
/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
For each query (a diagonal Diophantine form with mixed powers) it computes the representation numbers
r(n) = #{ (t_1, ..., t_T) : c_1*t_1^p_1 + c_2*t_2^p_2 + ... + c_T*t_T^p_T = n } for 0 <= n < N
where variable t_j ranges over all integers if term j is signed (s_j = 1, only for
even p_j) and over non-negative integers otherwise. Counts are kept modulo 2^64.
The CPU program starts from r = delta_0 and applies the terms one after another as sparse
convolutions: with the shifts c_j*t^p_j < N (t = 0, 1, 2, ...) and weights 2 for t > 0
of a signed term, else 1, r'(n) = sum_t weight(t) * r(n - c_j*t^p_j). It is blocked over n.
Input format
Q
N T
c_1 p_1 s_1
...
c_T p_T s_T
(repeated Q times)
1 <= N <= 5,000,000, 1 <= T <= 8, 1 <= c <= 1000, 2 <= p <= 6, s in {0, 1} and
s = 1 only for even p.
Output format
Three lines per query, in input order:
N TOTAL ZEROS HASH LASTZERO
max MAXR ARGMAX
tail r(N-1) r(N-2) ... r(N-8)
TOTAL: sum ofr(n)(mod 2^64);ZEROS: number ofnwithr(n) = 0;LASTZERO: the largest suchn(-1if none).HASH: sum overnwithr(n) != 0ofmix64((n << 1) xor mix64(r(n)))modulo 2^64 (mix64= SplitMix64 finaliser in the CPU source).MAXR: the largestr(n)(as unsigned 64-bit),ARGMAXthe smallestnattaining it (-1if all zero).tail: the lastmin(N, 8)values, starting fromr(N-1)downwards.
Hidden inputs
Correctness inputs include N = 1, terms with no admissible shift except t = 0, random
forms with 1 to 8 terms and powers 2..6 for N up to 10^6, and
one 8-term form with N = 5,000,000. The timing input has 32 forms with N in [3e6, 4e6],
each with four square terms (one with c = 1, three with c in [2, 6]), one cube term and one
fourth-power term (c in [1, 10]), in random order.
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 forms, each with N in [3e6, 4e6] and six terms (four squares, one cube, one fourth power). 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.