Path-count structure statistics of a sparse product A*B
/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
Two sparse 0/1 matrices are generated from the seed: A (NA x NB) and B
(NB x NC), stored as CSR. Row i of a rows x cols matrix has a skewed length
(1 row in 64 is a hub with 16*D entries, capped at 4096; the others have between 1 and
2D-1), and each entry is with probability 3/4 a column near the diagonal position
i*cols/rows (within +-512 for A, +-256 for B, cyclically) and otherwise uniform.
Duplicate entries within a row are allowed and count separately. The CPU source is the
exact specification of the generator (B uses seed mix64(SEED+1)).
It then forms C = A * B over the counting semiring: C[i][j] is the number of pairs
(entry k of row i of A, entry j of row k of B). Only statistics are output.
Input format
One line: NA NB NC DA DB SEED.
Output format
A NA x NB nnz NNZ_A
B NB x NC nnz NNZ_B
flops F number of products (sum of all C values)
nnz Z number of nonzero entries of C
mult1 X mult2 Y mult3plus W maxmult M entries with value 1, 2, >= 3; largest value
maxrow I nnz R the row with the most nonzeros (smallest index on ties)
hist h0 h1 ... rows by nonzero count: bucket 0 for 0, bucket b for [2^(b-1), 2^b),
last bucket 24 collects the rest; printed up to the last non-empty bucket
hash H sum mod 2^64 of mix64(mix64((i << 32) | j) + C[i][j]) over nonzeros
Hidden inputs
1 <= NA, NB, NC <= 3,300,000, 1 <= DA, DB <= 64. Correctness inputs include 1x1
matrices, single rows and columns, hub rows longer than the column count, strongly
rectangular shapes, and sizes up to 100,000. The timing input has NA = 3,000,000,
NB and NC within 10% of NA, DA = 32, DB = 64.
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 source generation only. Write /app/gpu/main.cu; compilation,
execution and verification are performed later in a separate verifier environment.
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. - GPU verification uses the backend selected for this run: an H100 attached to the separate verifier, or a remote H100 worker. Hidden inputs use a fresh random seed.
- 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.
- GPU execution: a separate, untimed CUPTI check must observe completed GPU kernel activity on the hidden timing input. A CPU-only submission receives reward 0 even if its output is correct.
- Speed: The timing input multiplies a 3,000,000-row A (mean row length about 39, hub rows of 512) by a B with about 3,000,000 rows (mean row length about 79, hub rows of 1024): about 9e9 scalar products and 6e9 nonzeros in C. 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 public input examples for understanding the input format.