Edge AI Add-on API 2.2.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
178
179#if defined(CONFIG_NRF_EDGEAI_OBSV_METRIC_PROBS_DISTRIBUTION)
180
187typedef struct {
194 float bin_edges[CONFIG_NRF_EDGEAI_OBSV_PROBS_DISTRIBUTION_BIN_NUM - 1];
196
206typedef struct {
207 uint16_t num_classes;
208 uint8_t bin_num;
209 uint8_t _pad[1];
210} _nrf_obsv_pd_hdr_t;
211
212_Static_assert(sizeof(_nrf_obsv_pd_hdr_t) == 4,
213 "Layout changed; update NRF_EDGEAI_OBSV_PD_STORAGE_BYTES and storage accessors");
214
221#define NRF_EDGEAI_OBSV_PD_STORAGE_BYTES(n_classes) \
222 (sizeof(_nrf_obsv_pd_hdr_t) \
223 + ((size_t)CONFIG_NRF_EDGEAI_OBSV_PROBS_DISTRIBUTION_BIN_NUM - 1U) * sizeof(float) \
224 + (size_t)(n_classes) * CONFIG_NRF_EDGEAI_OBSV_PROBS_DISTRIBUTION_BIN_NUM \
225 * sizeof(uint32_t))
226
239 uint16_t n_classes);
240
241#endif /* CONFIG_NRF_EDGEAI_OBSV_METRIC_PROBS_DISTRIBUTION */
242
243#if defined(CONFIG_NRF_EDGEAI_OBSV_METRIC_TRANSITION_MATRIX)
244
254typedef struct {
255 uint16_t num_classes;
256 uint16_t prev;
257} _nrf_obsv_tm_hdr_t;
258
259_Static_assert(sizeof(_nrf_obsv_tm_hdr_t) == 4,
260 "Layout changed; update NRF_EDGEAI_OBSV_TM_STORAGE_BYTES and storage accessors");
261
268#define NRF_EDGEAI_OBSV_TM_STORAGE_BYTES(n_classes) \
269 (sizeof(_nrf_obsv_tm_hdr_t) + (size_t)(n_classes) * (size_t)(n_classes) * sizeof(uint32_t))
270
283 uint16_t n_classes);
284
285#endif /* CONFIG_NRF_EDGEAI_OBSV_METRIC_TRANSITION_MATRIX */
286
287#if defined(CONFIG_NRF_EDGEAI_OBSV_METRIC_PREDICTION_SWITCHING_RATE)
288
298typedef struct {
299 uint16_t num_classes;
300 uint16_t prev;
301} _nrf_obsv_psr_hdr_t;
302
303_Static_assert(sizeof(_nrf_obsv_psr_hdr_t) == 4,
304 "Layout changed; update NRF_EDGEAI_OBSV_PSR_STORAGE_BYTES and storage accessors");
305
316#define NRF_EDGEAI_OBSV_PSR_STORAGE_BYTES(n_classes) \
317 (sizeof(_nrf_obsv_psr_hdr_t) + 2U * sizeof(uint32_t))
318
336void nrf_edgeai_obsv_metric_psr_create(nrf_edgeai_obsv_metric_t *metric, void *buf,
337 uint16_t n_classes);
338
339#endif /* CONFIG_NRF_EDGEAI_OBSV_METRIC_PREDICTION_SWITCHING_RATE */
340
341#if defined(CONFIG_NRF_EDGEAI_OBSV_METRIC_PROBS_ENTROPY_DIST)
342
352typedef struct {
353 uint16_t num_classes;
354 uint8_t bin_num;
355 uint8_t _pad[1];
356} _nrf_obsv_ped_hdr_t;
357
358_Static_assert(sizeof(_nrf_obsv_ped_hdr_t) == 4,
359 "Layout changed; update NRF_EDGEAI_OBSV_PED_STORAGE_BYTES and storage accessors");
360
370#define NRF_EDGEAI_OBSV_PED_STORAGE_BYTES(n_classes) \
371 (sizeof(_nrf_obsv_ped_hdr_t) \
372 + (size_t)CONFIG_NRF_EDGEAI_OBSV_PROBS_ENTROPY_DIST_BIN_NUM * sizeof(uint32_t))
373
390void nrf_edgeai_obsv_metric_ped_create(nrf_edgeai_obsv_metric_t *metric, void *buf,
391 uint16_t n_classes);
392
393#endif /* CONFIG_NRF_EDGEAI_OBSV_METRIC_PROBS_ENTROPY_DIST */
394
395#if defined(CONFIG_NRF_EDGEAI_OBSV_METRIC_PROBS_TOP2_MARGIN_DIST)
396
406typedef struct {
407 uint16_t num_classes;
408 uint8_t bin_num;
409 uint8_t _pad[1];
410} _nrf_obsv_pmd_hdr_t;
411
412_Static_assert(sizeof(_nrf_obsv_pmd_hdr_t) == 4,
413 "Layout changed; update NRF_EDGEAI_OBSV_PMD_STORAGE_BYTES and storage accessors");
414
424#define NRF_EDGEAI_OBSV_PMD_STORAGE_BYTES(n_classes) \
425 (sizeof(_nrf_obsv_pmd_hdr_t) \
426 + (size_t)CONFIG_NRF_EDGEAI_OBSV_PROBS_TOP2_MARGIN_DIST_BIN_NUM * sizeof(uint32_t))
427
444void nrf_edgeai_obsv_metric_pmd_create(nrf_edgeai_obsv_metric_t *metric, void *buf,
445 uint16_t n_classes);
446
447#endif /* CONFIG_NRF_EDGEAI_OBSV_METRIC_PROBS_TOP2_MARGIN_DIST */
448
449#if defined(CONFIG_NRF_EDGEAI_OBSV_METRIC_MEL_ENERGY_DESC)
450
461typedef struct {
462 uint16_t num_features;
463 uint8_t bin_num;
464 uint8_t _pad[1];
465 float scale_min;
466 float scale_max;
467} _nrf_obsv_med_hdr_t;
468
469_Static_assert(sizeof(_nrf_obsv_med_hdr_t) == 12,
470 "Layout changed; update NRF_EDGEAI_OBSV_MED_STORAGE_BYTES and storage accessors");
471
473#define NRF_EDGEAI_OBSV_MED_NUM_ROWS 4
474
484#define NRF_EDGEAI_OBSV_MED_STORAGE_BYTES(n_features) \
485 (sizeof(_nrf_obsv_med_hdr_t) \
486 + (size_t)NRF_EDGEAI_OBSV_MED_NUM_ROWS \
487 * CONFIG_NRF_EDGEAI_OBSV_MEL_ENERGY_DESC_BIN_NUM * sizeof(uint32_t))
488
508void nrf_edgeai_obsv_metric_med_create(nrf_edgeai_obsv_metric_t *metric, void *buf,
509 uint16_t n_features);
510
511#endif /* CONFIG_NRF_EDGEAI_OBSV_METRIC_MEL_ENERGY_DESC */
512
513#if defined(CONFIG_NRF_EDGEAI_OBSV_METRIC_MEL_SPECTRAL_DESC)
514
525typedef struct {
526 uint16_t num_features;
527 uint8_t bin_num;
528 uint8_t _pad[1];
529} _nrf_obsv_msd_hdr_t;
530
531_Static_assert(sizeof(_nrf_obsv_msd_hdr_t) == 4,
532 "Layout changed; update NRF_EDGEAI_OBSV_MSD_STORAGE_BYTES and storage accessors");
533
535#define NRF_EDGEAI_OBSV_MSD_NUM_ROWS 8
536
546#define NRF_EDGEAI_OBSV_MSD_STORAGE_BYTES(n_features) \
547 (sizeof(_nrf_obsv_msd_hdr_t) \
548 + (size_t)NRF_EDGEAI_OBSV_MSD_NUM_ROWS \
549 * CONFIG_NRF_EDGEAI_OBSV_MEL_SPECTRAL_DESC_BIN_NUM * sizeof(uint32_t))
550
568void nrf_edgeai_obsv_metric_msd_create(nrf_edgeai_obsv_metric_t *metric, void *buf,
569 uint16_t n_features);
570
571#endif /* CONFIG_NRF_EDGEAI_OBSV_METRIC_MEL_SPECTRAL_DESC */
572
573#ifdef __cplusplus
574}
575#endif
576
577#endif /* NRF_EDGEAI_OBSV_METRICS_H */
578
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_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:187