Bijective-BWT block decompression: RUNA/RUNB, inverse MTF, inverse BWTS, RLE1
/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
The back end of a bzip2-style block decompressor that uses the bijective Burrows-Wheeler
transform (BWTS, Gil-Scott): every string is a valid BWTS image, so the container can be generated
freely. The CPU source is the specification; this is a summary (mix64 = SplitMix64 finaliser).
- Container. Block
b(hb = mix64(SEED ^ (0xB75B000000000000 + b))) hasn = NMIN + hb % (NMAX-NMIN+1)MTF indices, redundancy levellvl = (hb >> 32) % 4, list rotationrot = (hb >> 40) & 255andkey = mix64(hb ^ 0xC0FFEE0DDF00D). Tokenkusesh = mix64(key + k * 0x9E3779B97F4A7C15): with probabilityRUNP[lvl]/256(h & 255) it starts with a zero run of1 + (e random bits)(e = (h >> 8) % RUNE[lvl]), followed by the MTF valuemin(255, 65536 / (((h >> 32) & 0xFFFF) + 1)); the last token is cut so that the block holds exactlynindices. Runs are written as bzip2 RUNA/RUNB digits (bijective base 2, RUNA = 0 meaning 1, RUNB = 1 meaning 2, least significant digit first), a valuejas symbolj + 1, and the block ends withEOB = 257. - Stage 1 expands the RUNA/RUNB runs into MTF index 0s.
- Stage 2 inverse move-to-front over a 256-entry list initialised to
list[i] = (167 i + rot) mod 256. - Stage 3 inverse BWTS of the resulting string
L: the standard permutationpi(stable counting sort:pi[f]= position inLof thef-th smallest character) is split into cycles; the cycle with smallest elementstyields the Lyndon factorL[pi[st]], L[pi[pi[st]]], ...(cycle length characters); the factors are concatenated in decreasing order ofst. - Stage 4 RLE1 expansion of that string
S: after four equal output bytes the next input byte is a repeat count (0..255) for the same byte, then counting restarts. - Checksum per block:
sum_j mix64(w_j ^ (j * 0xD1B54A32D192ED03) ^ (b << 40))over the little-endian 8-byte words of the expanded output (last word zero-padded); a global byte histogram; numbers of Lyndon factors (cycles), the longest factor and RLE1 count bytes.
Input format
One line: NB NMIN NMAX SEED (SEED is an unsigned 64-bit integer).
Output format
blocks NB symbols N container_symbols CS output_bytes O
level l blocks B symbols S factors F output O rle_runs R (l = 0..3)
lyndon factors F longest LMAX rle_runs R
max expansion block b permille P (largest floor(1000 * output / n), smallest b on ties)
histogram hash H top c:n c:n ... (8 most frequent output bytes, ties to smaller byte)
checksum C
Sums and hashes are modulo 2^64.
Hidden inputs
1 <= NB <= 200000,1 <= NMIN <= NMAX <= 262144.- Correctness inputs include a one-symbol block, blocks of 1-20 symbols, blocks of exactly 2 symbols, the largest blocks, seeds 0 and 2^64-1 and random mixes (at most a few million symbols).
- The timing input has the shape and size of
/app/inputs/timing_example.in. Blocks have about 10-25 Lyndon factors; the longest factor usually covers most of the block.
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 be identical to the CPU program's output (trailing whitespace ignored). 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:
/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.