BC7-like texture compressor: per-block mode/partition search, pruning and endpoint refinement
/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 texture-compression pipeline (as run by game asset builds): a procedural RGBA8 texture is generated, its mip chain is built, and every 4x4 block of every mip level is encoded into an invented BC7-like fixed-rate format "XB7" (128 bits per block), then decoded again for verification. All arithmetic is integer; the CPU source is the reference for every detail.
- Texture
W x H: per texel, fromseed(texel()): integer bilinear value noise at cell sizes 64/16/4/128/32, hashed flat-colour discs and stripes in 32x32 cells, and alpha cut-out regions. Texel(x, y)depends only on(seed, x, y). - Mips: level
l+1isceil(w/2) x ceil(h/2), each channel(a+b+c+d+2)>>2of the 2x2 footprint (edge-clamped), untilLlevels exist or the level is 1x1. - Blocks: block
(bx, by)of a level takes texels(min(4bx+i, w-1), min(4by+j, h-1)). The weighted error of a reconstruction issum 3dR^2 + 6dG^2 + 1dB^2 + 2dA^2. - XB7 modes (unary mode prefix, LSB-first bit packing; details in
pack):- mode 0: 1 subset, RGBA endpoints 7 bits, 4-bit indices;
- mode 1: 2 subsets, 64 partitions, RGB endpoints 6 bits, 3-bit indices, alpha decodes to 255;
- mode 2: 3 subsets, 32 partitions, RGB endpoints 5 bits, 2-bit indices, alpha 255;
- mode 3: 1 subset, 4 channel rotations (swap channel
rot-1with alpha), RGB 5-bit endpoints with 2-bit indices plus a separate 6-bit scalar endpoint pair with 3-bit indices. Endpoints are de-quantized by bit replication; palette entryiis((64-w_i)*e0 + w_i*e1 + 32) >> 6with the weight tablesWT2/WT3/WT4. Partition tables are anisotropic Voronoi diagrams of hashed seed texels (build_partitions). The anchor texel of a subset is its first texel in raster order and is stored with one index bit less.
- Encoder per block: all 101 candidates (mode 0, 64 x mode 1, 32 x mode 2, 4 x mode 3) get initial endpoints (covariance-signed, inset bounding box, quantized) and optimal indices (lowest index on ties); the 4 candidates with the lowest error (lower candidate id on ties) are refined by two greedy passes of +-1 steps on every quantized endpoint component (a step is kept only if the error strictly decreases); the lowest refined error wins (earlier kept candidate on ties); the anchor fix-up swaps endpoints so anchor indices have a zero top bit.
- Decode check: each packed block is decoded and its error recomputed; any difference from the encoder's error (or mode) counts as a mismatch.
Input format
One line: W H L seed (1 <= W, H <= 8192, L >= 1 maximum number of mip levels, 64-bit seed).
Output format
One line per encoded level:
mip l wxh blocks N modes m0 m1 m2 m3 sse S maxsse M gain G toppart p:c hash X mismatch K
S = total weighted error, M = largest block error, G = sum over blocks of (best coarse
error - final error), p:c = most used mode-1 partition (lowest id on ties) and its count,
X = sum over blocks of mix64(w0 ^ mix64(w1 ^ (bi*0x9E3779B97F4A7C15))) with w0, w1 the two
64-bit words of the block and bi its index in the level (mod 2^64), K = decode mismatches.
A final total line gives level count, block count, total error and a digest.
Hidden inputs
Correctness inputs (14 files): textures from 1x1 to 180x200 (including sizes that are not
multiples of 4), L from 1 to 20. The timing input has W, H in about [2918, 3226] and
L = 20 (full mip chain) at scale 1.0; the texture area grows linearly with the scale.
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 is a roughly 3072x3072 RGBA texture with its full mip chain, about 0.79 million 4x4 blocks in total. 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.