Verified model descriptors and bounded per-context tensor storage. More...
#include "inference_model.h"#include "sha256fst.h"#include <errno.h>#include <fcntl.h>#include <math.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/stat.h>#include <sys/mman.h>#include <unistd.h>
Go to the source code of this file.
Data Structures | |
| struct | model_parser |
| Independent duplicate masks for descriptor-wide and indexed tensor fields. More... | |
Functions | |
| bool | inference_file_sha256 (const char *filename, char digest[65]) |
| Hash a stable nonempty regular file using bounded streaming scratch. | |
| static bool | copy_name (char *destination, size_t capacity, const char *value) |
| Store an owned bounded name so parser-buffer destruction cannot invalidate tensor views. | |
| static bool | parse_dimensions (struct onnx_tensor *tensor, const char *text) |
| Accept concrete positive extents only; export-time dynamic axes need an explicit execution shape. | |
| static bool | parse_channels (float values[3], const char *text) |
| Accept one shared channel value or exactly three, without silently broadcasting an incomplete pair. | |
| static bool | tensor_field (struct model_parser *parser, const char *key, const char *value, bool input) |
| Parse one indexed tensor while keeping duplicate detection separate for each tensor and direction. | |
| static bool | model_field (void *context, const char *key, const char *value) |
| Recognize descriptor policy, not arbitrary network-specific configuration or custom operators. | |
| bool | inference_model_parse (struct inference_model *model, char *contents, size_t length, char *error, size_t capacity) |
| Parse a descriptor, not graph bytes; graph integrity remains a separate read-time check. | |
| bool | inference_model_label (const struct inference_model *model, unsigned category, char *label, size_t capacity) |
| Resolve one model-owned label without retaining a pointer into a mutable list. | |
| bool | inference_model_read (struct inference_model *model, const char *descriptor, const char *graph, char *error, size_t capacity) |
| Load a bounded descriptor and verify its exact graph digest; hashes are not authentication. | |
| bool | inference_context_open (struct inference_context *context, const struct inference_settings *settings, const char *adapter, char *error, size_t capacity) |
| Verify a bundle, map bounded tensors and bind one warm session. | |
| bool | inference_context_run (struct inference_context *context, char *error, size_t capacity) |
| Run the currently prepared tensors using the context's timeout policy. | |
| bool | inference_context_prepare_image (struct inference_context *context, const struct inference_image *image, char *error, size_t capacity) |
| Prepare a single image input without running the model, so camera leases can be released first. | |
| void | inference_context_close (struct inference_context *context) |
| Release the session before unmapping its borrowed tensor storage. | |
Detailed Description
Verified model descriptors and bounded per-context tensor storage.
Descriptors bind preprocessing to graph bytes; application adapters still qualify semantic outputs.
Definition in file inference_model.c.
Function Documentation
◆ copy_name()
|
static |
Store an owned bounded name so parser-buffer destruction cannot invalidate tensor views.
Definition at line 47 of file inference_model.c.
◆ inference_context_close()
| void inference_context_close | ( | struct inference_context * | context | ) |
Release the session before unmapping its borrowed tensor storage.
- Parameters
-
context Exclusive owner; NULL and repeated closes are harmless.
Definition at line 373 of file inference_model.c.
◆ inference_context_open()
| bool inference_context_open | ( | struct inference_context * | context, |
| const struct inference_settings * | settings, | ||
| const char * | adapter, | ||
| char * | error, | ||
| size_t | capacity ) |
Verify a bundle, map bounded tensors and bind one warm session.
- Parameters
-
context Zero-initialized noncopyable owner. settings Resolved ONNX configuration; values are consumed during open. adapter Required application ABI, or NULL when the caller validates it separately. error Writable failure diagnostic. capacity Available bytes in error.
- Returns
- True after the graph can use this context's tensor buffers.
- Note
- Mapping tensor storage does not make ORT allocations heap-free or bound whole-board RAM.
Definition at line 277 of file inference_model.c.
◆ inference_context_prepare_image()
| bool inference_context_prepare_image | ( | struct inference_context * | context, |
| const struct inference_image * | image, | ||
| char * | error, | ||
| size_t | capacity ) |
Prepare a single image input without running the model, so camera leases can be released first.
- Parameters
-
context Open owner with one declared image tensor. image Borrowed immutable pixels valid for this call only. error Writable failure diagnostic. capacity Available bytes in error.
- Returns
- True after filling input storage and its source-coordinate transform.
Definition at line 361 of file inference_model.c.
◆ inference_context_run()
| bool inference_context_run | ( | struct inference_context * | context, |
| char * | error, | ||
| size_t | capacity ) |
Run the currently prepared tensors using the context's timeout policy.
- Parameters
-
context Exclusive open model owner. error Writable failure diagnostic. capacity Available bytes in error.
- Returns
- True for valid completed output; ignore output on failure.
Definition at line 346 of file inference_model.c.
◆ inference_file_sha256()
| bool inference_file_sha256 | ( | const char * | filename, |
| char | digest[65] ) |
Hash a stable nonempty regular file using bounded streaming scratch.
- Parameters
-
filename Immutable input path during hashing. digest Destination for 64 lowercase hex characters and a NUL.
- Returns
- True for a complete stable read; digest is undefined on failure.
Definition at line 41 of file inference_model.c.
◆ inference_model_label()
| bool inference_model_label | ( | const struct inference_model * | model, |
| unsigned | category, | ||
| char * | label, | ||
| size_t | capacity ) |
Resolve one model-owned label without retaining a pointer into a mutable list.
- Parameters
-
model Parsed descriptor with comma-separated labels. category Zero-based class index. label Writable nontruncated class name. capacity Available bytes in label.
- Returns
- True when the requested label exists and fits.
Definition at line 237 of file inference_model.c.
◆ inference_model_parse()
| bool inference_model_parse | ( | struct inference_model * | model, |
| char * | contents, | ||
| size_t | length, | ||
| char * | error, | ||
| size_t | capacity ) |
Parse a descriptor, not graph bytes; graph integrity remains a separate read-time check.
- Parameters
-
model Destination with name storage backing its own tensor views. contents Destructively parsed input with at least length+1 writable bytes. length Input bytes excluding the writable terminator. error Writable failure diagnostic. capacity Available bytes in error.
- Returns
- True for supported schema, bounded concrete tensors and complete preprocessing.
Definition at line 189 of file inference_model.c.
◆ inference_model_read()
| bool inference_model_read | ( | struct inference_model * | model, |
| const char * | descriptor, | ||
| const char * | graph, | ||
| char * | error, | ||
| size_t | capacity ) |
Load a bounded descriptor and verify its exact graph digest; hashes are not authentication.
- Parameters
-
model Destination contract; discard it on failure. descriptor SENSORAIA_MODEL_V1 flat INI path. graph Graph whose bytes must match the descriptor hash. error Writable failure diagnostic. capacity Available bytes in error.
- Returns
- True for a complete descriptor and matching graph identity.
Definition at line 258 of file inference_model.c.
◆ model_field()
|
static |
Recognize descriptor policy, not arbitrary network-specific configuration or custom operators.
Definition at line 136 of file inference_model.c.
◆ parse_channels()
|
static |
Accept one shared channel value or exactly three, without silently broadcasting an incomplete pair.
Definition at line 76 of file inference_model.c.
◆ parse_dimensions()
|
static |
Accept concrete positive extents only; export-time dynamic axes need an explicit execution shape.
Definition at line 59 of file inference_model.c.
◆ tensor_field()
|
static |
Parse one indexed tensor while keeping duplicate detection separate for each tensor and direction.
Definition at line 99 of file inference_model.c.