Illustrated C/C++ source sheets, symbol index, API relationship graph, compiler console and debug trace

LIVE AI / FLEXIBLE SENSING / FLIGHT CONTEXT

Sensoraia API

Live AI and sensing, connected to the flight.
See, listen, inspect and return supported results while airborne.

Loading...
Searching...
No Matches
inference_model.c File Reference

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>
Include dependency graph for inference_model.c:

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()

bool copy_name ( char * destination,
size_t capacity,
const char * value )
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
contextExclusive 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
contextZero-initialized noncopyable owner.
settingsResolved ONNX configuration; values are consumed during open.
adapterRequired application ABI, or NULL when the caller validates it separately.
errorWritable failure diagnostic.
capacityAvailable 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
contextOpen owner with one declared image tensor.
imageBorrowed immutable pixels valid for this call only.
errorWritable failure diagnostic.
capacityAvailable 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
contextExclusive open model owner.
errorWritable failure diagnostic.
capacityAvailable 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
filenameImmutable input path during hashing.
digestDestination 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
modelParsed descriptor with comma-separated labels.
categoryZero-based class index.
labelWritable nontruncated class name.
capacityAvailable 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
modelDestination with name storage backing its own tensor views.
contentsDestructively parsed input with at least length+1 writable bytes.
lengthInput bytes excluding the writable terminator.
errorWritable failure diagnostic.
capacityAvailable 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
modelDestination contract; discard it on failure.
descriptorSENSORAIA_MODEL_V1 flat INI path.
graphGraph whose bytes must match the descriptor hash.
errorWritable failure diagnostic.
capacityAvailable bytes in error.
Returns
True for a complete descriptor and matching graph identity.

Definition at line 258 of file inference_model.c.

◆ model_field()

bool model_field ( void * context,
const char * key,
const char * value )
static

Recognize descriptor policy, not arbitrary network-specific configuration or custom operators.

Definition at line 136 of file inference_model.c.

◆ parse_channels()

bool parse_channels ( float values[3],
const char * text )
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()

bool parse_dimensions ( struct onnx_tensor * tensor,
const char * text )
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()

bool tensor_field ( struct model_parser * parser,
const char * key,
const char * value,
bool input )
static

Parse one indexed tensor while keeping duplicate detection separate for each tensor and direction.

Definition at line 99 of file inference_model.c.