Path-count structure statistics of a sparse product A*B
/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
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 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. - Grading runs on one H100 in a fresh container without network. 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 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 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.