FP16 residual 3x3 convolution blocks with padding modes and dilation
/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
A stack of NB FP16 residual convolution blocks applied to N images of H x W pixels with
C channels, stored NHWC. All constants and hash functions are defined in the CPU source.
Data (from SEED by counter hashes): the input activations are FP16 values in [0, 1). Block
b has two 3x3 weight tensors W1, W2 ([tap][c_in][c_out], FP16, uniform in
+-1/sqrt(C) and +-0.5/sqrt(C)), biases b1, b2 and a per-channel skip gain g in
[0.5, 1] (all FP16 values). Block b maps x to y:
h = fp16( clamp( conv(x, W1, PAD1, dilation 1) + b1, 0, 8 ) )
z = fp16( conv(h, W2, PAD2, dilation DIL) + b2 )
y = fp16( clamp( z + g[c] * x[(c + ROT) mod C], 0, 16 ) ) (channel c of each pixel)
conv(a, W, mode, d)[y][x][co] = sum over ky, kx in {0,1,2}, ci of a[P(y + (ky-1)*d)][P(x + (kx-1)*d)][ci] * W[ky*3+kx][ci][co]
where P resolves an out-of-image coordinate according to the padding mode: 0 zero (the tap
contributes nothing), 1 clamp to the edge, 2 mirror with the edge repeated
(-1 -> 0, -2 -> 1, n -> n-1, period 2n), 3 wrap (periodic). Dilations up to 3 may
exceed the image size; P is applied with the modular formulas of the source. fp16() rounds an
FP32 value to the nearest IEEE binary16 value (ties to even). The products and sums of a
convolution are FP32 (any summation order, FMA or tensor cores with FP16 inputs and FP32
accumulation are fine; FP16 accumulation is not guaranteed to pass). The output of block b is the
input of block b+1.
Input format
N H W C NB SEED
PAD1 PAD2 DIL ROT (NB lines, one per block)
1 <= N <= 64, 1 <= H, W <= 512, 1 <= C <= 128, 0 <= NB <= 8, 0 <= PAD1, PAD2 <= 3,
1 <= DIL <= 3, 0 <= ROT < C, N*H*W*C <= 2^27, SEED an unsigned 64-bit integer.
Output format
images N size HxW channels C blocks NB
mean c m_c ... m_{c+7} (per channel: mean of the final activations over all images and pixels, 8 per line)
ring c r_c ... r_{c+7} (per channel: mean over the pixels within 2 of the image border, all images)
image n mean M meansq Q (per image: mean and mean square over all pixels and channels)
patches P_0 P_1 P_2 P_3 P_4 (image 0: sums over all channels of the 3x3 patches at the four corners and the centre)
All statistics are computed from exact integer sums of the final FP16 values (values scaled by
2^24, squares scaled by 2^12 and truncated; see the source) and printed with %.9e. Numeric tokens
are compared with a relative tolerance of 5e-2 plus an absolute tolerance of 5e-3; words must match
exactly. The tolerance exists because any change of the FP32 summation order (tiling,
FMA, tensor cores) flips a few FP16 roundings of the intermediates by one ulp, and through the
residual stack these differences spread to a large part of the activations; in our measurements they
move the statistics by up to about 1e-3 relative. Storing activations in a format other than FP16
(or accumulating in FP16) is not what is asked and is not guaranteed to pass.
Hidden inputs
Correctness inputs (about 12) include a 1x1 image with one channel, a single-row image, a dilation
wider than the image, C = 3, no blocks at all, tiles and channel groups that are not full
(33 x 47 pixels, 40 channels), C = 128, all four padding modes and random shapes up to 48x48
pixels and 96 channels. The timing input has 16 images of 168-184 pixels squared, 128 channels and
8 residual blocks (16 convolutions, about 1.2e12 multiply-adds).
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 have the same tokens as the CPU program's output. Numeric tokens may differ by at most
atol + rtol*|expected|with rtol = 0.05 and atol = 0.005; every other token must be identical. 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 has 16 images of 168-184 pixels squared with 128 channels and 8 residual blocks (16 convolutions, about 1.2e12 multiply-adds).
/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.