FZGPUModules 2.0
GPU-accelerated modular compression pipelines
Loading...
Searching...
No Matches
fzm_format.h
Go to the documentation of this file.
1#pragma once
2
20#include <cstdint>
21#include <cstring>
22#include <stdexcept>
23#include <string>
24
25namespace fz {
26
28constexpr uint32_t FZM_MAGIC = 0x464D5A32;
29
40constexpr uint8_t FZM_VERSION_MAJOR = 3;
41constexpr uint8_t FZM_VERSION_MINOR = 1;
42constexpr uint16_t FZM_VERSION = (static_cast<uint16_t>(FZM_VERSION_MAJOR) << 8)
43 | static_cast<uint16_t>(FZM_VERSION_MINOR);
44
46constexpr size_t FZM_LEGACY_HEADER_CORE_SIZE = 72;
47
48constexpr uint16_t FZM_FLAG_HAS_DATA_CHECKSUM = 0x0001u;
49constexpr uint16_t FZM_FLAG_HAS_HEADER_CHECKSUM = 0x0002u;
50
55constexpr uint8_t fzmVersionMajor(uint16_t v) {
56 return (v <= 0xFF) ? static_cast<uint8_t>(v) : static_cast<uint8_t>(v >> 8);
57}
59constexpr uint8_t fzmVersionMinor(uint16_t v) {
60 return (v <= 0xFF) ? 0u : static_cast<uint8_t>(v & 0xFF);
61}
62
63constexpr size_t FZM_MAX_BUFFERS = 32;
64constexpr size_t FZM_MAX_NAME_LEN = 64;
65constexpr size_t FZM_STAGE_CONFIG_SIZE = 128;
66constexpr size_t FZM_MAX_SOURCES = 4;
67
78constexpr uint16_t FZM_STAGE_FLAG_PRIMARY_SOURCE = 0x1;
79
80// ─────────────────────────────────────────────────────────────────────────────
81
88enum class StageType : uint16_t {
89 UNKNOWN = 0,
90 LORENZO_QUANT = 1,
91 DIFFERENCE = 2,
92 SCALE = 3,
93 PASSTHROUGH= 4,
94 RLE = 5,
95 HUFFMAN = 6,
96 BITPACK = 7,
97 SPLIT = 10,
98 MERGE = 11,
99 LORENZO = 12,
100 QUANTIZER = 14,
101 ZIGZAG = 15,
102 NEGABINARY = 16,
103 BITSHUFFLE = 17,
104 RZE = 18,
105 ANS = 20,
106 ADM = 19,
107 G_INTERP = 22,
108 BITPLANE_RZE = 23,
109 ADAPTIVE_BITPACK = 24,
110 TILED_LORENZO = 25,
111 RRE = 26,
112 RARE = 27,
113 RAZE = 28,
114 CLOG = 29,
115 HCLOG = 30,
116 TUPL = 31,
117 GPULZ = 32,
118 LOG_TRANSFORM = 33,
119 ADAPTIVE_LORENZO = 34,
120 ROIBIN_SPLIT = 35,
121 SZX = 36,
122 SZP = 37,
123 // 38 (TEE, SPERR-branch-only) never shipped on main -- bindExternalInput()
124 // replaced the fan-out/duplicate-copy stage it would have been for before
125 // this branch merged. Not reused -- a future stage type reading an old
126 // archive that used it should fail loudly, not silently collide.
127 CDF97 = 39,
128 SPECK2D = 40,
130};
131
139enum class DataType : uint8_t {
140 UINT8 = 0,
141 UINT16 = 1,
142 UINT32 = 2,
143 UINT64 = 3,
144 INT8 = 4,
145 INT16 = 5,
146 INT32 = 6,
147 INT64 = 7,
148 FLOAT32 = 8,
149 FLOAT64 = 9,
150 UNKNOWN = 0xFF,
151};
152
153// ─────────────────────────────────────────────────────────────────────────────
154
155constexpr size_t FZM_MAX_STAGE_INPUTS = 8;
156constexpr size_t FZM_MAX_STAGE_OUTPUTS = 8;
157
169 uint16_t stage_version;
170 uint8_t num_inputs;
171 uint8_t num_outputs;
172 uint16_t stage_flags;
173
174 uint16_t input_buffer_ids[FZM_MAX_STAGE_INPUTS];
175 uint16_t output_buffer_ids[FZM_MAX_STAGE_OUTPUTS];
176
178 uint32_t config_size;
179
180 uint8_t reserved2[84];
181 // Total: 2+2+1+1+2+16+16+128+4+84 = 256 bytes
182
183 FZMStageInfo() {
184 // Zero the WHOLE object, not just the named arrays. This struct is
185 // written to disk verbatim, and the compiler's implicit tail padding
186 // (fields end at 254, sizeof is 256) is not covered by the member-wise
187 // initialization below — so an .fzm archive carried a few bytes of stack
188 // garbage and was not byte-reproducible across runs. See FZMBufferEntry.
189 std::memset(this, 0, sizeof(*this));
190 stage_type = StageType::UNKNOWN;
191 stage_version = 0;
192 num_inputs = 0;
193 num_outputs = 0;
194 stage_flags = 0;
195 memset(input_buffer_ids, 0xFF, sizeof(input_buffer_ids));
196 memset(output_buffer_ids, 0xFF, sizeof(output_buffer_ids));
198 config_size = 0;
199 memset(reserved2, 0, 84);
200 }
201};
202static_assert(sizeof(FZMStageInfo) == 256, "FZMStageInfo must be 256 bytes");
203
214 uint16_t stage_version;
217 uint16_t dag_buffer_id;
219
220 uint64_t data_size;
221 uint64_t allocated_size;
223 uint64_t byte_offset;
224
226 uint32_t config_size;
227
228 uint8_t reserved2[14];
229
231 // Zero the WHOLE object before setting fields. The named members end at
232 // byte 250 but sizeof(FZMBufferEntry) is 256 (8-byte alignment), and
233 // those 6 padding bytes are written straight to disk with the rest of
234 // the struct. Left uninitialized they made compression non-deterministic:
235 // two runs over CESM-2D/CLDHGH through gpu_zstd_lossless.toml produced
236 // archives differing in exactly 12 bytes — 2 padding bytes in each of the
237 // 4 buffer entries, plus the 4-byte header_checksum computed over them.
238 // Round-trip was unaffected (the padding is never read back), which is
239 // why it survived; but it breaks byte-for-byte reproducibility, and
240 // benchkit records compressed_sha256 per row and compares baselines
241 // across machines on exactly that.
242 std::memset(this, 0, sizeof(*this));
243 stage_type = StageType::UNKNOWN;
244 stage_version = 0;
245 data_type = DataType::UINT8;
247 dag_buffer_id = 0xFFFF;
248 memset(name, 0, FZM_MAX_NAME_LEN);
249 data_size = 0;
250 allocated_size = 0;
252 byte_offset = 0;
254 config_size = 0;
255 memset(reserved2, 0, 14);
256 }
257};
258static_assert(sizeof(FZMBufferEntry) == 256, "FZMBufferEntry must be 256 bytes");
259
273 uint32_t magic;
274 uint16_t version;
275 uint16_t num_buffers;
276
279 uint64_t header_size;
280
281 uint32_t num_stages;
282 uint16_t num_sources;
283 uint16_t flags;
284
291
292 uint32_t data_checksum;
294
295 FZMHeaderCore() {
297 version = FZM_VERSION;
298 num_buffers = 0;
300 compressed_size = 0;
301 header_size = sizeof(FZMHeaderCore);
302 num_stages = 0;
303 num_sources = 0;
304 flags = 0;
306 data_checksum = 0;
307 header_checksum = 0;
308 }
309
311 uint64_t computeHeaderSize() const {
312 return sizeof(FZMHeaderCore)
313 + num_stages * sizeof(FZMStageInfo)
314 + num_buffers * sizeof(FZMBufferEntry);
315 }
316};
317static_assert(sizeof(FZMHeaderCore) == 80, "FZMHeaderCore must be 80 bytes");
318
319// ─────────────────────────────────────────────────────────────────────────────
320// Helper functions
321// ─────────────────────────────────────────────────────────────────────────────
322
324inline size_t getDataTypeSize(DataType type) {
325 switch (type) {
326 case DataType::UINT8: case DataType::INT8: return 1;
327 case DataType::UINT16: case DataType::INT16: return 2;
328 case DataType::UINT32: case DataType::INT32: case DataType::FLOAT32: return 4;
329 case DataType::UINT64: case DataType::INT64: case DataType::FLOAT64: return 8;
330 default: throw std::runtime_error("Unknown data type");
331 }
332}
333
335inline std::string dataTypeToString(DataType type) {
336 switch (type) {
337 case DataType::UINT8: return "uint8";
338 case DataType::UINT16: return "uint16";
339 case DataType::UINT32: return "uint32";
340 case DataType::UINT64: return "uint64";
341 case DataType::INT8: return "int8";
342 case DataType::INT16: return "int16";
343 case DataType::INT32: return "int32";
344 case DataType::INT64: return "int64";
345 case DataType::FLOAT32: return "float32";
346 case DataType::FLOAT64: return "float64";
347 default: return "unknown";
348 }
349}
350
352inline std::string stageTypeToString(StageType type) {
353 switch (type) {
354 case StageType::LORENZO_QUANT: return "LorenzoQuant";
355 case StageType::DIFFERENCE: return "Difference";
356 case StageType::SCALE: return "Scale";
357 case StageType::PASSTHROUGH: return "PassThrough";
358 case StageType::RLE: return "RLE";
359 case StageType::HUFFMAN: return "Huffman";
360 case StageType::BITPACK: return "BitPack";
361 case StageType::SPLIT: return "Split";
362 case StageType::MERGE: return "Merge";
363 case StageType::ROIBIN_SPLIT: return "ROIBinSplit";
364 case StageType::SZX: return "SZx";
365 case StageType::SZP: return "SZp";
366 case StageType::QUANTIZER: return "Quantizer";
367 case StageType::ZIGZAG: return "Zigzag";
368 case StageType::NEGABINARY: return "Negabinary";
369 case StageType::BITSHUFFLE: return "Bitshuffle";
370 case StageType::RZE: return "RZE";
371 case StageType::RRE: return "RRE";
372 case StageType::RARE: return "RARE";
373 case StageType::RAZE: return "RAZE";
374 case StageType::CLOG: return "CLOG";
375 case StageType::HCLOG: return "HCLOG";
376 case StageType::TUPL: return "TUPL";
377 case StageType::LORENZO: return "Lorenzo";
378 case StageType::ANS: return "ANS";
379 case StageType::ADM: return "ADM";
380 case StageType::G_INTERP: return "GInterp";
381 case StageType::BITPLANE_RZE: return "BitplaneRZE";
382 case StageType::ADAPTIVE_BITPACK: return "AdaptiveBitpack";
383 case StageType::TILED_LORENZO: return "TiledLorenzo";
384 case StageType::GPULZ: return "GPULZ";
385 case StageType::LOG_TRANSFORM: return "LogTransform";
386 case StageType::ADAPTIVE_LORENZO: return "AdaptiveLorenzo";
387 case StageType::CDF97: return "CDF97";
388 case StageType::SPECK2D: return "SPECK2D";
389 case StageType::CDF97_OUTLIER_CORRECT: return "Cdf97OutlierCorrect";
390 default: return "Unknown";
391 }
392}
393
394} // namespace fz
Definition dag.h:24
size_t getDataTypeSize(DataType type)
Definition fzm_format.h:324
constexpr uint8_t FZM_VERSION_MAJOR
Definition fzm_format.h:40
std::string dataTypeToString(DataType type)
Definition fzm_format.h:335
std::string stageTypeToString(StageType type)
Definition fzm_format.h:352
constexpr uint8_t fzmVersionMinor(uint16_t v)
Definition fzm_format.h:59
constexpr uint16_t FZM_STAGE_FLAG_PRIMARY_SOURCE
Definition fzm_format.h:78
constexpr size_t FZM_MAX_SOURCES
Maximum source stages per pipeline.
Definition fzm_format.h:66
constexpr size_t FZM_STAGE_CONFIG_SIZE
Per-stage serialized config slot (bytes)
Definition fzm_format.h:65
constexpr uint8_t fzmVersionMajor(uint16_t v)
Definition fzm_format.h:55
constexpr uint16_t FZM_FLAG_HAS_DATA_CHECKSUM
data_checksum field is valid
Definition fzm_format.h:48
constexpr uint32_t FZM_MAGIC
Definition fzm_format.h:28
StageType
Stage type identifiers written into the FZM header.
Definition fzm_format.h:88
@ TUPL
Tuple deinterleave (AoS -> SoA) transpose (LC framework lossless component)
@ SZP
SZp / fZ-light: quantize + 1-D Lorenzo delta + fixed-length bitpack (fused, no entropy coder)
@ ADAPTIVE_BITPACK
Per-block adaptive fixed-rate bit-plane coder (cuSZp plain mode)
@ LOG_TRANSFORM
Log-space transform for point-wise relative bounds (Liang et al., CLUSTER'18)
@ ANS
rANS entropy coder (GPU, via dietGPU)
@ SPECK2D
GPU-parallel "wavefront" SPECK-like coder (2-D), decode-parallel format.
@ GPULZ
TODO: describe this stage.
@ RRE
Repeated-word bitmap reducer with recursive bitmap compression (LC component)
@ ADM
Adaptive Data Mapping transform (MANS)
@ ROIBIN_SPLIT
Region-of-interest / binned-background split (ROIBIN-style dual-error-bound branching)
@ CLOG
Per-subchunk leading-zero compression and bit packing (LC framework component)
@ CDF97
CDF 9/7 biorthogonal wavelet transform (SPERR's DWT front-half)
@ TILED_LORENZO
Dimension-aware (tiled separable) Lorenzo predictor (cuSZp3 delta)
@ BITPLANE_RZE
Fused bitplane transpose + zero-group RZE (FZ-GPU lossless encoder)
@ RARE
Adaptive top-bit matching generalization of RRE (LC component)
@ SZX
SZx ultrafast EB compressor: per-block constant/non-constant classification + fixed-length residuals ...
@ ADAPTIVE_LORENZO
Per-tile adaptive multi-order Lorenzo + centering (FSZ prediction stage)
@ RAZE
Adaptive leading-zero-bit generalization of RZE (LC component)
@ CDF97_OUTLIER_CORRECT
Sparse outlier correction, guarantees the GPU SPERR pipeline's pointwise bound.
@ G_INTERP
Spline interpolation predictor + quantizer (cuSZ-Hi G-Interp)
@ HCLOG
CLOG bit packing with per-subchunk TCMS selection (LC framework component)
constexpr uint16_t FZM_FLAG_HAS_HEADER_CHECKSUM
header_checksum field is valid
Definition fzm_format.h:49
DataType
Element data type identifiers used in buffer and stage descriptors.
Definition fzm_format.h:139
constexpr size_t FZM_LEGACY_HEADER_CORE_SIZE
Definition fzm_format.h:46
constexpr size_t FZM_MAX_NAME_LEN
Maximum output port name length (bytes, null-terminated)
Definition fzm_format.h:64
constexpr size_t FZM_MAX_BUFFERS
Maximum pipeline output buffers per file.
Definition fzm_format.h:63
Per-buffer metadata record written into the FZM header (256 bytes).
Definition fzm_format.h:212
StageType stage_type
Producer stage type (2B)
Definition fzm_format.h:213
uint64_t data_size
Actual compressed bytes in this segment (8B)
Definition fzm_format.h:220
uint8_t producer_output_idx
Which output port of the producer (1B)
Definition fzm_format.h:216
uint64_t uncompressed_size
Bytes after fully decompressing this stage's output (8B)
Definition fzm_format.h:222
uint8_t stage_config[FZM_STAGE_CONFIG_SIZE]
Producer stage config, see Stage::serializeHeader() (128B)
Definition fzm_format.h:225
char name[FZM_MAX_NAME_LEN]
Output port name, null-terminated (64B)
Definition fzm_format.h:218
DataType data_type
Element data type in this buffer (1B)
Definition fzm_format.h:215
uint64_t allocated_size
Buffer capacity required for decompression (8B)
Definition fzm_format.h:221
uint8_t reserved2[14]
Reserved for future use (14B)
Definition fzm_format.h:228
uint32_t config_size
Valid bytes in stage_config (4B)
Definition fzm_format.h:226
uint16_t dag_buffer_id
DAG buffer ID used for inverse routing; 0xFFFF = unassigned (2B)
Definition fzm_format.h:217
uint16_t stage_version
Producer stage config version (2B)
Definition fzm_format.h:214
uint64_t byte_offset
Byte offset of this segment within the compressed payload (8B)
Definition fzm_format.h:223
Fixed-size FZM file header core (80 bytes).
Definition fzm_format.h:272
uint64_t computeHeaderSize() const
Definition fzm_format.h:311
uint16_t num_buffers
Number of FZMBufferEntry records (2B)
Definition fzm_format.h:275
uint32_t header_checksum
CRC32 of header bytes (v3.1+; 0 if flag not set) (4B)
Definition fzm_format.h:293
uint16_t flags
Feature flags: FZM_FLAG_* constants (2B)
Definition fzm_format.h:283
uint32_t data_checksum
CRC32 of compressed payload (v3.1+; 0 if flag not set) (4B)
Definition fzm_format.h:292
uint32_t num_stages
Number of FZMStageInfo records (4B)
Definition fzm_format.h:281
uint64_t compressed_size
Total compressed payload size in bytes (8B)
Definition fzm_format.h:278
uint64_t source_uncompressed_sizes[FZM_MAX_SOURCES]
(32B)
Definition fzm_format.h:290
uint16_t version
FZM_VERSION (2B)
Definition fzm_format.h:274
uint64_t uncompressed_size
Sum of all source uncompressed sizes in bytes (8B)
Definition fzm_format.h:277
uint16_t num_sources
Number of source (input) stages in the pipeline (2B)
Definition fzm_format.h:282
uint32_t magic
Must equal FZM_MAGIC (4B)
Definition fzm_format.h:273
uint64_t header_size
Total header size; compressed payload starts at this offset (8B)
Definition fzm_format.h:279
Per-stage metadata record written into the FZM header (256 bytes).
Definition fzm_format.h:167
uint8_t stage_config[FZM_STAGE_CONFIG_SIZE]
Serialized stage config, see Stage::serializeHeader() (128B)
Definition fzm_format.h:177
uint8_t num_inputs
Number of input ports (1B)
Definition fzm_format.h:170
uint8_t num_outputs
Number of output ports (1B)
Definition fzm_format.h:171
StageType stage_type
Stage type (2B)
Definition fzm_format.h:168
uint8_t reserved2[84]
Reserved for future use (84B)
Definition fzm_format.h:180
uint16_t stage_flags
FZM_STAGE_FLAG_* bits; 0 on pre-flag archives (2B, was reserved1)
Definition fzm_format.h:172
uint16_t input_buffer_ids[FZM_MAX_STAGE_INPUTS]
Input buffer indices (16B); 0xFFFF = unused.
Definition fzm_format.h:174
uint16_t stage_version
Config format version (2B)
Definition fzm_format.h:169
uint32_t config_size
Valid bytes in stage_config (4B)
Definition fzm_format.h:178
uint16_t output_buffer_ids[FZM_MAX_STAGE_OUTPUTS]
Output buffer indices (16B); 0xFFFF = unused.
Definition fzm_format.h:175