From a1e355b8ceb12ac66c9d82e7786df4c3c40be479 Mon Sep 17 00:00:00 2001 From: Onur Gündüz Date: Wed, 21 Oct 2026 20:08:53 +0200 Subject: Init --- model_blob.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 model_blob.h (limited to 'model_blob.h') diff --git a/model_blob.h b/model_blob.h new file mode 100644 index 0000000..433947d --- /dev/null +++ b/model_blob.h @@ -0,0 +1,36 @@ +/* Access to packed, named float tensors in a read-only model blob. */ + +#ifndef FRAMESED_MODEL_BLOB_H +#define FRAMESED_MODEL_BLOB_H + +#include + +/* Tensor lookup returns NULL and records a failure, so a loader can request + * every tensor in a straight line and check the blob once at the end. */ +typedef struct { + const unsigned char *base; + size_t len; + const void *table; + unsigned count; + int verify; + int failed; +} framesed_model_blob; + +/* Returns 0 when the header and table are well formed. Tensor contents are + * only checked as they are taken. */ +int framesed_model_blob_parse(const void *data, size_t len, int verify, framesed_model_blob *out); + +/* The tensor called `name`, which must be exactly `floats` long. Returns NULL + * and marks the blob failed on any mismatch, so a blob exported from a + * different checkpoint or a different layout is rejected at load time rather + * than producing plausible wrong numbers. */ +const float *framesed_model_blob_take(framesed_model_blob *blob, const char *name, size_t floats); + +/* Maps `path` read-only and parses it. On success the caller must keep the + * mapping alive for as long as any pointer taken from it is used. */ +int framesed_model_blob_map( + const char *path, int verify, framesed_model_blob *out, void **map, size_t *map_len); + +void framesed_model_blob_unmap(void *map, size_t len); + +#endif -- cgit v1.3.1