Skip to content

Pfpl 4gib fields - #8

Open
Seth-Wolfgang wants to merge 9 commits into
szcompressor:mainfrom
Seth-Wolfgang:pfpl-4gib-fields
Open

Seth-Wolfgang wants to merge 9 commits into
szcompressor:mainfrom
Seth-Wolfgang:pfpl-4gib-fields

Conversation

@Seth-Wolfgang

Copy link
Copy Markdown

Title: fz::pfpl: the GPU coder takes fields of 4 GiB and more

Branch pfpl-4gib-fields (1002dcd), one commit on the fork's main (74855a4, the head of #7).

What

fz::pfpl::compress()/decompress() used to refuse every field of 4 GiB or more. The check was a worst case: even an
all-raw stream had to fit the LC archive's 32-bit sizes. The GPU kernels only need 32-bit element counts, so the GPU
coder now checks that limit instead: under 2^32 elements in whole chunks (fitsKernels).

Relaxing that check alone would let a stream that does reach 4 GiB corrupt itself silently. Its 32-bit look-back
offsets would wrap, later chunks would land on earlier bytes, and the stream would report a wrapped length that looks
like it fits. The rest of the change stops that:

  • Look-back offsets saturate at 0xffffffff instead of wrapping.
  • A stream that would reach 4 GiB records 0xfffffffc archive bytes in its header, and compress() reports
    SIZE_MAX through d_stream_bytes. streamBytes() reads that header as SIZE_MAX, so the stream fits no buffer.
  • compress() clamps the capacity to what a header can record, so nothing is written past that length.

The LC field-size word of such a field holds its size modulo 2^32, which the decoder already compares the same way.
compressHost()/decompressHost() keep the 4 GiB field limit. Documentation is in pfpl_stream.h and the changelog.

Testing

  • AMD MI250X (Frontier, ROCm 7.1.1, one GCD): test_pfpl_stream ran on the AMD kernels and on the generic harness
    kernels. 489 of 490 passed in each set. The one failure was PD8's input: uniform noise at 1e-12 coded to 3.3 GiB,
    under the 4 GiB it tests. PD8 now uses random 64-bit patterns, and PD7 and PD8 pass on both kernel sets. The
    library source did not change between the two runs; only the test did.
  • Consumer: QCLAB++ with 8 GiB tiles. A 36-qubit Hadamard state matches its closed form exactly
    (--verify-analytic), GHZ and BV run at 36 qubits, and GHZ and BV run at 59 qubits on 256 nodes.
  • NVIDIA: pfpl_stream.cu and test_pfpl_stream.cpp compile with nvcc 13.1 for sm_80. They have not run on an
    NVIDIA GPU yet.

New tests:

  • PD7, PfplStream64.FieldOf8GiBRoundTrips: an 8 GiB field (2^30 doubles) round-trips within the bound, its LC
    field-size word is 0 (2^33 modulo 2^32), and the host coder refuses it. Skipped without about 20 GiB of free device
    memory.
  • PD8, PfplStream64.StreamOf4GiBOrMoreNeverFits: a 5 GiB stream that would pass 4 GiB fits no capacity
    (SIZE_MAX from the kernel and from the header), and nothing is written past the length a header can record.
    Skipped without about 10 GiB.

Seth-Wolfgang and others added 9 commits November 4, 2026 14:27
Work in progress, on a branch for testing.

- fz::pfpl (modules/fused/chunk_fusion/pfpl_stream.{h,cu}): compress a float field from one device buffer into another and
  back, in one kernel each, ordered on a stream with no host synchronization. The archive is byte-identical to the PFPL preset's
  in ABS mode.
- AMD wave64 kernels for it (pfpl_stream_amd.inl), used on HIP. CUDA uses the generic chunk harness.
- include/backend/fp.h: fmulRounded(). On HIP, clang fused the bound check's multiply into its subtraction, so the check tested
  the exact product and passed values that decode up to half an ulp past the bound.
- backend/warp.h whole-wavefront primitives, chunk_fusion.cuh on the backend wrappers, and no NVRTC fusion on HIP.

Tested on MI250X with the HIP backend on development only. main configures for CUDA alone, so this branch has not been built yet.
Still missing for a PR: CHANGELOG entries, an in-tree test, a CN-* note, and removing two device-side printf calls.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
-DFZGMOD_BACKEND=HIP configures and builds again. The root CMakeLists.txt,
presets and package config take their HIP hunks from development, without its
profiling target, which main does not have. Module and test CMake files already
branch on the backend.

NVRTC specialization is not built on HIP, so every stage runs staged. Four tests
need it or include cuda_runtime.h directly, so they are CUDA-only.

On one MI250X GCD, 50 of 53 tests pass. test_huffman, test_log_transform and
test_stage_registry fail on HIP, and they are not changed here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Plan::reserve cleared its ticket counter and look-back state with a stream-less
cudaMemset, which is not ordered with a non-blocking stream's kernels. The first
encode could read old page contents as its ticket, compute a wild chunk id and
stop with a memory aperture violation. The clears now run on the calling stream,
ahead of that call's kernel. See CN-PFPLSTREAM-2.

tests/stages/test_pfpl_stream.cpp compares fz::pfpl with the staged pipeline. On
HIP, CTest runs it with the AMD kernels and with the generic harness kernels. The
device-side printf in the decode error paths is gone, and the measurements moved
from code comments to CN-PFPLSTREAM-1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fzgmod_modules calls fz::MemoryPool but never declared the dependency, so
libfzgmod_modules.so had no DT_NEEDED entry for libfzgmod_mem.so. A consumer
that links the library without calling fzgmod_mem itself failed with undefined
references on toolchains that default to --as-needed, such as Ubuntu's GCC.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CN-PFPLSTREAM-3 has the 64-bit chain, the radius, how the float-sized header
records the bound, and the throughput on one MI250X GCD.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
compressHost and decompressHost read and write the same stream as the kernels,
byte for byte, in plain C++, with no device, Plan or GPU. A caller off the GPU
path no longer has to stage a stream through the device: in QCLAB++ that ran out
of memory reading back double tiles of 512 MiB, and a rank with no GPU could not
code at all.

PfplHostCase holds them to the kernels on both kernel sets, both types and every
size class, including a hostile field for conversions out of range. compress()
and compressHost() now share their checks and quantizer parameters through
quantParams(). See CN-PFPLSTREAM-4.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CN-PFPLSTREAM-4 named the caller it came from. Say what any caller needs, and
call the measured data a field, as the rest of the library does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
compress()/decompress() refused any field of 4 GiB or more, because even its
all-raw stream could pass the LC archive's 32-bit sizes. A field that size
usually codes to far less (an 8 GiB state-vector tile to a few MB). The
kernels themselves only need 32-bit element counts, so the GPU coder now
checks that (fitsKernels: under 2^32 elements in whole chunks) and checks the
stream's own length while writing it:

- Look-back offsets saturate at 0xffffffff instead of wrapping, so a chunk
  past 4 GiB is never written over earlier bytes.
- A stream that would reach 4 GiB records 0xfffffffc archive bytes in its
  header. compress() reports SIZE_MAX through d_stream_bytes, and
  streamBytes() reads the header the same way, so the stream fits no buffer.
  The capacity is clamped to what a header can record.

The LC field-size word of such a field holds its size modulo 2^32, which the
decoder already compares the same way. compressHost()/decompressHost() keep
the 4 GiB field limit.

Tests: PD7 (an 8 GiB field round-trips; the host coder refuses it) and PD8
(a stream that would pass 4 GiB fits no capacity, and nothing is written past
the length a header can record).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant