Loading...
Searching...
No Matches
onnx_session.c
Go to the documentation of this file.
20 * @details Cancellation is cooperative; outer worker supervision remains the recovery boundary. */
30/** @brief Consume every ORT error object exactly once while copying its diagnostic before release. */
59 /* Divide before multiplying so malformed dimensions cannot wrap a valid-looking allocation size. */
60 if (dimensions[axis] <= 0 || (uint64_t)dimensions[axis] > ONNX_BUFFER_LIMIT / size) return false;
67/** @brief Compare concrete execution shapes, allowing dynamic graph axes only during initial binding. */
92/** @brief Bind by graph name rather than declaration order, which may change during export optimization. */
111 api->SessionGetOutputName(session->handle, index, allocator, &name), error, capacity)) return false;
134 const bool valid = checked(api->CastTypeInfoToTensorInfo(type, &info), error, capacity) && info &&
143 spec->dimensions, spec->rank, (ONNXTensorElementDataType)spec->type, &value), error, capacity)) return false;
145 for (size_t character = 0; character <= strlen(spec->name); ++character) destination[character] = spec->name[character];
155 for (size_t axis = 0; axis < spec->rank; ++axis) output->dimensions[axis] = spec->dimensions[axis];
196 !input_count || input_count > ONNX_TENSOR_LIMIT || !output_count || output_count > ONNX_TENSOR_LIMIT ||
201 if (!onnx_runtime_open(options ? options->library_directory : NULL, error, capacity)) return false;
209 /* Per-model default pools otherwise compete for every core and keep the small board spinning. */
210 bool valid = checked(api->SetIntraOpNumThreads(configuration, (int)threads), error, capacity) &&
213 checked(api->SetSessionGraphOptimizationLevel(configuration, ORT_ENABLE_ALL), error, capacity) &&
214 checked(api->AddSessionConfigEntry(configuration, "session.intra_op.allow_spinning", "0"), error, capacity) &&
215 checked(api->AddSessionConfigEntry(configuration, "session.inter_op.allow_spinning", "0"), error, capacity) &&
216 checked(api->CreateSession(onnx_runtime_environment(), model, configuration, &handle), error, capacity);
222 valid = checked(api->CreateCpuMemoryInfo(OrtArenaAllocator, OrtMemTypeDefault, &memory), error, capacity) &&
236 const int initialized = configured ? configured : pthread_cond_init(&session->condition, &attributes);
262 if (session->running || session->stopping || (deadline_us && onnx_monotonic_us() >= deadline_us)) {
bool onnx_runtime_open(const char *library_directory, char *error, size_t capacity)
Initialize one process-lifetime runtime/environment using explicit local search roots.
Definition onnx_runtime.c:38
OrtEnv * onnx_runtime_environment(void)
Borrow the environment retained until process exit.
Definition onnx_runtime.c:177
const OrtApi * onnx_runtime_api(void)
Borrow the initialized API, without transferring release ownership.
Definition onnx_runtime.c:169
Process-wide runtime ownership shared by independent model sessions.
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.
Definition onnx_session.c:47
static bool checked(OrtStatus *status, char *error, size_t capacity)
Consume every ORT error object exactly once while copying its diagnostic before release.
Definition onnx_session.c:31
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.
Definition onnx_session.c:251
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.
Definition onnx_session.c:187
static void * watch_deadline(void *context)
Request termination without releasing buffers still borrowed by a running graph.
Definition onnx_session.c:162
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.
Definition onnx_session.c:68
uint64_t onnx_monotonic_us(void)
Read the clock used by inference deadlines.
Definition onnx_session.c:40
void onnx_session_cancel(struct onnx_session *session)
Request cooperative cancellation from another thread; join the owner before destroying storage.
Definition onnx_session.c:325
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.
Definition onnx_session.c:93
void onnx_session_close(struct onnx_session *session)
Cancel/wait for an active run and release resources; repeated closes are harmless.
Definition onnx_session.c:337
Bounded tensor bindings and cooperative execution policy, independent of CAM semantics.
onnx_element_type
Supported numeric types; values match the ONNX Runtime C ABI.
Definition onnx_session.h:38
Explicit execution limits so each model cannot create an unbounded CPU pool.
Definition onnx_session.h:54
Noncopyable caller-owned session; zero-initialize and serialize open/run/close ownership.
Definition onnx_session.h:64
Named concrete tensor view; its aligned backing storage must outlive the session.
Definition onnx_session.h:44