Skip to content

Add kernel interface, generic impl, and test suite (#848)#848

Open
terrelln wants to merge 4 commits into
facebook:devfrom
terrelln:export-D109878842
Open

Add kernel interface, generic impl, and test suite (#848)#848
terrelln wants to merge 4 commits into
facebook:devfrom
terrelln:export-D109878842

Conversation

@terrelln

@terrelln terrelln commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Summary:

Introduces the architecture-specific kernel interface for the PivCo-Huffman codec along with a portable, correctness-oriented generic implementation and the kernel test suite.

The ZL_PivCoHuffmanEncode and ZL_PivCoHuffmanDecode structs provide the interface to cleanly swap between implementations based on the CPU. The select() function will pick the best implementation based on the current CPU, when they are added, but for now just returns the generic implementation.

These are the kernels defined in the PivCo Huffman paper. The only difference is the encode side is modified following the same strategy as the upstream repo to operate on uint8_t rank values, rather than uint16_t codeword values. The reasoning for how that change work is explained in the next diff, but the benefit is working on uint8_t instead of uint16_t.

Note that some buffers require SLOP bytes at the end, and partitionFull has an odd aliasing requirement. These are constraints that are imposed by the full implementation in the next diff.

Differential Revision: D109878842

@meta-codesync

meta-codesync Bot commented Jun 26, 2026

Copy link
Copy Markdown

@terrelln has exported this pull request. If you are a Meta employee, you can view the originating Diff in D109878842.

@meta-codesync meta-codesync Bot changed the title Add kernel interface, generic impl, and test suite Jun 29, 2026
terrelln added a commit to terrelln/openzl that referenced this pull request Jun 29, 2026
Summary:

Introduces the architecture-specific kernel interface for the Huffman Pivoted codec along with a portable, correctness-oriented generic implementation and the kernel test suite.

The `ZL_HuffmanPivotedEncode` and `ZL_HuffmanPivotedDecode` structs provide the interface to cleanly swap between implementations based on the CPU. The `select()` function will pick the best implementation based on the current CPU, when they are added, but for now just returns the generic implementation.

These are the kernels defined in the [PivCo Huffman paper](https://arxiv.org/pdf/2606.05765). The only difference is the encode side is modified following the same strategy as the [upstream repo](https://github.com/MarcinZukowski/pivco-huffman) to operate on `uint8_t rank` values, rather than `uint16_t codeword` values. The reasoning for how that change work is explained in the next diff, but the benefit is working on `uint8_t` instead of `uint16_t`.

Note that some buffers require `SLOP` bytes at the end, and `partitionFull` has an odd aliasing requirement. These are constraints that are imposed by the full implementation in the next diff.

Differential Revision: D109878842
@terrelln terrelln force-pushed the export-D109878842 branch from a739046 to 624807c Compare June 29, 2026 16:56
terrelln added a commit to terrelln/openzl that referenced this pull request Jun 29, 2026
Summary:

Introduces the architecture-specific kernel interface for the Huffman Pivoted codec along with a portable, correctness-oriented generic implementation and the kernel test suite.

The `ZL_HuffmanPivotedEncode` and `ZL_HuffmanPivotedDecode` structs provide the interface to cleanly swap between implementations based on the CPU. The `select()` function will pick the best implementation based on the current CPU, when they are added, but for now just returns the generic implementation.

These are the kernels defined in the [PivCo Huffman paper](https://arxiv.org/pdf/2606.05765). The only difference is the encode side is modified following the same strategy as the [upstream repo](https://github.com/MarcinZukowski/pivco-huffman) to operate on `uint8_t rank` values, rather than `uint16_t codeword` values. The reasoning for how that change work is explained in the next diff, but the benefit is working on `uint8_t` instead of `uint16_t`.

Note that some buffers require `SLOP` bytes at the end, and `partitionFull` has an odd aliasing requirement. These are constraints that are imposed by the full implementation in the next diff.

Differential Revision: D109878842
terrelln added a commit to terrelln/openzl that referenced this pull request Jun 29, 2026
Summary:

Introduces the architecture-specific kernel interface for the Huffman Pivoted codec along with a portable, correctness-oriented generic implementation and the kernel test suite.

The `ZL_HuffmanPivotedEncode` and `ZL_HuffmanPivotedDecode` structs provide the interface to cleanly swap between implementations based on the CPU. The `select()` function will pick the best implementation based on the current CPU, when they are added, but for now just returns the generic implementation.

These are the kernels defined in the [PivCo Huffman paper](https://arxiv.org/pdf/2606.05765). The only difference is the encode side is modified following the same strategy as the [upstream repo](https://github.com/MarcinZukowski/pivco-huffman) to operate on `uint8_t rank` values, rather than `uint16_t codeword` values. The reasoning for how that change work is explained in the next diff, but the benefit is working on `uint8_t` instead of `uint16_t`.

Note that some buffers require `SLOP` bytes at the end, and `partitionFull` has an odd aliasing requirement. These are constraints that are imposed by the full implementation in the next diff.

Differential Revision: D109878842
terrelln added a commit to terrelln/openzl that referenced this pull request Jun 29, 2026
Summary:

Introduces the architecture-specific kernel interface for the Huffman Pivoted codec along with a portable, correctness-oriented generic implementation and the kernel test suite.

The `ZL_HuffmanPivotedEncode` and `ZL_HuffmanPivotedDecode` structs provide the interface to cleanly swap between implementations based on the CPU. The `select()` function will pick the best implementation based on the current CPU, when they are added, but for now just returns the generic implementation.

These are the kernels defined in the [PivCo Huffman paper](https://arxiv.org/pdf/2606.05765). The only difference is the encode side is modified following the same strategy as the [upstream repo](https://github.com/MarcinZukowski/pivco-huffman) to operate on `uint8_t rank` values, rather than `uint16_t codeword` values. The reasoning for how that change work is explained in the next diff, but the benefit is working on `uint8_t` instead of `uint16_t`.

Note that some buffers require `SLOP` bytes at the end, and `partitionFull` has an odd aliasing requirement. These are constraints that are imposed by the full implementation in the next diff.

Differential Revision: D109878842
@terrelln terrelln force-pushed the export-D109878842 branch from 624807c to 61faf22 Compare June 29, 2026 18:40
terrelln added a commit to terrelln/openzl that referenced this pull request Jun 29, 2026
Summary:

Introduces the architecture-specific kernel interface for the Huffman Pivoted codec along with a portable, correctness-oriented generic implementation and the kernel test suite.

The `ZL_HuffmanPivotedEncode` and `ZL_HuffmanPivotedDecode` structs provide the interface to cleanly swap between implementations based on the CPU. The `select()` function will pick the best implementation based on the current CPU, when they are added, but for now just returns the generic implementation.

These are the kernels defined in the [PivCo Huffman paper](https://arxiv.org/pdf/2606.05765). The only difference is the encode side is modified following the same strategy as the [upstream repo](https://github.com/MarcinZukowski/pivco-huffman) to operate on `uint8_t rank` values, rather than `uint16_t codeword` values. The reasoning for how that change work is explained in the next diff, but the benefit is working on `uint8_t` instead of `uint16_t`.

Note that some buffers require `SLOP` bytes at the end, and `partitionFull` has an odd aliasing requirement. These are constraints that are imposed by the full implementation in the next diff.

Differential Revision: D109878842
terrelln added a commit to terrelln/openzl that referenced this pull request Jun 29, 2026
Summary:

Introduces the architecture-specific kernel interface for the Huffman Pivoted codec along with a portable, correctness-oriented generic implementation and the kernel test suite.

The `ZL_HuffmanPivotedEncode` and `ZL_HuffmanPivotedDecode` structs provide the interface to cleanly swap between implementations based on the CPU. The `select()` function will pick the best implementation based on the current CPU, when they are added, but for now just returns the generic implementation.

These are the kernels defined in the [PivCo Huffman paper](https://arxiv.org/pdf/2606.05765). The only difference is the encode side is modified following the same strategy as the [upstream repo](https://github.com/MarcinZukowski/pivco-huffman) to operate on `uint8_t rank` values, rather than `uint16_t codeword` values. The reasoning for how that change work is explained in the next diff, but the benefit is working on `uint8_t` instead of `uint16_t`.

Note that some buffers require `SLOP` bytes at the end, and `partitionFull` has an odd aliasing requirement. These are constraints that are imposed by the full implementation in the next diff.

Differential Revision: D109878842
@terrelln terrelln closed this Jun 29, 2026
@terrelln terrelln reopened this Jun 30, 2026
terrelln added 4 commits June 30, 2026 14:09
Summary:

As title

Reviewed By: daniellerozenblit

Differential Revision: D109877947
Summary:

Adds byte-aligned bit reservation and pop primitives to the FF bitstream, needed by the upcoming PivCo-Huffman kernels:

- `ZS_BitCStreamFF_reserveAlignedBits` / `ZS_BitCStreamFF_commitReservedBits` on the write side.
- `ZS_BitDStreamFF_popAlignedBits` on the read side, plus a `begin` cursor in `ZS_BitDStreamFF` so the reader can compute byte offsets.
- `ZS_BitDStreamFF_finish` now returns the number of bytes consumed.
- Hardens `ZS_BitCStreamFF_init`/`_finish`/`_flush` against small buffers by avoiding pointer arithmetic that could underflow.

Differential Revision: D109878843
Summary:

Introduces the architecture-specific kernel interface for the PivCo-Huffman codec along with a portable, correctness-oriented generic implementation and the kernel test suite.

The `ZL_PivCoHuffmanEncode` and `ZL_PivCoHuffmanDecode` structs provide the interface to cleanly swap between implementations based on the CPU. The `select()` function will pick the best implementation based on the current CPU, when they are added, but for now just returns the generic implementation.

These are the kernels defined in the [PivCo Huffman paper](https://arxiv.org/pdf/2606.05765). The only difference is the encode side is modified following the same strategy as the [upstream repo](https://github.com/MarcinZukowski/pivco-huffman) to operate on `uint8_t rank` values, rather than `uint16_t codeword` values. The reasoning for how that change work is explained in the next diff, but the benefit is working on `uint8_t` instead of `uint16_t`.

Note that some buffers require `SLOP` bytes at the end, and `partitionFull` has an odd aliasing requirement. These are constraints that are imposed by the full implementation in the next diff.

Differential Revision: D109878842
@terrelln terrelln force-pushed the export-D109878842 branch from 61faf22 to 4297c51 Compare June 30, 2026 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

1 participant