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>
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()
|
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()
|
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
-
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.
◆ tensor_contract()
|
static |
Compare concrete execution shapes, allowing dynamic graph axes only during initial binding.
Definition at line 68 of file onnx_session.c.
◆ watch_deadline()
|
static |
Request termination without releasing buffers still borrowed by a running graph.
Definition at line 162 of file onnx_session.c.