/* 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