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 writing the source only: it has g++ and the CPU program, but no CUDA
compiler and no GPU. Compilation, execution and verification happen later on an H100 in a
separate verifier, and a port that does not compile is rejected, so check your logic against
the CPU program before you finish (for example by emulating your kernels on the host).
How your port is verified
- 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. - Verification runs on one H100 in a fresh container without network. Hidden inputs are generated with a fresh random seed at verification time.
- Correctness: every hidden input (small edge cases plus a large timing input) must pass. Your output must be identical to the CPU program's output (trailing whitespace ignored). Any mismatch, crash or timeout is rejected.
- GPU execution is checked: a port that computes its answer on the CPU is rejected even when 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.
/app/inputs/timing_example.inhas the shape and size of the hidden timing input. Your port is timed against a reference GPU port on it; the faster your port, the higher its score. /app/inputs/holds public input examples for understanding the input format.