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 structures

  • nrf_edgeai_model_types.h - Model definitions and output structures

  • nrf_edgeai_output_types.h - Classification, regression, and anomaly output types

  • nrf_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

  • Input information

  • 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

  • Output access - After a successful nrf_edgeai_run_inference(), results are available through the decoded_output member 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_t enum specifies the model’s task.

    • NRF_EDGEAI_TASK_MULT_CLASS — Multi-class classification

    • NRF_EDGEAI_TASK_BIN_CLASS — Binary classification

    • NRF_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 integer

    • NRF_EDGEAI_INPUT_I16 — 16-bit signed integer

    • NRF_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 */
        }
    }
}