INT8 MLP chain with per-row dynamic requantisation
/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
A chain of L quantised MLP blocks applied to N token rows of D int8 activations.
All data are generated from the 64-bit seed with the counter hash gen(seed, tag, layer, idx)
defined in the CPU source. Everything is integer arithmetic; the output must match exactly.
Initial activations: A[i][k] = (gen(seed,1,0,i*D+k) % 201) - 100 (row-major N x D).
For each layer l = 0 .. L-1 (weights regenerated per layer):
W1(D x H, row-major) andW2(H x D, row-major): elementeis(gen(seed,2|3,l,e) % 255) - 127.b1[h] = 16 * ((gen(seed,4,l,h) % 4097) - 2048),m2[j] = 128 + gen(seed,5,l,j) % 128.- For every row
iindependently:acc[h] = b1[h] + sum_k A[i][k] * W1[k][h](int32).- Per-row dynamic requantisation:
M = max_h |acc[h]|;q[h] = round(acc[h] * 127 / M)with ties rounded away from zero (q = 0whenM = 0). - Activation:
g[h] = qifq >= 0, else-((3*(-q) + 4) >> 3). acc2[j] = sum_h g[h] * W2[h][j](int32).y[j] = round(acc2[j] * m2[j] / 2^S2)with ties away from zero, whereS2 = 14 + ceil(log2(H)) / 2(integer division).A[i][j] = clamp(A[i][j] + y[j], -127, 127)(in place; the new row is the next layer's input).
Input format
One line: N D H L SEED (all integers, SEED unsigned 64-bit).
Output format
N=<N> D=<D> H=<H> L=<L>
layer <l> rowmax_sum=<sum of M over rows> sum=<sum of new A> sumsq=<sum of squares> saturated=<number of clamped entries> hash=<H_l>
... (one line per layer)
row <i>: <first min(12, D) values of final row i> (4 lines, rows chosen by gen(seed,9,0,r) % N; omitted when N = 0)
final_hash=<F>
H_l = sum over (i, j) of mix64(((i*D + j) << 8) ^ (A[i][j] + 128)) modulo 2^64 (new values after
layer l), and F = sum over e of mix64(e * 0x2545F4914F6CDD1D + (A[e] + 128)) modulo 2^64 over the final
activations. mix64 is the SplitMix64 finaliser in the CPU source. Signed sums are printed as signed 64-bit.
Hidden inputs
Correctness inputs: 0 <= N <= 512, 1 <= D <= 2048, 1 <= H <= 4096, 0 <= L <= 5, including N = 0,
L = 0, D = H = 1, H = 1, sizes that are not multiples of 16/32/64, and D = 2048, H = 4096 with
few rows. The timing input has D in {960, 1024, 1088}, H = 4D, L = 8 and about
24000 * (1024/D)^2 rows. Intermediate values always fit in int32 (|acc| < 2^26 for these ranges);
acc2 * m2 needs 64 bits.
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: One input with D in {960, 1024, 1088}, H = 4D, L = 8 layers and about 24000 * (1024/D)^2 token rows (about 1.6e12 int8 multiply-adds). 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.