Skip to content

[GPU] GDeflate compression codec on the CPU - #127422

Merged
scanhex12 merged 12 commits into
masterfrom
gdeflate-cpu-codec
Oct 25, 2026
Merged

scanhex12 merged 12 commits into
masterfrom
gdeflate-cpu-codec

Conversation

@scanhex12

@scanhex12 scanhex12 commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

GDeflate compression codec on the CPU. ~SOTA codec for GPU decompression - highly important for our future pipeline https://docs.nvidia.com/cuda/nvcomp/gdeflate.html


Workflow [PR]
Sync PR [sync-upstream/pr/127422]

Version info

  • Merged into: 26.11.1.772-master (included in 26.11 and later)

`CODEC(GDeflate[(level)])`, behind `enable_gdeflate_codec`, levels 1..12,
default 6, method byte 0xa1. GDeflate is a variant of Deflate whose bit stream
is split into 32 interleaved sub-streams, the format that nvcomp and
DirectStorage expand on a GPU, many chunks in parallel.

A block is compressed in independent chunks of 64 KiB, each a GDeflate page,
from a multiple of 4 bytes, after the number of chunks and a descriptor of
each. Of a column of integers, `Int*`, `UInt*`, `Decimal32`, `Decimal64`,
`Date*` or `DateTime*`, a chunk is also bit-packed before it is compressed:
each integer as its difference from the least of the chunk, in as many bits as
the largest difference takes, up to 56. The smaller of the two forms is kept,
and the block says which. The format is that of the GPU codec of
#119502, so that a GPU can expand
the chunks of a column written by this codec.

The codec uses the GDeflate pages of NVIDIA's fork of libdeflate
(`contrib/gdeflate`), whose compressed pages nvcomp expands on the GPU, and
whose expansion reads what nvcomp compresses, as checked on the columns of
TPC-H `lineitem` at every level. The fork exports the same symbols as
libdeflate, so `contrib/gdeflate-cmake` builds only its GDeflate parts and
renames them.

`contrib/gdeflate` points at the upstream repository; it must be replaced with
a fork under github.com/ClickHouse before merging.
@scanhex12
scanhex12 marked this pull request as draft October 22, 2026 14:36
@scanhex12 scanhex12 changed the title GDeflate compression codec on the CPU [GPU] GDeflate compression codec on the CPU Oct 22, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ca28d67]

Summary: ✅


AI Review

Summary

This PR adds an experimental GDeflate compression codec, wires it into the factory/parser/settings/build, and documents a new 0xa1 wire-method byte. The current head is close, but I do not think it is ready to merge yet: one previously reported reserve-size overflow is still present, and the user-facing codec docs now promise numeric bit-packing that the implementation no longer provides.

PR Metadata
  • Changelog category: New Feature is correct for this PR.
  • Changelog entry: required for New Feature, but the current text is too promotional (~SOTA, "future pipeline", raw URL) instead of a concise user-facing description.
  • Exact replacement: Added experimental GDeflate compression codec with optional levels 1..12 for CPU compression and GPU-friendly decompression.
Findings

❌ Blockers

  • [src/Compression/CompressionCodecGDeflate.cpp:149] [dismissed by author -- https://github.com/[GPU] GDeflate compression codec on the CPU #127422#discussion_r4358640540] getMaxCompressedDataSize still truncates a size_t bound to UInt32. For uncompressed_size = UInt32::max(), GDeflate always splits the input into 65536 pages, so even the descriptor table plus one 64 KiB page per chunk already exceeds 4 GiB before any deflate overhead. That under-reserves the destination buffer and makes writeHeader wrap the stored block size. Suggested fix: compute the bound in UInt64 / size_t and throw CANNOT_COMPRESS when it exceeds UInt32::max(), like CompressionCodecPco::getMaxCompressedDataSize does.

⚠️ Majors

  • [src/Parsers/ParserCreateQuery.cpp:2927] The docs now promise integer chunk bit-packing, but the current CompressionCodecGDeflate implementation no longer has any type-dependent packing path and compresses raw 64 KiB chunks directly with libdeflate_gdeflate_compress. That makes the public contract of the new codec inaccurate. Suggested fix: either restore the packing path or rewrite the docs / PR wording to describe the current generic GDeflate page codec.
Final Verdict

❌ Request changes before merge: the still-open reserve-size overflow is a real correctness issue, and the new user-facing docs currently describe behavior the implementation does not provide.

@clickhouse-gh clickhouse-gh Bot added pr-feature Pull request with new product feature submodule changed At least one submodule changed in this PR. labels Oct 22, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-codecs Compression/encoding codecs (LZ4/ZSTD/etc.), archive formats (tar/zip/7z), codec selection and IO... label Oct 22, 2026
scanhex12 and others added 2 commits October 22, 2026 15:45
Values read back as they were written for each kind of column, with chunks of
integers that are packed and chunks that are not, at several levels, and in
`CODEC(Delta, GDeflate)`; an integer column takes fewer bytes than the same
bytes in a `FixedString`, which is not packed; the setting and the arguments
are checked.
The Fast test initializes only a whitelist of submodules, so the CMake
configuration failed: `clickhouse_compression` links `ch_contrib::gdeflate`,
which is not defined without the submodule. `GDeflate` is linked
unconditionally, like `ZXC`, so it is added to the list the same way.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/PRs/127422/eb67af8c4379872cf484890a65f39b55b6caca23/pr/fast_test/cmake_configuration/cmake_configuration.log
PR: #127422

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread src/Compression/CompressionInfo.h Resolved
scanhex12 and others added 3 commits October 23, 2026 09:14
The width of an integer is dispatched once per chunk to templates over the
type, as in `Delta` and `T64`, instead of a `switch` per integer in
`integerAt` and `storeInteger`, which are removed. The differences from the
least integer are taken in the unsigned type of the same width, so they need
no widening to 64 bits; unpacking does not depend on the signedness at all.

The format does not change: the reference of a chunk of signed integers is
now stored zero-extended instead of sign-extended, and the expansion adds the
differences to it modulo the width of the type, so blocks written before
read the same.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Instead of a template for each signed type, a chunk is packed as unsigned
integers of its width with the sign bit flipped where the type is signed,
which orders them as the signed type does. Flipping the sign bit adds half the
range modulo the width, so the reference, flipped back, expands to the same
integers, and the format does not change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`Header` is the number of chunks with the flag of packed descriptors and
knows where each descriptor is; `Chunk` is a descriptor with the compression
and the expansion of its chunk, plain or packed. `doCompressData` and
`doDecompressData` are loops over them. The functions of one GDeflate page are
renamed to `compressPage` and `decompressPage`. The format does not change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing ca28d675a with master 479496ca1 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

10 object files changed (+180.95 KiB total), 8 added.

Object file Master PR Δ
src/CMakeFiles/clickhouse_compression.dir/Compression/CompressionCodecGDeflate.cpp.o new 98.63 KiB +98.63 KiB
base/poco/NetSSL_OpenSSL/CMakeFiles/_poco_net_ssl.dir/src/EmbeddedCertificates.cpp.o 601.84 KiB 521.19 KiB -80.64 KiB (-13.40%)
contrib/gdeflate-cmake/CMakeFiles/_gdeflate.dir/__/gdeflate/lib/gdeflate_compress.c.o new 70.42 KiB +70.42 KiB
contrib/gdeflate-cmake/CMakeFiles/_gdeflate.dir/__/gdeflate/lib/deflate_compress.c.o new 50.44 KiB +50.44 KiB
contrib/gdeflate-cmake/CMakeFiles/_gdeflate.dir/__/gdeflate/lib/gdeflate_decompress.c.o new 17.43 KiB +17.43 KiB

719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

774 translation units recompiled, 6451 s compile time in total, 766 of them have a recent master baseline.

Translation units without a recent master baseline:

  • programs/keeper/Keeper.cpp (clickhouse-keeper): 7.4 s
Symbol sizes
Binary Symbol Master PR Δ
programs/clickhouse deflate_length_slot new 64.00 KiB +64.00 KiB
programs/clickhouse-keeper deflate_length_slot new 64.00 KiB +64.00 KiB

Job report

scanhex12 and others added 3 commits October 23, 2026 10:03
`pack`, `unpack`, `compressPage` and `decompressPage` become private methods
of `Chunk`; packing sets `bits` and `reference` of the chunk, and unpacking and
expansion read them and `compressed_size`, so `PackedChunk` is removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
scanhex12 and others added 3 commits October 23, 2026 10:46
A block is now only the number of chunks, the compressed size of each, and the
chunks, each a GDeflate page. Without packing the codec does not depend on the
column type, so it is registered without one, which also makes `updateHash`
complete: two columns of different types with `CODEC(GDeflate)` behave the
same and may share a codec in a Compact part.

Related: #127422

Co-Authored-By: Claude Opus 5.5 <[email protected]>
….codecs`

`isCompressionCodec` tells a codec declaration by a static list of family
names, which `CompressionCodecFamilyNames.ParserKnowsEveryRegisteredFamily`
checks against the factory; and `01222_system_codecs` lists every registered
codec.

PR: #127422

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mintlify

mintlify Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
ClickHouse-docs 🟢 Ready View Preview Oct 23, 2026, 11:19 AM


`GDeflate[(level)]` — [GDeflate](https://github.com/NVIDIA/libdeflate/tree/gdeflate), a variant of Deflate whose bit stream is split into 32 interleaved sub-streams, with configurable `level`. Possible levels: \[1, 12\]. Default level: 6.

A block is compressed in independent chunks of 64 KiB, each a GDeflate page, the format that nvcomp and DirectStorage expand on a GPU, many chunks in parallel. On the CPU, it compresses and decompresses about as fast as Deflate, slower than `LZ4` and `ZSTD`. For columns of integers (`Int*`, `UInt*`, `Decimal32`, `Decimal64`, `Date`, `Date32`, `DateTime`, `DateTime64`), a chunk whose values lie close together is bit-packed before it is compressed, each value as its difference from the least value of the chunk, where that makes the chunk smaller.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This paragraph still promises integer-specific bit-packing, but the current CompressionCodecGDeflate implementation no longer has any type-dependent packing path: it just splits the input into 64 KiB chunks and feeds each chunk directly to libdeflate_gdeflate_compress.

That leaves the public contract of the new codec inconsistent with the code users will actually run. Please either restore the numeric packing path or trim this description to match the current generic page codec.

@thevar1able thevar1able self-assigned this Oct 23, 2026
@scanhex12
scanhex12 added this pull request to the merge queue Oct 25, 2026
Merged via the queue into master with commit c0e5c9a Oct 25, 2026
179 checks passed
@scanhex12
scanhex12 deleted the gdeflate-cpu-codec branch October 25, 2026 18:41
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 25, 2026
@Algunenano

Copy link
Copy Markdown
Member

Please, do not ignore AI reviews. The CI is finding issues and external reviews are finding security problems

Reverting

This branch was successfully deployed

1 active deployment
staging - docs — ca28d675 Deployed Oct 23, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-codecs Compression/encoding codecs (LZ4/ZSTD/etc.), archive formats (tar/zip/7z), codec selection and IO... pr-feature Pull request with new product feature pr-synced-to-cloud The PR is synced to the cloud repo submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants