GeoZL

What a GPU wants from a format

  • PFOR (CTid 0x72D70D) and PivCo-Huffman inside the lanes codecs (CTids 0x72D713 and 0x72D712).

A GPU decodes in a way a CPU never has to. Thousands of threads run the same small program at once, and every one of them has to find its own input without waiting for another. This part is about what that asks of a compressed format, and which of GeoZL's codecs can give it. The reason to care is that a model wants its batch as a tensor in GPU memory, which is what Rumi asks GeoZL for.

That requirement splits the current codecs cleanly. GPU decoding supports layouts ending in PFOR or lanes. med and generic entropy graphs use the CPU path. Fixing the lanes format for GPU decoding also costs some compression ratio, as the last section explains.

A wave, 32 threads in step

A GPU runs its threads in groups of 32, and the 32 threads of a group execute the same instruction at the same moment, each on its own value. We call that group a wave (a warp on NVIDIA, a SIMD-group on Apple). It is the SIMD register from part one again, with 32 lanes instead of 8.

The figure gives 8 threads of a wave three jobs and counts the turns each one takes. Each thread is a column and each turn a row, so time runs down the panel. Green finishes in one turn, yellow in three, and red in eight.

Eight wave threads compare independent arithmetic, a prefix sum and a serial path. The jobs keep all threads busy for one, three and eight turns respectively.
1 / 8
The same eight threads, three jobs, one turn, three turns and eight turns.

Green. One instruction, x = 2 × x, gives eight results in one turn. Any work a thread can do with its own value alone runs like this, and a decoder wants as much of its work as possible to look like it.

Yellow. Sometimes a thread needs values from other threads. In the figure every thread holds a count and wants the total up to itself, close to what PivCo asks below, how many 1s come before it. A shuffle lets a thread read a value from another thread of its wave, register to register, for about the cost of an add. In turn 1 every thread adds the value one thread back, in turn 2 two back and in turn 3 four back, and the rings follow t7 as it does. After three turns every thread has its total, and nobody waited. This is the wave prefix sum, the doubling from a prefix sum inside a register with threads in place of lanes, and a wave of 32 needs five turns.

Red. Now the threads follow a raindrop downhill on a small elevation grid, one step each. A step looks at the eight neighbours of the cell where the drop is and moves it to the lowest. t0 starts at A1 and finds B2. t1 cannot even start until it knows the drop is at B2, and then finds B3, and so on. No thread knows where to look until the thread before it has moved the drop, so there is nothing to shuffle and the threads take turns, one busy and the rest waiting, eight turns here and 32 on a real wave. Reading variable-length codes, such as Huffman's, has the same shape, and the next section shows it.

PFOR, where every thread starts at once

PFOR packs a block at one bit width b and moves the high bits of the few values that do not fit, the exceptions, to a side list. Every value in the body has the same width, so the start of a value is a multiplication. In the lane layout from part one, with 16-bit samples, thread t finds its eight values at bit t × b of every lane, usually with one 16-byte load.

An exception takes one more step, because its thread has to find its high bits in the side list. Every thread builds the same bit mask, with one bit set at each exception position. In the figure, only bit 7 is set. The high bits of an exception sit at its rank, which is the number of exceptions before it. So a thread counts the set bits below its own position with popcount, reads the high bits at that rank, and ORs them in above its low b bits. A block stores the positions either as a list or as a bitmap; the PFOR page describes both.

Eight values, 3 5 2 7 4 6 1 90, at b = 3 bits. The body keeps the low 3 bits of each, and the high bits of 90, 1011, go to a side list with its position 7. Thread t reads its slot at bit 3 times t, so all eight read at once and get 3 5 2 7 4 6 1 2. Every thread turns the position list into a bit mask with bit 7 set. t7 counts the set bits before position 7 with popcount, gets rank 0, reads 1011 at rank 0, shifts it up by 3 and ORs it onto 010, which gives 90.
1 / 6
Every thread finds its bits with a multiplication and its exception with a count.

Nothing here waits on another thread. The block format came from SIMD on a CPU, long before the GPU decoder, and the GPU reads the same frames unchanged. Bytes to tensors follows the kernel through one real 256-value block.

PivCo, decoding from the leaves up

Plain Huffman writes each code in one piece, so a thread cannot find where its code starts until it has read every code before it. PivCo-Huffman keeps the same codes and only reorders the bits, one bitmap per node of the tree with one bit for every symbol that reaches it.

Root-down traversal. A symbol visits one bitmap per bit of its code, up to twelve, so threads with short codes sit idle while the long ones finish. Finding each thread's place also needs a rank directory over the bitmaps, built in a separate pass and about two thirds the size of the frames it serves.

The PivCo tree of a b a c a b a a, root bitmap 01010100 over an a leaf and a b or c node with bitmap 010. Walking down from the root, all eight threads take the first step, then the five a threads sit idle while t1, t3 and t5 take a second. To read its bit in 010, t3 needs the number of 1s before it in the root, one, and a separate pass writes those counts as a rank directory.
1 / 3
Walking down, short codes wait for long ones, and every step needs a rank directory.

Leaf-up decoding. GeoZL starts at the deepest level and writes each node's symbols in order. The threads of a wave work on the same node, and no rank directory is needed.

The figure decodes a b a c a b a a with a = 0, b = 10 and c = 11. A leaf repeats its symbol once for every symbol that reaches it. A node merges what its two children wrote, where a 0 in its bitmap takes the next symbol from the left child and a 1 the next from the right.

The PivCo tree of a b a c a b a a, root bitmap 01010100, an a leaf, and a b or c node with bitmap 010 over a b leaf and a c leaf. Decoding from the leaves up, the b and c leaves write b b c into positions 5 to 7 of the lane buffer, the a leaf writes five a into scratch, the b or c node merges b b c by 010 into b c b in scratch, and the root merges scratch by 01010100 back into the lane buffer, giving a b a c a b a a.
1 / 5
Each level merges the two ranges below it, and the symbols move between the lane buffer and scratch.

Position i of a node takes the left symbol numbered by the 0s before i, or the right one numbered by the 1s before it. A thread owns one byte of the bitmap, eight positions, counts its 1s with popcount, and a wave prefix sum tells it how many 1s come before its byte.

A node writes over the range its children used, so even levels write the lane buffer and odd levels write scratch, with a barrier between levels so a parent merges only once its children are done. The level loop is short, and Bytes to tensors shows how four waves share one block.

The same eight symbols both ways. From the root, all eight threads step once, then five sit idle while three step again, and a separate pass builds a rank directory. From the leaves, the wave writes b b c, merges it by 010 into b c b, then merges by 01010100 into a b a c a b a a, one node at a time and with no directory.
Walking down costs idle threads and an extra pass. Climbing up costs neither.

One idea, two shapes

PFOR and PivCo both work in independent blocks, 256 values for PFOR and 32 768 symbols of one byte lane for PivCo, so a batch splits into thousands of blocks that all decode at once. In planar>zigzag>pfor the independent piece is a strip of a band of rows, since its prediction restarts at the edges of every strip, and one wave walks the blocks of each strip.

A batch of three frames, two ending in pfor and one in lanes. The planar>zigzag>pfor frame splits into strips, each up to 16 rows by 1024 columns of blocks, the id>pfor frame into 256-value PFOR blocks, and the lanes frame into a low byte lane of 32 768-symbol PivCo blocks and a high byte lane of byte PFOR blocks. Every strip and every PFOR block gets one wave and every PivCo block a group of four waves, and all of them decode at once.
1 / 3
A batch becomes blocks and strips, and each one gets its own waves.
PFORPivCo
positionslot × bcount of 1s before you
block256 values32 768 symbols per byte lane
best forsmall residuals that do not repeatbytes with a skewed distribution
recipesplanar>zigzag>pfor, id>pforplanar>zigzag>lanes, id>lanes

Why the lane format is fixed

PivCo works on bytes, so the lanes codec splits a 16-bit raster into a low-byte lane and a high-byte lane, which is where its name comes from. A GPU kernel must know a frame's layout from its CTid alone. The lanes codec therefore writes each byte lane as PivCo Huffman or byte PFOR, whichever is smaller. It never delegates a lane to FSE or another generic entropy codec based on the data. That closed choice lets the GPU plan every lanes frame without first running a data-dependent OpenZL selector.

A data-dependent selector may choose FSE, PivCo or byte PFOR for a lane, so its CTid does not reveal the layout. The fixed lanes format chooses only PivCo Huffman or byte PFOR, whichever is smaller, so the GPU can plan the frame from its CTid.
A fixed layout is what lets a GPU plan a frame from its CTid. Skewed lanes paid for it.

The trade-off appears on skewed lanes. Huffman cannot use less than one bit per symbol, while FSE can, so a lane dominated by one value may compress worse. A class map is flat over large areas, and after prediction most residuals may be zero, which is exactly that case.

Data read only on a CPU can use planar>zigzag>transpose>entropy instead. A different GPU encoding needs its own CTid rather than a data-dependent branch inside lanes.

Other ways to decode on the GPU

The format of the files you already have often decides where to start. nvImageCodec reads TIFF and JPEG 2000, cog3pio reads GeoTIFFs through nvTIFF, a proposed Zarr integration uses nvCOMP to decode zstd, and cuSZp reads its own format. The table compares those paths with GeoZL and Rumi.

With GeoZL and cuSZp, you can inspect and change the GPU codecs themselves. nvImageCodec, cog3pio and the Zarr proposal have open libraries around closed NVIDIA decoders.

GeoZL
with Rumi
nvImageCodeccog3pioZarr
with nvCOMP
cuSZp
source codeopenopen library; closed nvTIFF and nvJPEG2000 decodersopen library; closed nvTIFF decoderopen zarr-python; closed nvCOMPopen
GPUsCUDA and Metal from one Slang source, extensible to Vulkan, WebGPU or HIPNVIDIA; TIFF needs Volta or newerNVIDIA, with CUDA wheels for Linux onlyNVIDIANVIDIA
GPU codecsonly PFOR and PivCononenonenoneits own codec, decoded in one kernel
bounded errornot supported on the GPUnononofloat32 and float64 only
Python outputDLPack for PyTorch, JAX or TensorFlowDLPack and the CUDA array interfaceDLPack, or CuPy with the cuda extraCuPy arrays, which other libraries take through DLPacka PyTorch tensor you allocate
existing filesnoneCOGs with Deflate, LZW or JPEG, plus Sentinel-2 JPEG 2000. No ZSTD or LERCGeoTIFFs and COGs that nvTIFF decodesZarr arrays compressed with zstdnone
statusreleased; format may still changereleasedreleased 0.1.0; API still changingopen pull requestreleased

Green marks a strength, yellow a partial fit and red a gap.

The table compares what each path supports, not how fast it is. We have not yet run these options side by side on the same data and GPUs, so where open codecs stand against NVIDIA's closed decoders is still an open question. It needs more experiments and a shared benchmark.

A GPU read also has to fetch compressed bytes, plan the work on the CPU and put the result where the caller needs it. The next part, Bytes to tensors, follows one batch from file to tensor.