|
Oakfield API Documentation 1.0.0
Numerical core APIs
|
Context-level neural model registry and execution helpers. More...
#include "operators/neural/neural_infer.h"#include <stdbool.h>#include <stddef.h>#include <stdint.h>

Go to the source code of this file.
Classes | |
| struct | SimNeuralModelConfig |
| Registration-time model metadata and backend configuration. More... | |
| struct | SimNeuralModelRuntimeStats |
| Accumulated runtime counters for a registered model. More... | |
| struct | SimNeuralModelEntry |
| Stored registry entry pairing model config with runtime stats. More... | |
| struct | SimNeuralModelRegistry |
| Owning dynamic array of neural model entries. More... | |
Macros | |
| #define | SIM_NEURAL_MODEL_COMMAND_MAX 255U |
| #define | SIM_NEURAL_MODEL_NOTE_MAX 127U |
| #define | SIM_NEURAL_MODEL_ERROR_MAX 191U |
| #define | SIM_NEURAL_DEVICE_MASK_CPU (1U << 0) |
| #define | SIM_NEURAL_DEVICE_MASK_CUDA (1U << 1) |
| #define | SIM_NEURAL_DEVICE_MASK_MPS (1U << 2) |
Typedefs | |
| typedef enum SimNeuralBackendKind | SimNeuralBackendKind |
| Supported neural inference backend families. | |
| typedef enum SimNeuralExecutionDevice | SimNeuralExecutionDevice |
| Execution devices that can be requested for inference. | |
| typedef struct SimNeuralModelConfig | SimNeuralModelConfig |
| Registration-time model metadata and backend configuration. | |
| typedef struct SimNeuralModelRuntimeStats | SimNeuralModelRuntimeStats |
| Accumulated runtime counters for a registered model. | |
| typedef struct SimNeuralModelEntry | SimNeuralModelEntry |
| Stored registry entry pairing model config with runtime stats. | |
| typedef struct SimNeuralModelRegistry | SimNeuralModelRegistry |
| Owning dynamic array of neural model entries. | |
Enumerations | |
| enum | SimNeuralBackendKind { SIM_NEURAL_BACKEND_CALLBACK = 0 , SIM_NEURAL_BACKEND_EXTERNAL_PROCESS , SIM_NEURAL_BACKEND_INPROCESS_ONNX_RUNTIME , SIM_NEURAL_BACKEND_INPROCESS_LIBTORCH } |
| Supported neural inference backend families. More... | |
| enum | SimNeuralExecutionDevice { SIM_NEURAL_EXEC_DEVICE_CPU = 0 , SIM_NEURAL_EXEC_DEVICE_CUDA , SIM_NEURAL_EXEC_DEVICE_MPS } |
| Execution devices that can be requested for inference. More... | |
Functions | |
| SimNeuralModelConfig | sim_neural_model_config_defaults (void) |
| Return a default callback/CPU/deterministic model config. | |
| void | sim_neural_model_runtime_stats_reset (SimNeuralModelRuntimeStats *stats) |
| Reset runtime stats to their initial successful CPU state. | |
| const char * | sim_neural_backend_kind_name (SimNeuralBackendKind kind) |
| Return a stable name for a backend kind. | |
| bool | sim_neural_backend_kind_from_string (const char *text, SimNeuralBackendKind *out_kind) |
| Parse a backend kind name. | |
| const char * | sim_neural_execution_device_name (SimNeuralExecutionDevice device) |
| Return a stable name for an execution device. | |
| bool | sim_neural_execution_device_from_string (const char *text, SimNeuralExecutionDevice *out_device) |
| Parse an execution device name. | |
| bool | sim_neural_model_supports_device (const SimNeuralModelConfig *config, SimNeuralExecutionDevice device) |
| Test whether a model configuration supports a device. | |
| SimResult | sim_neural_model_registry_init (SimNeuralModelRegistry *registry) |
| Initialize an empty model registry. | |
| void | sim_neural_model_registry_destroy (SimNeuralModelRegistry *registry) |
| Destroy a model registry and release entry storage. | |
| SimResult | sim_neural_model_register (struct SimContext *context, const SimNeuralModelConfig *config, size_t *out_index) |
| Register or replace a neural model in a simulation context. | |
| size_t | sim_neural_model_count (const struct SimContext *context) |
| Return the number of registered models. | |
| SimResult | sim_neural_model_config_at (const struct SimContext *context, size_t model_index, SimNeuralModelConfig *out_config) |
| Copy model config by registry index. | |
| SimResult | sim_neural_model_stats_at (const struct SimContext *context, size_t model_index, SimNeuralModelRuntimeStats *out_stats) |
| Copy model runtime stats by registry index. | |
| SimResult | sim_neural_model_config (const struct SimContext *context, const char *model_id, SimNeuralModelConfig *out_config) |
| Copy model config by model id. | |
| SimResult | sim_neural_model_stats (const struct SimContext *context, const char *model_id, SimNeuralModelRuntimeStats *out_stats) |
| Copy model runtime stats by model id. | |
| SimResult | sim_neural_model_infer (struct SimContext *context, const char *model_id, const SimField *input, SimField *output, const SimNeuralInferenceRequest *request) |
| Run inference for a registered model. | |
Context-level neural model registry and execution helpers.
Neural model registrations bind a stable model id to either an in-process callback, an external process command, or a compiled backend placeholder. Runtime helpers choose devices, apply determinism policy, invoke inference, and keep per-model statistics inside SimContext.
| #define SIM_NEURAL_MODEL_COMMAND_MAX 255U |
Maximum external-process command length (excluding null terminator).
| #define SIM_NEURAL_MODEL_ERROR_MAX 191U |
Maximum stored runtime error length (excluding null terminator).
| #define SIM_NEURAL_MODEL_NOTE_MAX 127U |
Maximum free-form model note length (excluding null terminator).
| enum SimNeuralBackendKind |
Supported neural inference backend families.
| bool sim_neural_backend_kind_from_string | ( | const char * | text, |
| SimNeuralBackendKind * | out_kind | ||
| ) |
Parse a backend kind name.
Accepted aliases include "external-process", "process", "onnx", and "torch". Matching is case-insensitive.
| text | Text to parse. | |
| [out] | out_kind | Receives the parsed backend kind. |
| const char * sim_neural_backend_kind_name | ( | SimNeuralBackendKind | kind | ) |
Return a stable name for a backend kind.
Unknown values return "callback" for compatibility with the default backend.
| kind | Backend enum value. |
| bool sim_neural_execution_device_from_string | ( | const char * | text, |
| SimNeuralExecutionDevice * | out_device | ||
| ) |
Parse an execution device name.
Accepted aliases include "gpu" for CUDA and "metal" for MPS. Matching is case-insensitive.
| text | Text to parse. | |
| [out] | out_device | Receives the parsed device. |
| const char * sim_neural_execution_device_name | ( | SimNeuralExecutionDevice | device | ) |
Return a stable name for an execution device.
Unknown values return "cpu" for compatibility with default routing.
| device | Device enum value. |
| SimResult sim_neural_model_config | ( | const struct SimContext * | context, |
| const char * | model_id, | ||
| SimNeuralModelConfig * | out_config | ||
| ) |
Copy model config by model id.
| context | Context to inspect. | |
| model_id | Registered model id. | |
| [out] | out_config | Receives the stored config. |
| SimResult sim_neural_model_config_at | ( | const struct SimContext * | context, |
| size_t | model_index, | ||
| SimNeuralModelConfig * | out_config | ||
| ) |
Copy model config by registry index.
| context | Context to inspect. | |
| model_index | Registry index in [0, sim_neural_model_count()). | |
| [out] | out_config | Receives the stored config. |
| SimNeuralModelConfig sim_neural_model_config_defaults | ( | void | ) |
Return a default callback/CPU/deterministic model config.
| size_t sim_neural_model_count | ( | const struct SimContext * | context | ) |
Return the number of registered models.
| context | Context to inspect. |
context is NULL. | SimResult sim_neural_model_infer | ( | struct SimContext * | context, |
| const char * | model_id, | ||
| const SimField * | input, | ||
| SimField * | output, | ||
| const SimNeuralInferenceRequest * | request | ||
| ) |
Run inference for a registered model.
The effective request inherits the stored model id, default precision, and routeable device. Unsupported devices or strict determinism requests against non-deterministic models fail before backend invocation but still update model stats.
| context | Context containing the model registry and runtime clock. |
| model_id | Registered model id. |
| input | Input field passed to the backend; caller-owned. |
| output | Output field passed to the backend; caller-owned and mutable. |
| request | Optional inference request overrides. |
| SimResult sim_neural_model_register | ( | struct SimContext * | context, |
| const SimNeuralModelConfig * | config, | ||
| size_t * | out_index | ||
| ) |
Register or replace a neural model in a simulation context.
model_id must be non-empty. Callback configs require callback_fn; external process configs require external_command. Re-registering an existing model id replaces its config and resets its stats.
| context | Target simulation context. | |
| config | Model configuration to store. | |
| [out] | out_index | Optional receiver for the registry index. |
| void sim_neural_model_registry_destroy | ( | SimNeuralModelRegistry * | registry | ) |
Destroy a model registry and release entry storage.
| registry | Registry to destroy; NULL is ignored. |
| SimResult sim_neural_model_registry_init | ( | SimNeuralModelRegistry * | registry | ) |
Initialize an empty model registry.
| registry | Registry storage to initialize. |
| void sim_neural_model_runtime_stats_reset | ( | SimNeuralModelRuntimeStats * | stats | ) |
Reset runtime stats to their initial successful CPU state.
| stats | Stats object to reset; NULL is ignored. |
| SimResult sim_neural_model_stats | ( | const struct SimContext * | context, |
| const char * | model_id, | ||
| SimNeuralModelRuntimeStats * | out_stats | ||
| ) |
Copy model runtime stats by model id.
| context | Context to inspect. | |
| model_id | Registered model id. | |
| [out] | out_stats | Receives the stored stats. |
| SimResult sim_neural_model_stats_at | ( | const struct SimContext * | context, |
| size_t | model_index, | ||
| SimNeuralModelRuntimeStats * | out_stats | ||
| ) |
Copy model runtime stats by registry index.
| context | Context to inspect. | |
| model_index | Registry index in [0, sim_neural_model_count()). | |
| [out] | out_stats | Receives the stored stats. |
| bool sim_neural_model_supports_device | ( | const SimNeuralModelConfig * | config, |
| SimNeuralExecutionDevice | device | ||
| ) |
Test whether a model configuration supports a device.
A zero supported_device_mask is treated as CPU-only.
| config | Model configuration to inspect. |
| device | Requested device. |