Edge AI Add-on API 3.0.0
Loading...
Searching...
No Matches
nrf_edgeai_obsv_metrics.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2026 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
15#ifndef NRF_EDGEAI_OBSV_METRICS_H
16#define NRF_EDGEAI_OBSV_METRICS_H
17
18#include <stdbool.h>
19#include <stddef.h>
20#include <stdint.h>
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
49typedef struct {
51 uint32_t metric_id;
53 uint32_t version;
55 uint16_t num_rows;
57 uint16_t num_cols;
64 const uint32_t *counts;
66 uint16_t config_rows;
68 uint16_t config_cols;
75 const int32_t *config;
77
90 NRF_EDGEAI_OBSV_SOURCE_PROBS = 0, /* metric fed via nrf_edgeai_obsv_update_probs */
93};
94
111 void (*init)(const void *p_cfg, void *priv);
112
129 void (*update)(const float *p_data, uint16_t n, void *priv);
130
141 void (*clear)(void *priv);
142
150 void (*finalize)(void *priv);
151
166
176
178 void *priv;
179
183
194
195#if defined(CONFIG_NRF_EDGEAI_OBSV_METRIC_TRANSITION_MATRIX)
196
206typedef struct {
207 uint16_t num_classes;
208 uint16_t prev;
209} _nrf_obsv_tm_hdr_t;
210
211_Static_assert(sizeof(_nrf_obsv_tm_hdr_t) == 4,
212 "Layout changed; update NRF_EDGEAI_OBSV_TM_STORAGE_BYTES and storage accessors");
213
220#define NRF_EDGEAI_OBSV_TM_STORAGE_BYTES(n_classes) \
221 (sizeof(_nrf_obsv_tm_hdr_t) + (size_t)(n_classes) * (size_t)(n_classes) * sizeof(uint32_t))
222
235 uint16_t n_classes);
236
237#endif /* CONFIG_NRF_EDGEAI_OBSV_METRIC_TRANSITION_MATRIX */
238
239#if defined(CONFIG_NRF_EDGEAI_OBSV_METRIC_MODEL_CERTAINTY_DESC)
240
252typedef struct {
253 uint16_t num_classes;
254 uint16_t prev;
255 uint8_t bin_num;
256 uint8_t _pad[3];
257} _nrf_obsv_mcd_hdr_t;
258
259_Static_assert(sizeof(_nrf_obsv_mcd_hdr_t) == 8,
260 "Layout changed; update NRF_EDGEAI_OBSV_MCD_STORAGE_BYTES and storage accessors");
261
263#define NRF_EDGEAI_OBSV_MCD_NUM_ROWS 3
264
275#define NRF_EDGEAI_OBSV_MCD_STORAGE_BYTES(n_classes) \
276 (sizeof(_nrf_obsv_mcd_hdr_t) + \
277 (size_t)NRF_EDGEAI_OBSV_MCD_NUM_ROWS * \
278 CONFIG_NRF_EDGEAI_OBSV_MODEL_CERTAINTY_DESC_BIN_NUM * sizeof(uint32_t))
279
308 uint16_t n_classes);
309
310#endif /* CONFIG_NRF_EDGEAI_OBSV_METRIC_MODEL_CERTAINTY_DESC */
311
312#if defined(CONFIG_NRF_EDGEAI_OBSV_METRIC_MEL_ENERGY_DESC)
313
323
337typedef struct {
339 uint16_t num_features;
340 uint8_t bin_num;
341 uint8_t _pad[1];
342} _nrf_obsv_med_hdr_t;
343
344_Static_assert(sizeof(_nrf_obsv_med_hdr_t) == 12,
345 "Layout changed; update NRF_EDGEAI_OBSV_MED_STORAGE_BYTES and storage accessors");
346
348#define NRF_EDGEAI_OBSV_MED_NUM_ROWS 4
349
359#define NRF_EDGEAI_OBSV_MED_STORAGE_BYTES(n_features) \
360 (sizeof(_nrf_obsv_med_hdr_t) + (size_t)NRF_EDGEAI_OBSV_MED_NUM_ROWS * \
361 CONFIG_NRF_EDGEAI_OBSV_MEL_ENERGY_DESC_BIN_NUM * \
362 sizeof(uint32_t))
363
384 uint16_t n_features);
385
386#endif /* CONFIG_NRF_EDGEAI_OBSV_METRIC_MEL_ENERGY_DESC */
387
388#if defined(CONFIG_NRF_EDGEAI_OBSV_METRIC_MEL_SPECTRAL_DESC)
389
400typedef struct {
401 uint16_t num_features;
402 uint8_t bin_num;
403 uint8_t _pad[1];
404} _nrf_obsv_msd_hdr_t;
405
406_Static_assert(sizeof(_nrf_obsv_msd_hdr_t) == 4,
407 "Layout changed; update NRF_EDGEAI_OBSV_MSD_STORAGE_BYTES and storage accessors");
408
410#define NRF_EDGEAI_OBSV_MSD_NUM_ROWS 8
411
421#define NRF_EDGEAI_OBSV_MSD_STORAGE_BYTES(n_features) \
422 (sizeof(_nrf_obsv_msd_hdr_t) + (size_t)NRF_EDGEAI_OBSV_MSD_NUM_ROWS * \
423 CONFIG_NRF_EDGEAI_OBSV_MEL_SPECTRAL_DESC_BIN_NUM * \
424 sizeof(uint32_t))
425
444 uint16_t n_features);
445
446#endif /* CONFIG_NRF_EDGEAI_OBSV_METRIC_MEL_SPECTRAL_DESC */
447
448#if defined(CONFIG_NRF_EDGEAI_OBSV_METRIC_CLASS_PRED_DIST)
449
459
475typedef struct {
477 uint16_t num_classes;
478 uint16_t cur_class;
479 uint16_t alt_class;
480 uint8_t bin_num;
481 uint8_t cur_len;
482 uint8_t cur_miss;
483 uint8_t alt_len;
484 uint8_t _pad[2];
485} _nrf_obsv_cpd_hdr_t;
486
487_Static_assert(sizeof(_nrf_obsv_cpd_hdr_t) == 20,
488 "Layout changed; update NRF_EDGEAI_OBSV_CPD_STORAGE_BYTES and storage accessors");
489
491#define NRF_EDGEAI_OBSV_CPD_ROW_GROUPS 2
492
502#define NRF_EDGEAI_OBSV_CPD_STORAGE_BYTES(n_classes) \
503 (sizeof(_nrf_obsv_cpd_hdr_t) + (size_t)NRF_EDGEAI_OBSV_CPD_ROW_GROUPS * (n_classes) * \
504 CONFIG_NRF_EDGEAI_OBSV_CLASS_PRED_DIST_BIN_NUM * \
505 sizeof(uint32_t))
506
539 uint16_t n_classes);
540
541#endif /* CONFIG_NRF_EDGEAI_OBSV_METRIC_CLASS_PRED_DIST */
542
543#ifdef __cplusplus
544}
545#endif
546
547#endif /* NRF_EDGEAI_OBSV_METRICS_H */
548
void nrf_edgeai_obsv_metric_mcd_create(nrf_edgeai_obsv_metric_t *metric, void *buf, uint16_t n_classes)
Initialize a model certainty descriptor metric using caller-provided storage.
void nrf_edgeai_obsv_metric_med_create(nrf_edgeai_obsv_metric_t *metric, void *buf, uint16_t n_features)
Initialize a mel energy descriptor metric using caller-provided storage.
nrf_edgeai_obsv_cpd_config
Layout of the config row reported by the class predictions distribution.
Definition nrf_edgeai_obsv_metrics.h:451
@ NRF_EDGEAI_OBSV_CPD_CFG_STREAK_TOP
Streak length saturating the top streak bin (STREAK_TOP_BIN).
Definition nrf_edgeai_obsv_metrics.h:453
@ NRF_EDGEAI_OBSV_CPD_CFG_STREAK_TOL
Flicker tolerance, in bridged frames (STREAK_TOL).
Definition nrf_edgeai_obsv_metrics.h:455
@ NRF_EDGEAI_OBSV_CPD_CFG_COUNT
Number of config values (columns of the single config row).
Definition nrf_edgeai_obsv_metrics.h:457
nrf_edgeai_obsv_med_config
Layout of the config row reported by the mel energy descriptor.
Definition nrf_edgeai_obsv_metrics.h:315
@ NRF_EDGEAI_OBSV_MED_CFG_COUNT
Number of config values (columns of the single config row).
Definition nrf_edgeai_obsv_metrics.h:321
@ NRF_EDGEAI_OBSV_MED_CFG_SCALE_P01_MILLI
Lower scaling percentile p01, thousandths of a feature unit.
Definition nrf_edgeai_obsv_metrics.h:317
@ NRF_EDGEAI_OBSV_MED_CFG_SCALE_P99_MILLI
Upper scaling percentile p99, thousandths of a feature unit.
Definition nrf_edgeai_obsv_metrics.h:319
nrf_edgeai_obsv_source
Data stream a metric consumes.
Definition nrf_edgeai_obsv_metrics.h:88
@ NRF_EDGEAI_OBSV_SOURCE_PROBS
Model output: class-probability vector (length == num_classes).
Definition nrf_edgeai_obsv_metrics.h:90
@ NRF_EDGEAI_OBSV_SOURCE_FEATURES
Model input: extracted feature vector (length supplied per update).
Definition nrf_edgeai_obsv_metrics.h:92
void nrf_edgeai_obsv_metric_msd_create(nrf_edgeai_obsv_metric_t *metric, void *buf, uint16_t n_features)
Initialize a mel spectral descriptor metric using caller-provided storage.
void nrf_edgeai_obsv_metric_cpd_create(nrf_edgeai_obsv_metric_t *metric, void *buf, uint16_t n_classes)
Initialize a class predictions distribution metric using caller-provided storage.
nrf_edgeai_obsv_metric_id
Metric identifier values emitted by each metric's snapshot.
Definition nrf_edgeai_obsv_metrics.h:187
@ NRF_EDGEAI_OBSV_METRIC_ID_MEL_SPECTRAL_DESC
Definition nrf_edgeai_obsv_metrics.h:192
@ NRF_EDGEAI_OBSV_METRIC_ID_TRANSITION_MATRIX
Definition nrf_edgeai_obsv_metrics.h:190
@ NRF_EDGEAI_OBSV_METRIC_ID_MODEL_CERTAINTY_DESC
Definition nrf_edgeai_obsv_metrics.h:188
@ NRF_EDGEAI_OBSV_METRIC_ID_CLASS_PRED_DIST
Definition nrf_edgeai_obsv_metrics.h:189
@ NRF_EDGEAI_OBSV_METRIC_ID_MEL_ENERGY_DESC
Definition nrf_edgeai_obsv_metrics.h:191
void nrf_edgeai_obsv_metric_tm_create(nrf_edgeai_obsv_metric_t *metric, void *buf, uint16_t n_classes)
Initialize a transition matrix metric using caller-provided storage.
struct nrf_edgeai_obsv_metric_s nrf_edgeai_obsv_metric_t
Observability metric operation table and list node.
void(* snapshot)(nrf_edgeai_obsv_metric_snapshot_t *out, void *priv)
Populates a read-only view over the metric's counters.
Definition nrf_edgeai_obsv_metrics.h:165
struct nrf_edgeai_obsv_metric_s * p_next
Pointer to next metric in context list.
Definition nrf_edgeai_obsv_metrics.h:181
void(* init)(const void *p_cfg, void *priv)
Initializes metric internal state.
Definition nrf_edgeai_obsv_metrics.h:111
enum nrf_edgeai_obsv_source source
Data stream this metric consumes (nrf_edgeai_obsv_source).
Definition nrf_edgeai_obsv_metrics.h:175
void(* finalize)(void *priv)
Finalizes metric state before a snapshot is taken.
Definition nrf_edgeai_obsv_metrics.h:150
void * priv
Opaque per-instance storage; set by the define macro.
Definition nrf_edgeai_obsv_metrics.h:178
void(* clear)(void *priv)
Resets accumulated counters without touching configuration.
Definition nrf_edgeai_obsv_metrics.h:141
void(* update)(const float *p_data, uint16_t n, void *priv)
Consumes one data vector from the metric's source stream.
Definition nrf_edgeai_obsv_metrics.h:129
Observability metric operation table and list node.
Definition nrf_edgeai_obsv_metrics.h:105
uint16_t num_rows
Number of rows in the counter matrix.
Definition nrf_edgeai_obsv_metrics.h:55
uint16_t config_rows
Number of rows in the config matrix (0 = no configuration reported).
Definition nrf_edgeai_obsv_metrics.h:66
uint16_t num_cols
Number of columns in the counter matrix.
Definition nrf_edgeai_obsv_metrics.h:57
uint32_t version
Metric payload version.
Definition nrf_edgeai_obsv_metrics.h:53
uint32_t metric_id
On-wire metric identifier.
Definition nrf_edgeai_obsv_metrics.h:51
const uint32_t * counts
Row-major counter matrix, num_rows x num_cols uint32s.
Definition nrf_edgeai_obsv_metrics.h:64
const int32_t * config
Row-major config matrix, config_rows x config_cols int32s.
Definition nrf_edgeai_obsv_metrics.h:75
uint16_t config_cols
Number of columns in the config matrix.
Definition nrf_edgeai_obsv_metrics.h:68
Read-only view over one metric's accumulated counters.
Definition nrf_edgeai_obsv_metrics.h:49