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 40000 blocks of 65536..262144 symbols (about 6.6e9 symbols). 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 source generation only. Write /app/gpu/main.cu; compilation,
execution and verification are performed later in a separate verifier environment.
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.
- 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 40000 blocks of 65536-262144 symbols (about 6.6e9 symbols 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 public input examples for understanding the input format.