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.h
Go to the documentation of this file.
1/*
2 * Copyright 2026 OpenUAS
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/** @file onnx_session.h
19 * @brief Bounded tensor bindings and cooperative execution policy, independent of CAM semantics. */
20#ifndef SENSORAIA_ONNX_SESSION_H
21#define SENSORAIA_ONNX_SESSION_H
22
23#include <stdbool.h>
24#include <stddef.h>
25#include <stdint.h>
26#include <pthread.h>
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32#define ONNX_TENSOR_LIMIT 16U
33#define ONNX_RANK_LIMIT 8U
34#define ONNX_NAME_CAPACITY 128U
35#define ONNX_BUFFER_LIMIT (64U * 1024U * 1024U)
36
37/** @brief Supported numeric types; values match the ONNX Runtime C ABI. */
42
43/** @brief Named concrete tensor view; its aligned backing storage must outlive the session. */
45 const char *name; /**< Graph name, copied by session open rather than matched by declaration order. */
46 enum onnx_element_type type; /**< Exact numeric storage representation. */
47 size_t rank; /**< Concrete rank, including zero for a scalar. */
48 int64_t dimensions[ONNX_RANK_LIMIT]; /**< Positive concrete extents; unused axes are ignored. */
49 void *data; /**< Aligned caller storage, never freed by the session. */
50 size_t bytes; /**< Exact byte count implied by type and concrete dimensions. */
51};
52
53/** @brief Explicit execution limits so each model cannot create an unbounded CPU pool. */
55 unsigned threads; /**< Intra-op thread count in 1..32; inter-op execution remains sequential. */
56 const char *library_directory; /**< Optional runtime search directory, consumed during open. */
57};
58
59#define ONNX_SESSION_OPTIONS_DEFAULT {1U, NULL}
60
61/** @brief Noncopyable caller-owned session; zero-initialize and serialize open/run/close ownership.
62 * @details Fields are implementation state, not configuration knobs. Caller tensors must
63 * remain alive until close has completed; a failed run does not validate their output contents. */
77
78/** @brief Compute bounded concrete storage, rejecting unsupported types, dynamic extents and overflow.
79 * @param type Supported numeric element type.
80 * @param dimensions Concrete extents; NULL is allowed only for rank zero.
81 * @param rank Number of extents, at most ONNX_RANK_LIMIT.
82 * @param bytes Output byte count, meaningful only on success.
83 * @return True for a representable tensor within ONNX_BUFFER_LIMIT. */
84bool onnx_tensor_bytes(enum onnx_element_type type, const int64_t *dimensions,
85 size_t rank, size_t *bytes);
86/** @brief Validate graph contracts and bind reusable caller buffers; failure releases acquired resources.
87 * @param session Zero-initialized owner with no open session; do not copy it after opening.
88 * @param model Readable ONNX graph path.
89 * @param inputs Named input views whose backing buffers outlive the session.
90 * @param input_count Number of input views, in 1..ONNX_TENSOR_LIMIT.
91 * @param outputs Named writable output views with the same lifetime rule.
92 * @param output_count Number of output views, in 1..ONNX_TENSOR_LIMIT.
93 * @param options Optional execution/search policy; NULL uses one CPU thread.
94 * @param error Writable failure diagnostic, cleared on success.
95 * @param capacity Available bytes in error.
96 * @return True only after every name, type, shape and backing byte count is accepted.
97 * @note Dynamic graph axes bind to the declared concrete shape; outputs are checked again after each run. */
98bool onnx_session_open(struct onnx_session *session, const char *model,
99 const struct onnx_tensor *inputs, size_t input_count,
100 const struct onnx_tensor *outputs, size_t output_count,
101 const struct onnx_session_options *options,
102 char *error, size_t capacity);
103/** @brief Run once; deadline is absolute CLOCK_MONOTONIC microseconds, or zero for none.
104 * @param session Open owner; one run at a time is admitted.
105 * @param deadline_us Absolute completion budget in the host monotonic clock domain.
106 * @param error Writable failure diagnostic, cleared on success.
107 * @param capacity Available bytes in error.
108 * @return True for complete execution with valid output shapes and an unexpired budget.
109 * @warning Ignore output buffers on false. Cancellation is cooperative, not a hard deadline. */
110bool onnx_session_run(struct onnx_session *session, uint64_t deadline_us,
111 char *error, size_t capacity);
112/** @brief Request cooperative cancellation from another thread; join the owner before destroying storage.
113 * @param session Live owner; NULL/unopened owners are ignored. */
115/** @brief Cancel/wait for an active run and release resources; repeated closes are harmless.
116 * @param session Exclusive lifecycle owner; NULL is ignored.
117 * @pre No new calls may begin while close destroys synchronization objects. */
119/** @brief Read the clock used by inference deadlines.
120 * @return CLOCK_MONOTONIC microseconds, or zero when the clock cannot be read. */
121uint64_t onnx_monotonic_us(void);
122
123#ifdef __cplusplus
124}
125#endif
126#endif
static unsigned capacity[COVERAGE_CAMERAS]
static uint32_t session
uint8_t bytes[CHDK_CONTROL_REPLY_SIZE]
Definition chdk_pipe.c:144
struct jpeg_error_mgr error
Definition lwir_image.c:60
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.
#define ONNX_NAME_CAPACITY
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.
#define ONNX_TENSOR_LIMIT
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.
onnx_element_type
Supported numeric types; values match the ONNX Runtime C ABI.
@ ONNX_INT32
@ ONNX_FLOAT32
@ ONNX_FLOAT64
@ ONNX_INT64
@ ONNX_UINT8
@ ONNX_INT8
uint64_t onnx_monotonic_us(void)
Read the clock used by inference deadlines.
void onnx_session_cancel(struct onnx_session *session)
Request cooperative cancellation from another thread; join the owner before destroying storage.
#define ONNX_RANK_LIMIT
void onnx_session_close(struct onnx_session *session)
Cancel/wait for an active run and release resources; repeated closes are harmless.
Explicit execution limits so each model cannot create an unbounded CPU pool.
const char * library_directory
Noncopyable caller-owned session; zero-initialize and serialize open/run/close ownership.
void * run_options
char output_names[ONNX_TENSOR_LIMIT][ONNX_NAME_CAPACITY]
void * inputs[ONNX_TENSOR_LIMIT]
void * outputs[ONNX_TENSOR_LIMIT]
struct onnx_tensor output_specs[ONNX_TENSOR_LIMIT]
uint64_t deadline_us
pthread_t watchdog
pthread_mutex_t mutex
size_t output_count
size_t input_count
pthread_cond_t condition
char input_names[ONNX_TENSOR_LIMIT][ONNX_NAME_CAPACITY]
Named concrete tensor view; its aligned backing storage must outlive the session.
enum onnx_element_type type
int64_t dimensions[ONNX_RANK_LIMIT]
const char * name
Validated capture and reporting policy, fixed before the sample loop.
Definition earcam.c:137