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:

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