Bounded tensor bindings and cooperative execution policy, independent of CAM semantics. More...
#include <stdbool.h>#include <stddef.h>#include <stdint.h>#include <pthread.h>

Go to the source code of this file.
Data Structures | |
| struct | onnx_tensor |
| Named concrete tensor view; its aligned backing storage must outlive the session. More... | |
| struct | onnx_session_options |
| Explicit execution limits so each model cannot create an unbounded CPU pool. More... | |
| struct | onnx_session |
| Noncopyable caller-owned session; zero-initialize and serialize open/run/close ownership. More... | |
Macros | |
| #define | ONNX_TENSOR_LIMIT 16U |
| #define | ONNX_RANK_LIMIT 8U |
| #define | ONNX_NAME_CAPACITY 128U |
| #define | ONNX_BUFFER_LIMIT (64U * 1024U * 1024U) |
| #define | ONNX_SESSION_OPTIONS_DEFAULT {1U, NULL} |
Enumerations | |
| enum | onnx_element_type { ONNX_FLOAT32 = 1 , ONNX_UINT8 = 2 , ONNX_INT8 = 3 , ONNX_INT32 = 6 , ONNX_INT64 = 7 , ONNX_FLOAT64 = 11 } |
| Supported numeric types; values match the ONNX Runtime C ABI. More... | |
Functions | |
| 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. | |
| 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. | |
| uint64_t | onnx_monotonic_us (void) |
| Read the clock used by inference deadlines. | |
Detailed Description
Bounded tensor bindings and cooperative execution policy, independent of CAM semantics.
Definition in file onnx_session.h.
Macro Definition Documentation
◆ ONNX_BUFFER_LIMIT
| #define ONNX_BUFFER_LIMIT (64U * 1024U * 1024U) |
Definition at line 35 of file onnx_session.h.
◆ ONNX_NAME_CAPACITY
| #define ONNX_NAME_CAPACITY 128U |
Definition at line 34 of file onnx_session.h.
◆ ONNX_RANK_LIMIT
| #define ONNX_RANK_LIMIT 8U |
Definition at line 33 of file onnx_session.h.
◆ ONNX_SESSION_OPTIONS_DEFAULT
| #define ONNX_SESSION_OPTIONS_DEFAULT {1U, NULL} |
Definition at line 59 of file onnx_session.h.
◆ ONNX_TENSOR_LIMIT
| #define ONNX_TENSOR_LIMIT 16U |
Definition at line 32 of file onnx_session.h.
Enumeration Type Documentation
◆ onnx_element_type
| enum onnx_element_type |
Supported numeric types; values match the ONNX Runtime C ABI.
| Enumerator | |
|---|---|
| ONNX_FLOAT32 | |
| ONNX_UINT8 | |
| ONNX_INT8 | |
| ONNX_INT32 | |
| ONNX_INT64 | |
| ONNX_FLOAT64 | |
Definition at line 38 of file onnx_session.h.
Function Documentation
◆ 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
-
session Live 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
-
session Exclusive 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
-
session Zero-initialized owner with no open session; do not copy it after opening. model Readable ONNX graph path. inputs Named input views whose backing buffers outlive the session. input_count Number of input views, in 1..ONNX_TENSOR_LIMIT. outputs Named writable output views with the same lifetime rule. output_count Number of output views, in 1..ONNX_TENSOR_LIMIT. options Optional execution/search policy; NULL uses one CPU thread. error Writable failure diagnostic, cleared on success. capacity Available 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
-
session Open owner; one run at a time is admitted. deadline_us Absolute completion budget in the host monotonic clock domain. error Writable failure diagnostic, cleared on success. capacity Available 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
-
type Supported numeric element type. dimensions Concrete extents; NULL is allowed only for rank zero. rank Number of extents, at most ONNX_RANK_LIMIT. bytes Output 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.