nRF Edge AI runtime module
The nRF Edge AI Runtime library module provides a lightweight C library with interface for initializing and running machine learning models generated by the Nordic Edge AI Lab web tooling.
Overview
The runtime handles model setup, input feeding, inference execution, and output decoding. Models are generated using the Nordic Edge AI Lab web tooling and distributed as C source files that integrate with the nRF Connect SDK build system. For more information about integrating Nordic Edge AI Lab models, see nRF Edge AI Library integration. This model provides the following features:
Sets up model parameters and allocates necessary resources.
Accepts raw input data (sensor readings, signal samples) and prepares it for inference.
Runs the model’s inference pipeline to generate predictions.
Extracts and interprets model outputs for application use.
The runtime is designed to be portable and efficient, making it suitable for deployment on Nordic Semiconductor devices with constrained resources. It abstracts the complexities of model execution, allowing you to focus on application logic rather than low-level model handling.
Module structure
The runtime module (include/nrf_edgeai/rt/) is organized into several header files, each responsible for a specific part of the API or data structure:
nrf_edgeai_runtime.h- Core runtime API (init, feed inputs, run inference)nrf_edgeai_types.h- Type definitions (context, interfaces, metadata)nrf_edgeai_input_types.h- Input handling types and structuresnrf_edgeai_model_types.h- Model definitions and output structuresnrf_edgeai_output_types.h- Classification, regression, and anomaly output typesnrf_edgeai_dsp_pipeline_types.h- DSP pipeline configuration
Core API
The runtime API consists of a small number of essential functions for model inference:
Initialization and inference
nrf_edgeai_init()- Initializes the runtime (call once at startup).nrf_edgeai_feed_inputs()- Feeds raw input data (sensor readings, signal samples) to the model.nrf_edgeai_run_inference()- Executes the model inference pipeline, including features processing and compute predictions.
Input information
nrf_edgeai_input_type()- Gets the data type of input features (for example, int16, float32).nrf_edgeai_uniq_inputs_num()- Gets the number of unique input features the model expects.nrf_edgeai_input_window_size()- Gets the size of the input window (for time-series models).nrf_edgeai_input_subwindows_num()- Gets the number of subwindows in the input.
Model information
nrf_edgeai_model_neurons_num()- Gets the number of neurons in the model.nrf_edgeai_model_weights_num()- Gets the number of weights in the model.nrf_edgeai_model_outputs_num()- Gets the number of model outputs.nrf_edgeai_model_task()- Gets the model task type (classification, regression, anomaly detection).
Solution and version information
nrf_edgeai_solution_id_str()- Gets the solution ID string.nrf_edgeai_solution_runtime_version()- Gets the version of the solution runtime.nrf_edgeai_runtime_version()- Gets the version of the Edge AI library runtime.nrf_edgeai_is_runtime_compatible()- Checks version compatibility between library and solution.
Output access - After a successful
nrf_edgeai_run_inference(), results are available through thedecoded_outputmember of the context:p_edgeai->decoded_output.classif— Classification results (predicted class, probabilities, number of classes)p_edgeai->decoded_output.regression— Regression results (predicted values array, number of outputs)p_edgeai->decoded_output.anomaly— Anomaly detection results (anomaly score)
Model task types supported - The
nrf_edgeai_model_task_tenum specifies the model’s task.NRF_EDGEAI_TASK_MULT_CLASS— Multi-class classificationNRF_EDGEAI_TASK_BIN_CLASS— Binary classificationNRF_EDGEAI_TASK_REGRESSION— Regression (numeric prediction)NRF_EDGEAI_TASK_ANOMALY— Anomaly detection
Input types supported - Models accept input data of type
nrf_edgeai_input_type_t.NRF_EDGEAI_INPUT_I8— 8-bit signed integerNRF_EDGEAI_INPUT_I16— 16-bit signed integerNRF_EDGEAI_INPUT_F32— 32-bit floating-point
Example worklflow
The general integration sequence involves initializing the model, feeding input data, running inference, and accessing the results. The following example demonstrates this workflow:
#include <nrf_edgeai/nrf_edgeai.h>
#include <nrf_edgeai_generated/nrf_edgeai_user_model.h>
static nrf_edgeai_t* p_edgeai = NULL;
/* Initialize at startup */
void init_model(void)
{
p_edgeai = nrf_edgeai_user_model();
nrf_edgeai_init(p_edgeai);
}
/* Feed data and run inference */
void process_sensor_data(int16_t* sensor_readings, uint32_t count)
{
nrf_edgeai_err_t res = nrf_edgeai_feed_inputs(p_edgeai, sensor_readings, count);
if (res == NRF_EDGEAI_ERR_SUCCESS) {
res = nrf_edgeai_run_inference(p_edgeai);
if (res == NRF_EDGEAI_ERR_SUCCESS) {
/* Access results via p_edgeai->decoded_output */
}
}
}