Wavelet image codec rate/distortion run with a 3-step integer lifting DWT
/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 rate/distortion evaluation of a wavelet image codec (the encoder and decoder are both run, the
bitstream itself is only costed). For each of NIMG synthetic images of W x H pixels:
-
Synthesis. A 12-bit image (values 0..4095) is built from a seeded smooth lattice (bilinear on a 128-pixel grid), per-64x64-cell half-plane edges, optional stripe textures and per-pixel hash noise, exactly as in the CPU source (
mix64is the SplitMix64 finaliser, imagemuses the seedsi = mix64(seed ^ (0x9E3779B97F4A7C15 * (m+1)))). The coder works ona = v - 2048. -
Forward DWT,
Llevels.L = min(LEV, number of halvings until the low band is 1x1); levellworks on the top-leftlw[l] x lh[l]region (lw[l+1] = ceil(lw[l]/2), same forlh). Each level transforms every row (if the width is at least 2) and then every column (if the height is at least 2) with the same 1D integer lifting: split into even sampless(ns = ceil(n/2)) and odd samplesd(nd = floor(n/2)), then- predict:
d[i] -= (s[i] + s[i+1]) >> 1 - update:
s[i] += (d[i-1] + d[i] + 2) >> 2 - refine:
d[i] += (s[i-1] - s[i] - s[i+1] + s[i+2] + 8) >> 4
with indices clamped into the valid range of the array they index (
>>is an arithmetic shift). The result is stored deinterleaved: low half first, high half second. - predict:
-
Subbands and quantisation. Level
l(1 = finest) has HL (right of the low part, top), LH (left, bottom) and HH (bottom-right) bands, plus one final LL band. Step sizes:delta = max(1, (QBASE * WO[o] * WL[l]) >> 12)withWO = {64, 64, 90}andWL = {-, 64, 48, 34, 24, 17, 12, 8, 6}, andmax(1, (QBASE*6) >> 6)for LL. Dead-zone quantiser:q = sign(c) * floor((4|c| + delta) / (4 delta)). -
Entropy and bit-plane statistics. Each band is cut into
CB x CBcode-blocks. Inside a code-block every coefficient gets a context = number of non-zero quantised neighbours among left, up, up-left and up-right that lie inside the same code-block. Cost (in 1/16 bit): a zero costsZC[ctx], a non-zeroNZC[ctx] + 16*(2*bitlen(|q|) - 1) + 16; each code-block adds 96 if it has a non-zero coefficient and 4 otherwise. Per code-block the number of coding passes is3*bitlen(max|q|) - 2(0 if all zero). Every non-zero coefficient also counts in a significance histogram bymin(bitlen(|q|), 16). -
Decoder. Dequantise
c' = sign(q) * (((4|q| + 1) * delta) >> 2), run the exact inverse lifting (steps undone in reverse order, coarsest level first, columns before rows), add 2048, clamp to 0..4095 and compare with the original image.
Input format
One line: W H NIMG LEV QBASE CB SEED (all integers, SEED is an unsigned 64-bit value).
Output format
For each of the first 20 images:
img m bits16 B bpp R sse S psnr P maxerr E exact X nonzero N qhash QH rhash RH
where bits16 is the estimated size in 1/16 bit, bpp = bits16 / (16 W H) (%.5f), sse the
sum of squared reconstruction errors, psnr = 10 log10(4095^2 W H / sse) (%.4f, inf when
sse = 0), exact the number of pixels reconstructed exactly, nonzero the number of non-zero
quantised coefficients, qhash = sum over non-zero q at linear position p of
mix64(p * 0x9E3779B97F4A7C15 ^ (u64)q) and rhash = sum over pixels of
mix64(p * 0xD1B54A32D192ED03 + r) (sums mod 2^64, printed as 16 hex digits).
Then one band line per subband (finest level first, HL LH HH, then LL) with its size, step,
and totals over all images: coefficients, non-zeros, sum of |q|, max |q|, bits16, max bit length
(planes) and coding passes; one sigplanes line with the 16 histogram counts; and one total
line with the totals over all images and a combined hash (see the CPU source). PSNR and bpp are
computed on the host from the exact integer totals.
Hidden inputs
Correctness inputs (14 files): 1x1, a single column, a single row, 2x2, odd sizes with LEV
larger than possible, QBASE = 1 (near lossless), QBASE up to 512, up to 25 images (only 20
printed), code-block sizes 16, 32 and 64, and random sizes W, H in 1..300 plus one 512x320
image. All inputs satisfy 1 <= W, H <= 8192, 1 <= NIMG <= 72, 1 <= LEV <= 8,
1 <= QBASE <= 512, CB in {16, 32, 64}. The timing input has W = 8192, H in 7680..8192,
44 to 50 images, LEV 5 or 6, QBASE 12..48 and CB 32 or 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.
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.
- For public GPU experiments, use
/app/bin/gpu_run [--backend auto|local|remote] [--repeat N] [--quiet] SOURCE.cu INPUT_FILE.... The default usesGPU_RUNNER_URLwhen configured, otherwise a GPU attached to this sandbox. Sandbox GPU access is configured independently from verification; a CPU-only sandbox needs a runner URL. - 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 has 44-50 synthetic images of 8192 x 7680..8192 pixels with 5 or 6 decomposition levels, QBASE 12-48 and 32x32 or 64x64 code-blocks (about 3e9 pixels through the forward and inverse transform). 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.