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
onnx_session.c File Reference

Reusable numeric tensor sessions without image, acoustic or planning semantics. More...

#include "onnx_session.h"
#include "onnx_runtime.h"
#include <onnxruntime_c_api.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
Include dependency graph for onnx_session.c:

Go to the source code of this file.

Functions

static bool checked (OrtStatus *status, char *error, size_t capacity)
 Consume every ORT error object exactly once while copying its diagnostic before release.
uint64_t onnx_monotonic_us (void)
 Read the clock used by inference deadlines.
bool onnx_tensor_bytes (enum onnx_element_type type, const int64_t *dimensions, size_t rank, size_t *bytes)
 Compute bounded concrete storage, rejecting unsupported types, dynamic extents and overflow.
static bool tensor_contract (const OrtTensorTypeAndShapeInfo *info, const struct onnx_tensor *spec, bool dynamic, char *error, size_t capacity)
 Compare concrete execution shapes, allowing dynamic graph axes only during initial binding.
static bool bind_tensors (struct onnx_session *session, const struct onnx_tensor *specs, size_t count, bool input, char *error, size_t capacity)
 Bind by graph name rather than declaration order, which may change during export optimization.
static void * watch_deadline (void *context)
 Request termination without releasing buffers still borrowed by a running graph.
bool onnx_session_open (struct onnx_session *session, const char *model, const struct onnx_tensor *inputs, size_t input_count, const struct onnx_tensor *outputs, size_t output_count, const struct onnx_session_options *options, char *error, size_t capacity)
 Validate graph contracts and bind reusable caller buffers; failure releases acquired resources.
bool onnx_session_run (struct onnx_session *session, uint64_t deadline_us, char *error, size_t capacity)
 Run once; deadline is absolute CLOCK_MONOTONIC microseconds, or zero for none.
void onnx_session_cancel (struct onnx_session *session)
 Request cooperative cancellation from another thread; join the owner before destroying storage.
void onnx_session_close (struct onnx_session *session)
 Cancel/wait for an active run and release resources; repeated closes are harmless.

Detailed Description

Reusable numeric tensor sessions without image, acoustic or planning semantics.

Cancellation is cooperative; outer worker supervision remains the recovery boundary.

Definition in file onnx_session.c.

Function Documentation

◆ bind_tensors()

bool bind_tensors ( struct onnx_session * session,
const struct onnx_tensor * specs,
size_t count,
bool input,
char * error,
size_t capacity )
static

Bind by graph name rather than declaration order, which may change during export optimization.

Definition at line 93 of file onnx_session.c.

◆ checked()

bool checked ( OrtStatus * status,
char * error,
size_t capacity )
static

Consume every ORT error object exactly once while copying its diagnostic before release.

Definition at line 31 of file onnx_session.c.

◆ onnx_monotonic_us()

uint64_t onnx_monotonic_us ( void )

Read the clock used by inference deadlines.

Returns
CLOCK_MONOTONIC microseconds, or zero when the clock cannot be read.

Definition at line 40 of file onnx_session.c.

◆ onnx_session_cancel()

void onnx_session_cancel ( struct onnx_session * session)

Request cooperative cancellation from another thread; join the owner before destroying storage.

Parameters
sessionLive owner; NULL/unopened owners are ignored.

Definition at line 325 of file onnx_session.c.

◆ onnx_session_close()

void onnx_session_close ( struct onnx_session * session)

Cancel/wait for an active run and release resources; repeated closes are harmless.

Parameters
sessionExclusive lifecycle owner; NULL is ignored.
Precondition
No new calls may begin while close destroys synchronization objects.

Definition at line 337 of file onnx_session.c.

◆ onnx_session_open()

bool onnx_session_open ( struct onnx_session * session,
const char * model,
const struct onnx_tensor * inputs,
size_t input_count,
const struct onnx_tensor * outputs,
size_t output_count,
const struct onnx_session_options * options,
char * error,
size_t capacity )

Validate graph contracts and bind reusable caller buffers; failure releases acquired resources.

Parameters
sessionZero-initialized owner with no open session; do not copy it after opening.
modelReadable ONNX graph path.
inputsNamed input views whose backing buffers outlive the session.
input_countNumber of input views, in 1..ONNX_TENSOR_LIMIT.
outputsNamed writable output views with the same lifetime rule.
output_countNumber of output views, in 1..ONNX_TENSOR_LIMIT.
optionsOptional execution/search policy; NULL uses one CPU thread.
errorWritable failure diagnostic, cleared on success.
capacityAvailable bytes in error.
Returns
True only after every name, type, shape and backing byte count is accepted.
Note
Dynamic graph axes bind to the declared concrete shape; outputs are checked again after each run.

Definition at line 187 of file onnx_session.c.

◆ onnx_session_run()

bool onnx_session_run ( struct onnx_session * session,
uint64_t deadline_us,
char * error,
size_t capacity )

Run once; deadline is absolute CLOCK_MONOTONIC microseconds, or zero for none.

Parameters
sessionOpen owner; one run at a time is admitted.
deadline_usAbsolute completion budget in the host monotonic clock domain.
errorWritable failure diagnostic, cleared on success.
capacityAvailable bytes in error.
Returns
True for complete execution with valid output shapes and an unexpired budget.
Warning
Ignore output buffers on false. Cancellation is cooperative, not a hard deadline.

Definition at line 251 of file onnx_session.c.

◆ onnx_tensor_bytes()

bool onnx_tensor_bytes ( enum onnx_element_type type,
const int64_t * dimensions,
size_t rank,
size_t * bytes )

Compute bounded concrete storage, rejecting unsupported types, dynamic extents and overflow.

Parameters
typeSupported numeric element type.
dimensionsConcrete extents; NULL is allowed only for rank zero.
rankNumber of extents, at most ONNX_RANK_LIMIT.
bytesOutput byte count, meaningful only on success.
Returns
True for a representable tensor within ONNX_BUFFER_LIMIT.

Definition at line 47 of file onnx_session.c.

◆ tensor_contract()

bool tensor_contract ( const OrtTensorTypeAndShapeInfo * info,
const struct onnx_tensor * spec,
bool dynamic,
char * error,
size_t capacity )
static

Compare concrete execution shapes, allowing dynamic graph axes only during initial binding.

Definition at line 68 of file onnx_session.c.

◆ watch_deadline()

void * watch_deadline ( void * context)
static

Request termination without releasing buffers still borrowed by a running graph.

Definition at line 162 of file onnx_session.c.