|
FZGPUModules 2.0
GPU-accelerated modular compression pipelines
|
#include <ginterp_stage.h>
Inheritance diagram for fz::GInterpStage< TInput, TCode >:Public Member Functions | |
| void | execute (cudaStream_t stream, MemoryPool *pool, const std::vector< void * > &inputs, const std::vector< void * > &outputs, const std::vector< size_t > &sizes) override |
| void | postStreamSync (cudaStream_t stream) override |
| void | onFinalize (size_t estimated_inlen, MemoryPool *pool) override |
| size_t | estimateDeviceFootprintBytes (size_t) const override |
| size_t | estimatePinnedFootprintBytes (size_t) const override |
| std::string | getName () const override |
| std::vector< std::string > | getOutputNames () const override |
| std::vector< size_t > | estimateOutputSizes (const std::vector< size_t > &input_sizes) const override |
| std::unordered_map< std::string, size_t > | getActualOutputSizesByName () const override |
| size_t | getActualOutputSize (int index) const override |
| void | saveState () override |
| void | setErrorBoundMode (ErrorBoundMode m) |
| void | setAutoTuning (uint8_t mode) |
| void | setManualAlphaBeta (double alpha, double beta) |
| void | setDims (const std::array< size_t, 3 > &dims) override |
| void | setInverse (bool inv) override |
| int | ndim () const |
| uint16_t | getStageTypeId () const override |
| uint8_t | getOutputDataType (size_t output_index) const override |
| uint8_t | getInputDataType (size_t) const override |
| size_t | serializeHeader (size_t output_index, uint8_t *buf, size_t max_size) const override |
| void | deserializeHeader (const uint8_t *buf, size_t size) override |
| size_t | getMaxHeaderSize (size_t) const override |
| bool | isGraphCompatible () const override |
Public Member Functions inherited from fz::Stage | |
| virtual size_t | getRequiredInputAlignment () const |
| int | getOutputIndex (const std::string &name) const |
| virtual size_t | estimateScratchBytes (const std::vector< size_t > &input_sizes) const |
G-Interp predictor with error-bounded quantization (3-D, MVP).
THIRD_PARTY.md.Forward outputs (compression):
TCode, full N elements)TInput, ~N/4096 elements)TInput)uint32_t)The outlier count is not a DAG output port — it lives in a stage-private 4-byte device scratch (allocated via pool->allocatePersistentDevice in onFinalize()), is D2H'd in postStreamSync(), and is serialized in the FZM header. The inverse path consumes it as a uint32_t kernel-launch argument (read from the deserialized header), so the inverse kernel never has to dereference a device pointer to know its loop bound.
Inverse: takes the four forward outputs, produces the reconstructed TInput volume.
The error bound eb is a target, not a hard guarantee. The multi-level interpolation tree predicts finer-level values from already-lossy coarser- level reconstructions, so prediction errors accumulate across the four levels. In practice the maximum element-wise error is:
<= 1.1 * eb on smooth data~2 * eb on data with many outliers (large spikes that the spline can't predict — these are stored exactly via the outlier triplet, but their neighbours still see compounded interpolation error).setErrorBoundMode() accepts ABS, REL, and NOA, but — like LorenzoQuantStage and unlike QuantizerStage — this stage resolves all modes to a single absolute bound before quantizing:
abs_eb = eb directly.abs_eb = eb * max(|data|) (one min/max scan, then treated as ABS). This is not the exact per-element PFPL relative bound |error| / |x| <= eb.abs_eb = eb * (max(data) - min(data)).The interpolation tree predicts each element against a fixed absolute tolerance, so a per-element varying bound cannot be threaded through it. For an exact point-wise relative bound use QuantizerStage with ErrorBoundMode::REL (log-space encoding); see quantizer.h.
Other limitations to be aware of:
setDims() throws for 1-D input.dim is a multiple of 16 (the 3-D anchor tile size). 2-D path: anchor tile is 32×8, so best results when dim_x is a multiple of 32 and dim_y of 8. Ragged dims still work but edge elements see slightly worse prediction.INTERPOLATION_PARAMS auto-tuning (setAutoTuning(1) / (3)) is wired for the 3-D path only. In 2-D the stage logs a warning and falls back to the deterministic baseline (alpha=1.75, beta=4.0, use_md={t,t,f,f,f,f}). 2-D auto-tune (cuSZ-Hi auto_tuning_mode == 2) is a follow-up.Both float and double inputs are supported, and both run the exact same encode/decode kernels — c_spline_infprecis_data / x_spline_infprecis_data are single templates parameterised on the data type, so there is no separate "float path" and "double path".
Those two kernels stage two working tiles (data + ectrl) in dynamic shared memory (extern __shared__, sized by the launcher) rather than static __shared__. This is unconditional — it is not a double-only branch:
(16+1)³ = 4913 elements × 2 buffers. In double that is ~77 KB, over the 48 KB static __shared__ cap, which is why dynamic shared memory is used. float is ~38.5 KB — comfortably under the cap, but it goes through the same dynamic-shmem code path.ginterpRaiseSmemIfNeeded) only calls cudaFuncSetAttribute(..., cudaFuncAttributeMaxDynamicSharedMemorySize, …) when the tile exceeds 48 KB. So in practice the opt-in fires only for the 3-D double path; float (and all 2-D) use the default dynamic region and never touch the attribute.float is expected to be negligible: the requested shared-memory size, occupancy, and in-kernel access pattern are unchanged versus the previous static-__shared__ version; only the tile base address is now a launch-time value.double path therefore needs a GPU whose opt-in max dynamic shared memory is ≥ ~77 KB (Volta and newer). On older GPUs capped at 48 KB the cudaFuncSetAttribute call fails and the launch surfaces the error; 2-D double and all float configs are unaffected.float-only**; double inputs with a profiling mode set fall back to the deterministic baseline with a warning (mode 5 manual alpha/beta is still honored for double).setQuantRadius(0) (the default) means "auto": on first execute(), the stage scans the input min/max and picks the largest radius that fits the data range, capped at the TCode bit-width's maximum. This minimises outlier count for unknown data ranges and is the recommended setting.
For CUDA graph capture or strict determinism, set the radius explicitly to any positive value to skip the scan (e.g. setQuantRadius(512) for climate-style data where the user wants extremes routed to the outlier triplet for downstream handling).
| TInput | Floating-point input type (float or double). Both use the same dynamic-shared-memory kernels; see "Precision and shared
memory" above. The 3-D double path needs a GPU whose opt-in max dynamic shared memory is ≥ ~77 KB (Volta+). |
| TCode | Quantization code type (uint8_t, uint16_t, or uint32_t). |
|
overridevirtual |
Execute the stage. Inputs, outputs, and sizes are device pointers/bytes.
Stages may call cudaStreamSynchronize(stream) or issue blocking D2H copies when the algorithm requires it (e.g. Huffman histogram readback for codebook construction, ANS renormalization tables). Such stages must return false from isGraphCompatible() and must document the sync points.
Note: the DAG dispatches sibling nodes (same topological level) via a sequential CPU loop, each enqueuing to its own stream. A sync inside execute() blocks the CPU from dispatching subsequent siblings until the synced stream is idle — this delays parallel branches in wide DAGs. In a linear pipeline there are no siblings and no extra cost.
Implements fz::Stage.
|
overridevirtual |
|
overridevirtual |
In PREALLOCATE mode + auto-tuning > 0, pre-allocate the persistent profiling-errors scratch (36 floats device + pinned host) via the pool's persistent allocators so they aren't on the per-call stream-ordered path. In MINIMAL mode this is deferred to first execute(). Auto-tune off is a no-op.
Reimplemented from fz::Stage.
|
inlineoverridevirtual |
Estimated persistent device memory this stage allocates outside the pool (via pool->allocatePersistentDevice). Used for total footprint reporting. Default: 0.
Reimplemented from fz::Stage.
|
inlineoverridevirtual |
Estimated persistent pinned-host memory this stage allocates outside the pool (via pool->allocatePersistentPinned). Used for total footprint reporting. Default: 0.
Reimplemented from fz::Stage.
|
inlineoverridevirtual |
Human-readable name used in error messages and debug output.
Implements fz::Stage.
|
inlineoverridevirtual |
Output port names in order. Default: single port named "output". Multi-output stages (e.g. Lorenzo: "codes", "outliers") override this.
Reimplemented from fz::Stage.
|
overridevirtual |
Estimate output buffer sizes given input sizes. Used for buffer allocation planning in PREALLOCATE mode — must be a safe upper bound; under-estimation causes buffer overruns.
Implements fz::Stage.
|
inlineoverridevirtual |
|
inlineoverridevirtual |
Actual size of a single output by index after execute(). Avoids constructing the map for the common single-output case. Default delegates to getActualOutputSizesByName(); override to return directly from an internal field.
Reimplemented from fz::Stage.
|
inlineoverridevirtual |
Save/restore config state around a decompression pass. deserializeHeader() overwrites the stage's forward-pass config; saveState() is called before and restoreState() after so the stage returns to its original configuration.
Reimplemented from fz::Stage.
|
inline |
REL here is global-approximate (abs_eb = eb * max(|data|)), NOT the exact per-element PFPL bound — use QuantizerStage REL for that. See the "Error-bound modes" section in the class doc.
|
inline |
Enable cuSZ-Hi's INTERPOLATION_PARAMS auto-tuning. See Config::auto_tuning_mode for mode semantics. Default is 0 (off). Profiling modes (1/3/4) disable CUDA graph capture for this stage; mode 5 (manual override) is graph-safe.
|
inline |
Set the manual alpha/beta override pair used when auto_tuning_mode == 5. Both must be > 0 to take effect; passing 0 for either field defers to the cuSZ-Hi piecewise-linear schedule (alpha from rel_eb) or the upstream default (beta = 4.0).
|
overridevirtual |
Called once by Pipeline::finalize() so stages can react to the dataset dimensions set via Pipeline::setDims() after construction.
| dims | {x, y, z} extents (z==1 → 2-D; y==z==1 → 1-D) |
Reimplemented from fz::Stage.
|
inlineoverridevirtual |
Switch between forward (compression) and inverse (decompression) mode. Affects getNumInputs()/getNumOutputs() for stages with asymmetric port counts.
Reimplemented from fz::Stage.
|
inline |
Returns the effective spatial dimensionality (2 or 3). 1-D inputs are rejected by setDims() so this method never returns 1 once the stage has been configured.
|
inlineoverridevirtual |
|
inlineoverridevirtual |
DataType enum of the given output port.
Implements fz::Stage.
|
inlineoverridevirtual |
Expected DataType of the given input port.
Used by Pipeline::finalize() to detect type mismatches between connected stages before any execution. Return DataType::UNKNOWN to opt out of checking — byte-transparent stages (Bitshuffle, RZE, RRE) and mock stages must return UNKNOWN; finalize() skips any connection where either side is UNKNOWN.
Reimplemented from fz::Stage.
|
overridevirtual |
Serialize stage config into header_buffer (max 128 bytes) for the FZM file. Return the number of bytes written, or 0 if the stage has no config.
Reimplemented from fz::Stage.
|
overridevirtual |
Restore stage config from header_buffer during decompression.
Reimplemented from fz::Stage.
|
inlineoverridevirtual |
Maximum bytes this stage writes into its per-output FZM header slot.
Reimplemented from fz::Stage.
|
inlineoverridevirtual |
Graph-compatible iff execute() does no host-blocking work. Four scans inside execute() can break capture, each conditional:
computeValueBase() (D2H min/max scan) — runs for REL/NOA when precomputed_value_base <= 0. Caller must setValueBase(...) to skip this.quant_radius == 0. Caller must setQuantRadius(...) to a positive value to skip.cudaStreamSynchronize of the error array. Only modes 0 (baseline) and 5 (manual α/β override) skip the profile entirely.manual_alpha <= 0 still computes rel_eb to pick α from the piecewise-linear schedule, which (for ABS) goes through the same min/max scan. Caller must setManualAlphaBeta(α>0, β) to skip that. (Mode 0 never touches rel_eb.) postStreamSync() runs outside the captured region (same pattern as LorenzoQuantStage) so the outlier-count D2H doesn't gate this. Reimplemented from fz::Stage.