C
- Headers in
core/include/geozl, the library every binding calls.
make submodules
make lib # core/build/libgeozl, with OpenZL linked in
Include geozl/geozl.h for compression, geozl/coeffs.h for coefficients and geozl/gpu.h for GPU decode. The CMake project in core/ also installs the headers and the library.
Types and errors
Most operations in geozl.h return 0 on success and a ZL_ErrorCode on failure. Calls with errCtx also write a one-line message there: GeoZL's reason, or OpenZL's error text with its reason and node when it gives them. A failed call leaves *outSize at 0 and a failed open leaves *out NULL, and src must be aligned to its samples and may be NULL only when numElts is 0. Functions with different return conventions document them in their entries below, and GPU failures use the caller's error buffer. The headers are the supported source API. Before 1.0 they may change in any release, as C API stability sets out.
typedef enum {
GEOZL_DT_U8 = 0, GEOZL_DT_U16 = 1, GEOZL_DT_U32 = 2, GEOZL_DT_U64 = 3,
GEOZL_DT_I8 = 4, GEOZL_DT_I16 = 5, GEOZL_DT_I32 = 6, GEOZL_DT_I64 = 7,
GEOZL_DT_F16 = 8, GEOZL_DT_F32 = 9, GEOZL_DT_F64 = 10
} geozl_dtype;
typedef enum {
GEOZL_NODATA_NONE = 0,
GEOZL_NODATA_NAN = 1,
GEOZL_NODATA_VALUE = 2
} geozl_nodata_mode;
A dtype argument takes a geozl_dtype code, which is part of the wire format. NaN mode applies to floating point data and value mode masks the sentinel given as bits. The geozl_2d_* calls refuse NaN mode with an integer dtype and value mode with a dtype whose width is not eltWidth.
One-shot compression
int geozl_2d_compress_c(const char *method, uint32_t width, uint32_t planes,
const char *error, int dtype, int nodataMode,
uint64_t nodataBits, const void *src,
size_t numElts, size_t eltWidth, void *dst,
size_t dstCapacity, size_t *outSize, char *errCtx,
size_t errCtxSize);
Builds the graph for a recipe and compresses src with it in one call. error is NULL or "" for lossless, or a LINEAR, LOG or SQRT recipe. nodataBits holds the sentinel's low eltWidth bytes and is read only in value mode.
int geozl_2d_frame_dsize_c(const void *frame, size_t frameSize,
size_t *outSize);
Writes the decompressed size in bytes to outSize. An empty frame succeeds with a size of 0, and an unreadable frame returns a ZL_ErrorCode with outSize set to 0.
size_t geozl_2d_compress_bound_c(size_t srcSize, size_t coeffsSize);
Returns the largest frame any compress call writes for srcSize input bytes and a coefficient blob of coeffsSize bytes, 0 without one. A dstCapacity of this size never fails for lack of room. Returns 0 when the bound overflows size_t.
int geozl_2d_decompress_c(const void *frame, size_t frameSize, void *dst,
size_t dstCapacity, size_t *outSize, int verify,
char *errCtx, size_t errCtxSize);
Decompresses a frame into dst, which must be aligned to the frame's element width; 8 bytes always suffices. The frame header does not record that width, so the call cannot check it. verify set to 0 skips checksum verification.
int geozl_2d_bench_c(const char *method, uint32_t width, uint32_t planes,
const char *error, int dtype, int nodataMode,
uint64_t nodataBits, const void *src, size_t numElts,
size_t eltWidth, size_t reps, int checksum, int verify,
size_t *compSize, double *encSec, double *decSec,
char *errCtx, size_t errCtxSize);
Times reps round trips of one recipe and reports the frame size and the fastest encode and decode, in seconds. checksum controls the frame checksums and verify their check during decode.
int geozl_2d_grid_c(const char *prior, size_t eltWidth, char *names,
size_t stride, size_t maxNames, size_t *outCount);
Writes the recipe names profile sweeps, one per stride-byte slot, for the sample width. prior is a prior as in profile, with NULL or "" for all predictors. A slot of GEOZL_2D_NAME_MAX (48) bytes holds any name. Returns -1 for an unknown prior, and for a stride below GEOZL_2D_NAME_MAX or NULL names when maxNames is nonzero.
Graphs
typedef struct geozl_2d_graph_s geozl_2d_graph;
int geozl_2d_graph_open_c(geozl_2d_graph **out, const char *method,
uint32_t width, uint32_t planes,
const char *error, int dtype, int nodataMode,
uint64_t nodataBits, const void *src,
size_t numElts, size_t eltWidth, char *errCtx,
size_t errCtxSize);
Opens a reusable graph, the C side of geozl.graph. src fixes the lossy grid, and a later tile the grid cannot hold to its bound is refused before compression, as compress describes. A graph serves one call at a time, and distinct graphs are independent.
int geozl_2d_compress_graph_c(geozl_2d_graph *g, const void *src,
size_t numElts, void *dst, size_t dstCapacity,
size_t *outSize, char *errCtx,
size_t errCtxSize);
int geozl_2d_compress_coeffs_c(geozl_2d_graph *g, const void *src,
size_t numElts, const void *coeffs,
size_t coeffsSize, void *dst,
size_t dstCapacity, size_t *outSize,
char *errCtx, size_t errCtxSize);
Compress one tile with an open graph, which supplies the sample width. The second attaches a blob from geozl_coeffs_pack to this frame only. NULL and 0 write a frame without one. A declared sentinel is left out of the domain check. A predictor that reads rows refuses a tile longer than one row that is not whole rows of the graph's width.
void geozl_2d_graph_close_c(geozl_2d_graph *g);
Frees a graph. Accepts NULL.
int geozl_2d_frame_coeffs_c(const void *frame, size_t frameSize, void *dst,
size_t dstCapacity, size_t *outSize);
Copies a frame's coefficient blob without decoding the payload. Returns 0 on success, -1 when the frame has none and a positive ZL_ErrorCode on failure, ZL_ErrorCode_formatVersion_unsupported for a frame older than GEOZL_COEFFS_FORMAT_MIN. Pass dst as NULL to query the size.
Nodes
ZL_Report geozl_register_decoders(ZL_DCtx *dctx);
int geozl_owns_ctid(uint32_t ctid);
int geozl_ctid_is_lossy(uint32_t ctid);
The first registers every GeoZL decoder in an OpenZL decompression context. The others report whether a codec id lies in GeoZL's reserved range and in its lossy part. The ids are the GeozlCtid values in geozl/ctids.h.
ZL_NodeID geozl_node_delta_w(ZL_Compressor *c, uint32_t width);
ZL_NodeID geozl_node_delta_n(ZL_Compressor *c, uint32_t width,
uint32_t planes);
ZL_NodeID geozl_node_planar(ZL_Compressor *c, uint32_t width,
uint32_t planes);
ZL_NodeID geozl_node_planar_zigzag(ZL_Compressor *c, uint32_t width,
uint32_t planes);
ZL_NodeID geozl_node_planar_zigzag_pfor(ZL_Compressor *c, uint32_t width,
uint32_t planes);
ZL_NodeID geozl_node_planar_zigzag_lanes(ZL_Compressor *c, uint32_t width,
uint32_t planes);
ZL_NodeID geozl_node_lanes(ZL_Compressor *c);
ZL_NodeID geozl_node_med(ZL_Compressor *c, uint32_t width, uint32_t planes);
ZL_NodeID geozl_node_med_zigzag(ZL_Compressor *c, uint32_t width,
uint32_t planes);
ZL_NodeID geozl_node_average(ZL_Compressor *c, uint32_t width,
uint32_t planes);
ZL_NodeID geozl_node_wp_static(ZL_Compressor *c, uint32_t width,
uint32_t planes);
ZL_NodeID geozl_node_deinterleave(ZL_Compressor *c);
ZL_NodeID geozl_node_pfor(ZL_Compressor *c);
Build an encoder node in a compressor, or return ZL_NODE_ILLEGAL. width is in samples, and 0 or a width above the stream's length is one row. A predictor fails to encode a stream of partial rows. planes counts stacked images, and planes that do not split into whole rows are one plane. lanes splits samples into byte lanes coded with PivCo or PFOR, and planar_zigzag_lanes runs planar and zigzag first.
ZL_NodeID geozl_node_quant_linear(ZL_Compressor *c,
const quant_linear_params *params,
int dtype);
ZL_NodeID geozl_node_quant_log(ZL_Compressor *c,
const quant_log_params *params, int dtype);
ZL_NodeID geozl_node_quant_sqrt(ZL_Compressor *c,
const quant_sqrt_params *params, int dtype);
Build a quantizer node from resolved parameters, the structs in geozl/quant_*_params.h that a frame header carries. geozl_node_quant resolves them from a recipe.
ZL_NodeID geozl_node_quant(ZL_Compressor *c, const char *error,
uint32_t width, int dtype, const void *src,
size_t numElts, char *errCtx, size_t errCtxSize);
Builds a quantizer node from an error recipe with the same parse, fit and resolve as geozl_2d_graph_open_c. error takes the LINEAR, LOG and SQRT recipes, and src holds numElts samples of dtype that fix the grid. A SQRT recipe without A and B fits them from src read as rows of width samples, and width is unused otherwise.
The node does not check later tiles against src, so compress only tiles inside its domain. Returns ZL_NODE_ILLEGAL on failure, including a lossless recipe, with a message in errCtx. Set ZL_CParam_contentChecksum to ZL_TernaryParam_disable on the compression context, since the decoded samples differ from the input.
ZL_NodeID geozl_node_nodata(ZL_Compressor *c, uint32_t width,
geozl_nodata_mode mode, uint64_t valueBits,
int dtype, double radius);
Builds a NoData node. In value mode dtype lets it guard samples a lossy stage could move onto the sentinel. radius is that stage's largest error, 0 on a lossless path and INFINITY when unknown. In NaN mode a radius of 0 keeps every NaN's bits and any other marks every NaN as a hole.
Coefficients
size_t geozl_coeffs_size(const uint32_t *counts, size_t nbVecs);
size_t geozl_coeffs_pack(void *dst, size_t dstCapacity,
const int32_t *const *vecs, const uint32_t *counts,
size_t nbVecs, char *err, size_t errSize);
geozl_coeffs_size returns the packed size of nbVecs vectors, or 0 for an invalid shape. geozl_coeffs_pack packs them into dst and returns the bytes written, or 0 on error. The limits are GEOZL_COEFFS_MAX_VECS (255) vectors and GEOZL_COEFFS_MAX_BYTES (10000) bytes. These functions do not depend on OpenZL.
int geozl_coeffs_parse(const void *src, size_t srcSize, int32_t *dst,
size_t dstValues, uint32_t *counts, size_t maxVecs,
size_t *outVecs, size_t *outValues);
Reads a blob into dst, vectors back to back, and their lengths into counts. Returns 0 on success, 1 when src is not a GeoZL blob, -1 when it is invalid and -2 when a buffer is too small, with the sizes still written. Call with both buffers NULL to learn the sizes first.
GPU decode
The decoder in geozl/gpu.h writes frames straight into device memory on a GPU. CUDA and Metal are the first backends. GPU decoding walks through a full call, and this section lists the exact prototypes.
#define GEOZL_GPU_DEVICE_CUDA 2 // DLPack device types
#define GEOZL_GPU_DEVICE_METAL 8
typedef struct GeozlGpu GeozlGpu;
typedef struct GeozlGpuMemory GeozlGpuMemory;
typedef struct {
const void *data;
size_t size;
size_t decodedBytes;
} GeozlGpuFrame;
typedef struct {
size_t frame;
size_t source;
size_t sourceRow;
size_t sourceStep;
size_t destination;
size_t destinationRow;
size_t destinationStep;
uint32_t width;
uint32_t rows;
} GeozlGpuCopy;
typedef struct {
void *memory;
size_t offset;
size_t bytes;
void *stream;
} GeozlGpuTarget;
A GeozlGpuFrame is the compressed bytes and the exact size they decode to. A GeozlGpuCopy moves a window of rows × width samples from one decoded frame into the target, with offsets and strides in bytes. A GeozlGpuTarget names the device memory, the byte offset and writable bytes after it, and the stream the work joins, which on CUDA belongs to the device's primary context.
int geozl_gpu_available(int deviceType);
Returns nonzero when this build drives the device type.
GeozlGpu *geozl_gpu_create(int deviceType, int device, size_t threads,
size_t maxDecodedBytes, int verifyChecksums,
char *error, size_t errorCapacity);
void geozl_gpu_destroy(GeozlGpu *gpu);
Creates a decoder on one device, or returns NULL with a message. threads caps the host threads of one decode, with 0 meaning one, and maxDecodedBytes caps the decoded bytes of one call and must be nonzero. Host staging grows with the compressed and host-decoded bytes of a call and is kept until geozl_gpu_destroy, so bound it by the batch size. A decoder serves one decode or synchronize at a time, and one that overlaps another fails. Destroying must not overlap any call.
int geozl_gpu_decode(GeozlGpu *gpu, const GeozlGpuFrame frames[],
size_t frameCount, const GeozlGpuCopy copies[],
size_t copyCount, size_t sampleBytes,
size_t elementBytes, const GeozlGpuTarget *target,
const uint8_t forceHost[], char *error,
size_t errorCapacity);
Decodes the frames and runs the copies into the target. Single-chunk pfor and lanes frames of 1 or 2-byte samples expand on the device, and the rest decode on the host and upload. forceHost is NULL or one byte per frame, nonzero to send that frame through the host. The frames, their bytes, the copies and forceHost may be reused once the call returns. Invalid arguments fail the call before it waits on or reports earlier work. After a failure the target's contents are unspecified, and work queued by earlier calls may still write to it.
int geozl_gpu_synchronize(GeozlGpu *gpu, char *error, size_t errorCapacity);
Waits for queued work and reports its errors. On CUDA geozl_gpu_decode returns once work is queued, so keep the target alive until this returns. Metal finishes inside the decode call.
GeozlGpuMemory *geozl_gpu_alloc(GeozlGpu *gpu, size_t bytes, char *error,
size_t errorCapacity);
void *geozl_gpu_pointer(const GeozlGpuMemory *memory);
void geozl_gpu_free(GeozlGpuMemory *memory);
Allocate and free caller-owned device memory for a target. geozl_gpu_pointer returns the device handle to pass as GeozlGpuTarget.memory. These three may run on any thread, also while a decode is in progress.