Edge AI Add-on API 2.3.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
42typedef struct {
44 uint32_t metric_id;
46 uint32_t version;
48 uint16_t num_rows;
50 uint16_t num_cols;
57 const uint32_t *counts;
59
72 NRF_EDGEAI_OBSV_SOURCE_PROBS = 0, /* metric fed via nrf_edgeai_obsv_update_probs */
75};
76
93 void (*init)(const void *p_cfg, void *priv);
94
111 void (*update)(const float *p_data, uint16_t n, void *priv);
112
123 void (*clear)(void *priv);
124
132 void (*finalize)(void *priv);
133
148
158
160 void *priv;
161
165
179
180#if defined(CONFIG_NRF_EDGEAI_OBSV_METRIC_PROBS_DISTRIBUTION)
181
188typedef struct {
195 float bin_edges[CONFIG_NRF_EDGEAI_OBSV_PROBS_DISTRIBUTION_BIN_NUM - 1];
197
207typedef struct {
208 uint16_t num_classes;
209 uint8_t bin_num;
210 uint8_t _pad[1];
211} _nrf_obsv_pd_hdr_t;
212
213_Static_assert(sizeof(_nrf_obsv_pd_hdr_t) == 4,
214 "Layout changed; update NRF_EDGEAI_OBSV_PD_STORAGE_BYTES and storage accessors");
215
222#define NRF_EDGEAI_OBSV_PD_STORAGE_BYTES(n_classes) \
223 (sizeof(_nrf_obsv_pd_hdr_t) \
224 + ((size_t)CONFIG_NRF_EDGEAI_OBSV_PROBS_DISTRIBUTION_BIN_NUM - 1U) * sizeof(float) \
225 + (size_t)(n_classes) * CONFIG_NRF_EDGEAI_OBSV_PROBS_DISTRIBUTION_BIN_NUM \
226 * sizeof(uint32_t))
227
240 uint16_t n_classes);
241
242#endif /* CONFIG_NRF_EDGEAI_OBSV_METRIC_PROBS_DISTRIBUTION */
243
244#if defined(CONFIG_NRF_EDGEAI_OBSV_METRIC_TRANSITION_MATRIX)
245
255typedef struct {
256 uint16_t num_classes;
257 uint16_t prev;
258} _nrf_obsv_tm_hdr_t;
259
260_Static_assert(sizeof(_nrf_obsv_tm_hdr_t) == 4,
261 "Layout changed; update NRF_EDGEAI_OBSV_TM_STORAGE_BYTES and storage accessors");
262
269#define NRF_EDGEAI_OBSV_TM_STORAGE_BYTES(n_classes) \
270 (sizeof(_nrf_obsv_tm_hdr_t) + (size_t)(n_classes) * (size_t)(n_classes) * sizeof(uint32_t))
271
284 uint16_t n_classes);
285
286#endif /* CONFIG_NRF_EDGEAI_OBSV_METRIC_TRANSITION_MATRIX */
287
288#if defined(CONFIG_NRF_EDGEAI_OBSV_METRIC_PREDICTION_SWITCHING_RATE)
289
299typedef struct {
300 uint16_t num_classes;
301 uint16_t prev;
302} _nrf_obsv_psr_hdr_t;
303
304_Static_assert(sizeof(_nrf_obsv_psr_hdr_t) == 4,
305 "Layout changed; update NRF_EDGEAI_OBSV_PSR_STORAGE_BYTES and storage accessors");
306
317#define NRF_EDGEAI_OBSV_PSR_STORAGE_BYTES(n_classes) \
318 (sizeof(_nrf_obsv_psr_hdr_t) + 2U * sizeof(uint32_t))
319
337void nrf_edgeai_obsv_metric_psr_create(nrf_edgeai_obsv_metric_t *metric, void *buf,
338 uint16_t n_classes);
339
340#endif /* CONFIG_NRF_EDGEAI_OBSV_METRIC_PREDICTION_SWITCHING_RATE */
341
342#if defined(CONFIG_NRF_EDGEAI_OBSV_METRIC_PROBS_ENTROPY_DIST)
343
353typedef struct {
354 uint16_t num_classes;
355 uint8_t bin_num;
356 uint8_t _pad[1];
357} _nrf_obsv_ped_hdr_t;
358
359_Static_assert(sizeof(_nrf_obsv_ped_hdr_t) == 4,
360 "Layout changed; update NRF_EDGEAI_OBSV_PED_STORAGE_BYTES and storage accessors");
361
371#define NRF_EDGEAI_OBSV_PED_STORAGE_BYTES(n_classes) \
372 (sizeof(_nrf_obsv_ped_hdr_t) \
373 + (size_t)CONFIG_NRF_EDGEAI_OBSV_PROBS_ENTROPY_DIST_BIN_NUM * sizeof(uint32_t))
374
391void nrf_edgeai_obsv_metric_ped_create(nrf_edgeai_obsv_metric_t *metric, void *buf,
392 uint16_t n_classes);
393
394#endif /* CONFIG_NRF_EDGEAI_OBSV_METRIC_PROBS_ENTROPY_DIST */
395
396#if defined(CONFIG_NRF_EDGEAI_OBSV_METRIC_PROBS_TOP2_MARGIN_DIST)
397
407typedef struct {
408 uint16_t num_classes;
409 uint8_t bin_num;
410 uint8_t _pad[1];
411} _nrf_obsv_pmd_hdr_t;
412
413_Static_assert(sizeof(_nrf_obsv_pmd_hdr_t) == 4,
414 "Layout changed; update NRF_EDGEAI_OBSV_PMD_STORAGE_BYTES and storage accessors");
415
425#define NRF_EDGEAI_OBSV_PMD_STORAGE_BYTES(n_classes) \
426 (sizeof(_nrf_obsv_pmd_hdr_t) \
427 + (size_t)CONFIG_NRF_EDGEAI_OBSV_PROBS_TOP2_MARGIN_DIST_BIN_NUM * sizeof(uint32_t))
428
445void nrf_edgeai_obsv_metric_pmd_create(nrf_edgeai_obsv_metric_t *metric, void *buf,
446 uint16_t n_classes);
447
448#endif /* CONFIG_NRF_EDGEAI_OBSV_METRIC_PROBS_TOP2_MARGIN_DIST */
449
450#if defined(CONFIG_NRF_EDGEAI_OBSV_METRIC_MEL_ENERGY_DESC)
451
462typedef struct {
463 uint16_t num_features;
464 uint8_t bin_num;
465 uint8_t _pad[1];
466 float scale_min;
467 float scale_max;
468} _nrf_obsv_med_hdr_t;
469
470_Static_assert(sizeof(_nrf_obsv_med_hdr_t) == 12,
471 "Layout changed; update NRF_EDGEAI_OBSV_MED_STORAGE_BYTES and storage accessors");
472
474#define NRF_EDGEAI_OBSV_MED_NUM_ROWS 4
475
485#define NRF_EDGEAI_OBSV_MED_STORAGE_BYTES(n_features) \
486 (sizeof(_nrf_obsv_med_hdr_t) \
487 + (size_t)NRF_EDGEAI_OBSV_MED_NUM_ROWS \
488 * CONFIG_NRF_EDGEAI_OBSV_MEL_ENERGY_DESC_BIN_NUM * sizeof(uint32_t))
489
509void nrf_edgeai_obsv_metric_med_create(nrf_edgeai_obsv_metric_t *metric, void *buf,
510 uint16_t n_features);
511
512#endif /* CONFIG_NRF_EDGEAI_OBSV_METRIC_MEL_ENERGY_DESC */
513
514#if defined(CONFIG_NRF_EDGEAI_OBSV_METRIC_MEL_SPECTRAL_DESC)
515
526typedef struct {
527 uint16_t num_features;
528 uint8_t bin_num;
529 uint8_t _pad[1];
530} _nrf_obsv_msd_hdr_t;
531
532_Static_assert(sizeof(_nrf_obsv_msd_hdr_t) == 4,
533 "Layout changed; update NRF_EDGEAI_OBSV_MSD_STORAGE_BYTES and storage accessors");
534
536#define NRF_EDGEAI_OBSV_MSD_NUM_ROWS 8
537
547#define NRF_EDGEAI_OBSV_MSD_STORAGE_BYTES(n_features) \
548 (sizeof(_nrf_obsv_msd_hdr_t) \
549 + (size_t)NRF_EDGEAI_OBSV_MSD_NUM_ROWS \
550 * CONFIG_NRF_EDGEAI_OBSV_MEL_SPECTRAL_DESC_BIN_NUM * sizeof(uint32_t))
551
569void nrf_edgeai_obsv_metric_msd_create(nrf_edgeai_obsv_metric_t *metric, void *buf,
570 uint16_t n_features);
571
572#endif /* CONFIG_NRF_EDGEAI_OBSV_METRIC_MEL_SPECTRAL_DESC */
573
574#if defined(CONFIG_NRF_EDGEAI_OBSV_METRIC_CLASS_STREAK_DIST)
575
588typedef struct {
589 uint16_t num_classes;
590 uint16_t cur_class;
591 uint8_t bin_num;
592 uint8_t top;
593 uint8_t tolerance;
594 uint8_t cur_len;
595 uint8_t cur_miss;
596 uint8_t _pad[3];
597} _nrf_obsv_csd_hdr_t;
598
599_Static_assert(sizeof(_nrf_obsv_csd_hdr_t) == 12,
600 "Layout changed; update NRF_EDGEAI_OBSV_CSD_STORAGE_BYTES and storage accessors");
601
608#define NRF_EDGEAI_OBSV_CSD_STORAGE_BYTES(n_classes) \
609 (sizeof(_nrf_obsv_csd_hdr_t) \
610 + (size_t)(n_classes) * CONFIG_NRF_EDGEAI_OBSV_CLASS_STREAK_DIST_BIN_NUM \
611 * sizeof(uint32_t))
612
634void nrf_edgeai_obsv_metric_csd_create(nrf_edgeai_obsv_metric_t *metric, void *buf,
635 uint16_t n_classes);
636
637#endif /* CONFIG_NRF_EDGEAI_OBSV_METRIC_CLASS_STREAK_DIST */
638
639#ifdef __cplusplus
640}
641#endif
642
643#endif /* NRF_EDGEAI_OBSV_METRICS_H */
644
nrf_edgeai_obsv_source
Data stream a metric consumes.
Definition nrf_edgeai_obsv_metrics.h:70
@ NRF_EDGEAI_OBSV_SOURCE_PROBS
Model output: class-probability vector (length == num_classes).
Definition nrf_edgeai_obsv_metrics.h:72
@ NRF_EDGEAI_OBSV_SOURCE_FEATURES
Model input: extracted feature vector (length supplied per update).
Definition nrf_edgeai_obsv_metrics.h:74
void nrf_edgeai_obsv_metric_pd_create(nrf_edgeai_obsv_metric_t *metric, void *buf, uint16_t n_classes)
Initialize a probability 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:169
@ NRF_EDGEAI_OBSV_METRIC_ID_PREDICTION_SWITCHING_RATE
Definition nrf_edgeai_obsv_metrics.h:172
@ NRF_EDGEAI_OBSV_METRIC_ID_MEL_SPECTRAL_DESC
Definition nrf_edgeai_obsv_metrics.h:176
@ NRF_EDGEAI_OBSV_METRIC_ID_TRANSITION_MATRIX
Definition nrf_edgeai_obsv_metrics.h:170
@ NRF_EDGEAI_OBSV_METRIC_ID_MEL_ENERGY_DESC
Definition nrf_edgeai_obsv_metrics.h:175
@ NRF_EDGEAI_OBSV_METRIC_ID_PROBS_TOP2_MARGIN_DIST
Definition nrf_edgeai_obsv_metrics.h:174
@ NRF_EDGEAI_OBSV_METRIC_ID_CLASS_STREAK_DIST
Definition nrf_edgeai_obsv_metrics.h:177
@ NRF_EDGEAI_OBSV_METRIC_ID_PROBS_DISTRIBUTION
Definition nrf_edgeai_obsv_metrics.h:171
@ NRF_EDGEAI_OBSV_METRIC_ID_PROBS_ENTROPY_DIST
Definition nrf_edgeai_obsv_metrics.h:173
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:147
struct nrf_edgeai_obsv_metric_s * p_next
Pointer to next metric in context list.
Definition nrf_edgeai_obsv_metrics.h:163
void(* init)(const void *p_cfg, void *priv)
Initializes metric internal state.
Definition nrf_edgeai_obsv_metrics.h:93
enum nrf_edgeai_obsv_source source
Data stream this metric consumes (nrf_edgeai_obsv_source).
Definition nrf_edgeai_obsv_metrics.h:157
void(* finalize)(void *priv)
Finalizes metric state before a snapshot is taken.
Definition nrf_edgeai_obsv_metrics.h:132
void * priv
Opaque per-instance storage; set by the define macro.
Definition nrf_edgeai_obsv_metrics.h:160
void(* clear)(void *priv)
Resets accumulated counters without touching configuration.
Definition nrf_edgeai_obsv_metrics.h:123
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:111
Observability metric operation table and list node.
Definition nrf_edgeai_obsv_metrics.h:87
uint16_t num_rows
Number of rows in the counter matrix.
Definition nrf_edgeai_obsv_metrics.h:48
uint16_t num_cols
Number of columns in the counter matrix.
Definition nrf_edgeai_obsv_metrics.h:50
uint32_t version
Metric payload version.
Definition nrf_edgeai_obsv_metrics.h:46
uint32_t metric_id
On-wire metric identifier.
Definition nrf_edgeai_obsv_metrics.h:44
const uint32_t * counts
Row-major counter matrix, num_rows x num_cols uint32s.
Definition nrf_edgeai_obsv_metrics.h:57
Read-only view over one metric's accumulated counters.
Definition nrf_edgeai_obsv_metrics.h:42
Runtime configuration for probability distribution metric.
Definition nrf_edgeai_obsv_metrics.h:188