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
68// ─────────────────────────────────────────────────────────────────────────────
69
76enum class StageType : uint16_t {
77 UNKNOWN = 0,
78 LORENZO_QUANT = 1,
79 DIFFERENCE = 2,
80 SCALE = 3,
81 PASSTHROUGH= 4,
82 RLE = 5,
83 HUFFMAN = 6,
84 BITPACK = 7,
85 SPLIT = 10,
86 MERGE = 11,
87 LORENZO = 12,
88 QUANTIZER = 14,
89 ZIGZAG = 15,
90 NEGABINARY = 16,
91 BITSHUFFLE = 17,
92 RZE = 18,
93 ANS = 20,
94 ADM = 19,
95 G_INTERP = 22,
96 BITPLANE_RZE = 23,
97 ADAPTIVE_BITPACK = 24,
98 TILED_LORENZO = 25,
99 RRE = 26,
100 RARE = 27,
101 RAZE = 28,
102 CLOG = 29,
103 HCLOG = 30,
104 TUPL = 31,
105 GPULZ = 32,
106 LOG_TRANSFORM = 33,
107 ADAPTIVE_LORENZO = 34,
108};
109
117enum class DataType : uint8_t {
118 UINT8 = 0,
119 UINT16 = 1,
120 UINT32 = 2,
121 UINT64 = 3,
122 INT8 = 4,
123 INT16 = 5,
124 INT32 = 6,
125 INT64 = 7,
126 FLOAT32 = 8,
127 FLOAT64 = 9,
128 UNKNOWN = 0xFF,
129};
130
131// ─────────────────────────────────────────────────────────────────────────────
132
133constexpr size_t FZM_MAX_STAGE_INPUTS = 8;
134constexpr size_t FZM_MAX_STAGE_OUTPUTS = 8;
135
147 uint16_t stage_version;
148 uint8_t num_inputs;
149 uint8_t num_outputs;
150 uint16_t reserved1;
151
152 uint16_t input_buffer_ids[FZM_MAX_STAGE_INPUTS];
153 uint16_t output_buffer_ids[FZM_MAX_STAGE_OUTPUTS];
154
156 uint32_t config_size;
157
158 uint8_t reserved2[84];
159 // Total: 2+2+1+1+2+16+16+128+4+84 = 256 bytes
160
161 FZMStageInfo() {
162 // Zero the WHOLE object, not just the named arrays. This struct is
163 // written to disk verbatim, and the compiler's implicit tail padding
164 // (fields end at 254, sizeof is 256) is not covered by the member-wise
165 // initialization below — so an .fzm archive carried a few bytes of stack
166 // garbage and was not byte-reproducible across runs. See FZMBufferEntry.
167 std::memset(this, 0, sizeof(*this));
168 stage_type = StageType::UNKNOWN;
169 stage_version = 0;
170 num_inputs = 0;
171 num_outputs = 0;
172 reserved1 = 0;
173 memset(input_buffer_ids, 0xFF, sizeof(input_buffer_ids));
174 memset(output_buffer_ids, 0xFF, sizeof(output_buffer_ids));
176 config_size = 0;
177 memset(reserved2, 0, 84);
178 }
179};
180static_assert(sizeof(FZMStageInfo) == 256, "FZMStageInfo must be 256 bytes");
181
192 uint16_t stage_version;
195 uint16_t dag_buffer_id;
197
198 uint64_t data_size;
199 uint64_t allocated_size;
201 uint64_t byte_offset;
202
204 uint32_t config_size;
205
206 uint8_t reserved2[14];
207
209 // Zero the WHOLE object before setting fields. The named members end at
210 // byte 250 but sizeof(FZMBufferEntry) is 256 (8-byte alignment), and
211 // those 6 padding bytes are written straight to disk with the rest of
212 // the struct. Left uninitialized they made compression non-deterministic:
213 // two runs over CESM-2D/CLDHGH through gpu_zstd_lossless.toml produced
214 // archives differing in exactly 12 bytes — 2 padding bytes in each of the
215 // 4 buffer entries, plus the 4-byte header_checksum computed over them.
216 // Round-trip was unaffected (the padding is never read back), which is
217 // why it survived; but it breaks byte-for-byte reproducibility, and
218 // benchkit records compressed_sha256 per row and compares baselines
219 // across machines on exactly that.
220 std::memset(this, 0, sizeof(*this));
221 stage_type = StageType::UNKNOWN;
222 stage_version = 0;
223 data_type = DataType::UINT8;
225 dag_buffer_id = 0xFFFF;
226 memset(name, 0, FZM_MAX_NAME_LEN);
227 data_size = 0;
228 allocated_size = 0;
230 byte_offset = 0;
232 config_size = 0;
233 memset(reserved2, 0, 14);
234 }
235};
236static_assert(sizeof(FZMBufferEntry) == 256, "FZMBufferEntry must be 256 bytes");
237
251 uint32_t magic;
252 uint16_t version;
253 uint16_t num_buffers;
254
257 uint64_t header_size;
258
259 uint32_t num_stages;
260 uint16_t num_sources;
261 uint16_t flags;
262
269
270 uint32_t data_checksum;
272
273 FZMHeaderCore() {
275 version = FZM_VERSION;
276 num_buffers = 0;
278 compressed_size = 0;
279 header_size = sizeof(FZMHeaderCore);
280 num_stages = 0;
281 num_sources = 0;
282 flags = 0;
284 data_checksum = 0;
285 header_checksum = 0;
286 }
287
289 uint64_t computeHeaderSize() const {
290 return sizeof(FZMHeaderCore)
291 + num_stages * sizeof(FZMStageInfo)
292 + num_buffers * sizeof(FZMBufferEntry);
293 }
294};
295static_assert(sizeof(FZMHeaderCore) == 80, "FZMHeaderCore must be 80 bytes");
296
297// ─────────────────────────────────────────────────────────────────────────────
298// Helper functions
299// ─────────────────────────────────────────────────────────────────────────────
300
302inline size_t getDataTypeSize(DataType type) {
303 switch (type) {
304 case DataType::UINT8: case DataType::INT8: return 1;
305 case DataType::UINT16: case DataType::INT16: return 2;
306 case DataType::UINT32: case DataType::INT32: case DataType::FLOAT32: return 4;
307 case DataType::UINT64: case DataType::INT64: case DataType::FLOAT64: return 8;
308 default: throw std::runtime_error("Unknown data type");
309 }
310}
311
313inline std::string dataTypeToString(DataType type) {
314 switch (type) {
315 case DataType::UINT8: return "uint8";
316 case DataType::UINT16: return "uint16";
317 case DataType::UINT32: return "uint32";
318 case DataType::UINT64: return "uint64";
319 case DataType::INT8: return "int8";
320 case DataType::INT16: return "int16";
321 case DataType::INT32: return "int32";
322 case DataType::INT64: return "int64";
323 case DataType::FLOAT32: return "float32";
324 case DataType::FLOAT64: return "float64";
325 default: return "unknown";
326 }
327}
328
330inline std::string stageTypeToString(StageType type) {
331 switch (type) {
332 case StageType::LORENZO_QUANT: return "LorenzoQuant";
333 case StageType::DIFFERENCE: return "Difference";
334 case StageType::SCALE: return "Scale";
335 case StageType::PASSTHROUGH: return "PassThrough";
336 case StageType::RLE: return "RLE";
337 case StageType::HUFFMAN: return "Huffman";
338 case StageType::BITPACK: return "BitPack";
339 case StageType::SPLIT: return "Split";
340 case StageType::MERGE: return "Merge";
341 case StageType::QUANTIZER: return "Quantizer";
342 case StageType::ZIGZAG: return "Zigzag";
343 case StageType::NEGABINARY: return "Negabinary";
344 case StageType::BITSHUFFLE: return "Bitshuffle";
345 case StageType::RZE: return "RZE";
346 case StageType::RRE: return "RRE";
347 case StageType::RARE: return "RARE";
348 case StageType::RAZE: return "RAZE";
349 case StageType::CLOG: return "CLOG";
350 case StageType::HCLOG: return "HCLOG";
351 case StageType::TUPL: return "TUPL";
352 case StageType::LORENZO: return "Lorenzo";
353 case StageType::ANS: return "ANS";
354 case StageType::ADM: return "ADM";
355 case StageType::G_INTERP: return "GInterp";
356 case StageType::BITPLANE_RZE: return "BitplaneRZE";
357 case StageType::ADAPTIVE_BITPACK: return "AdaptiveBitpack";
358 case StageType::TILED_LORENZO: return "TiledLorenzo";
359 case StageType::GPULZ: return "GPULZ";
360 case StageType::LOG_TRANSFORM: return "LogTransform";
361 case StageType::ADAPTIVE_LORENZO: return "AdaptiveLorenzo";
362 default: return "Unknown";
363 }
364}
365
366} // namespace fz
Definition algorithms.h:48
size_t getDataTypeSize(DataType type)
Definition fzm_format.h:302
constexpr uint8_t FZM_VERSION_MAJOR
Definition fzm_format.h:40
std::string dataTypeToString(DataType type)
Definition fzm_format.h:313
std::string stageTypeToString(StageType type)
Definition fzm_format.h:330
constexpr uint8_t fzmVersionMinor(uint16_t v)
Definition fzm_format.h:59
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:76
@ TUPL
Tuple deinterleave (AoS -> SoA) transpose (LC framework lossless component)
@ 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)
@ GPULZ
TODO: describe this stage.
@ RRE
Repetition-Reduction Encoding (LC framework lossless component)
@ ADM
Adaptive Data Mapping transform (MANS)
@ CLOG
Compressed-Logarithm adaptive bit-width coding (LC framework lossless component)
@ TILED_LORENZO
Dimension-aware (tiled separable) Lorenzo predictor (cuSZp3 delta)
@ BITPLANE_RZE
Fused bitplane transpose + zero-group RZE (FZ-GPU lossless encoder)
@ RARE
Repetition-Adaptive Reduction Encoding (LC framework, auto-k generalization of RRE)
@ ADAPTIVE_LORENZO
Per-tile adaptive multi-order Lorenzo + centering (FSZ prediction stage)
@ RAZE
Zero-Adaptive Reduction Encoding (LC framework, auto-k generalization of RZE)
@ G_INTERP
Spline interpolation predictor + quantizer (cuSZ-Hi G-Interp)
@ HCLOG
Compressed-Logarithm coding with per-subchunk TCMS fallback (LC framework lossless 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:117
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:190
StageType stage_type
Producer stage type (2B)
Definition fzm_format.h:191
uint64_t data_size
Actual compressed bytes in this segment (8B)
Definition fzm_format.h:198
uint8_t producer_output_idx
Which output port of the producer (1B)
Definition fzm_format.h:194
uint64_t uncompressed_size
Bytes after fully decompressing this stage's output (8B)
Definition fzm_format.h:200
uint8_t stage_config[FZM_STAGE_CONFIG_SIZE]
Producer stage config, see Stage::serializeHeader() (128B)
Definition fzm_format.h:203
char name[FZM_MAX_NAME_LEN]
Output port name, null-terminated (64B)
Definition fzm_format.h:196
DataType data_type
Element data type in this buffer (1B)
Definition fzm_format.h:193
uint64_t allocated_size
Buffer capacity required for decompression (8B)
Definition fzm_format.h:199
uint8_t reserved2[14]
Reserved for future use (14B)
Definition fzm_format.h:206
uint32_t config_size
Valid bytes in stage_config (4B)
Definition fzm_format.h:204
uint16_t dag_buffer_id
DAG buffer ID used for inverse routing; 0xFFFF = unassigned (2B)
Definition fzm_format.h:195
uint16_t stage_version
Producer stage config version (2B)
Definition fzm_format.h:192
uint64_t byte_offset
Byte offset of this segment within the compressed payload (8B)
Definition fzm_format.h:201
Fixed-size FZM file header core (80 bytes).
Definition fzm_format.h:250
uint64_t computeHeaderSize() const
Definition fzm_format.h:289
uint16_t num_buffers
Number of FZMBufferEntry records (2B)
Definition fzm_format.h:253
uint32_t header_checksum
CRC32 of header bytes (v3.1+; 0 if flag not set) (4B)
Definition fzm_format.h:271
uint16_t flags
Feature flags: FZM_FLAG_* constants (2B)
Definition fzm_format.h:261
uint32_t data_checksum
CRC32 of compressed payload (v3.1+; 0 if flag not set) (4B)
Definition fzm_format.h:270
uint32_t num_stages
Number of FZMStageInfo records (4B)
Definition fzm_format.h:259
uint64_t compressed_size
Total compressed payload size in bytes (8B)
Definition fzm_format.h:256
uint64_t source_uncompressed_sizes[FZM_MAX_SOURCES]
(32B)
Definition fzm_format.h:268
uint16_t version
FZM_VERSION (2B)
Definition fzm_format.h:252
uint64_t uncompressed_size
Sum of all source uncompressed sizes in bytes (8B)
Definition fzm_format.h:255
uint16_t num_sources
Number of source (input) stages in the pipeline (2B)
Definition fzm_format.h:260
uint32_t magic
Must equal FZM_MAGIC (4B)
Definition fzm_format.h:251
uint64_t header_size
Total header size; compressed payload starts at this offset (8B)
Definition fzm_format.h:257
Per-stage metadata record written into the FZM header (256 bytes).
Definition fzm_format.h:145
uint8_t stage_config[FZM_STAGE_CONFIG_SIZE]
Serialized stage config, see Stage::serializeHeader() (128B)
Definition fzm_format.h:155
uint8_t num_inputs
Number of input ports (1B)
Definition fzm_format.h:148
uint8_t num_outputs
Number of output ports (1B)
Definition fzm_format.h:149
StageType stage_type
Stage type (2B)
Definition fzm_format.h:146
uint8_t reserved2[84]
Reserved for future use (84B)
Definition fzm_format.h:158
uint16_t input_buffer_ids[FZM_MAX_STAGE_INPUTS]
Input buffer indices (16B); 0xFFFF = unused.
Definition fzm_format.h:152
uint16_t stage_version
Config format version (2B)
Definition fzm_format.h:147
uint32_t config_size
Valid bytes in stage_config (4B)
Definition fzm_format.h:156
uint16_t reserved1
Padding (2B)
Definition fzm_format.h:150
uint16_t output_buffer_ids[FZM_MAX_STAGE_OUTPUTS]
Output buffer indices (16B); 0xFFFF = unused.
Definition fzm_format.h:153