diff options
| author | Onur Gündüz <ogunduz@gmail.com> | 2026-10-21 20:08:53 +0200 |
|---|---|---|
| committer | Onur Gündüz <ogunduz@gmail.com> | 2026-10-21 20:08:53 +0200 |
| commit | a1e355b8ceb12ac66c9d82e7786df4c3c40be479 (patch) | |
| tree | 9d69cf196ec00e85009e1037a3a314d703466ac3 /model_blob.h | |
| download | framesed-a1e355b8ceb12ac66c9d82e7786df4c3c40be479.tar.gz framesed-a1e355b8ceb12ac66c9d82e7786df4c3c40be479.zip | |
Diffstat (limited to 'model_blob.h')
| -rw-r--r-- | model_blob.h | 36 |
1 files changed, 36 insertions, 0 deletions
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 <stddef.h> + +/* 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 |
