Edge AI Add-on API 2.2.0
Loading...
Searching...
No Matches
nrf_axon_nn_infer.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
6
7#pragma once
8
9#ifdef __cplusplus
10extern "C" {
11#endif
12#include <stdarg.h>
13#include <stdint.h>
14#include "nrf_axon_driver.h"
15
16
20typedef struct {
21 uint16_t height;
22 uint16_t width;
23 uint16_t channel_cnt;
24 uint8_t byte_width;
26
50
56typedef struct {
58 int8_t *buf_ptr;
60 uint32_t buf_size;
64 uint8_t byte_width;
66
97
102#define NRF_AXON_NN_MAX_MODEL_INPUTS 2
193
194#define NRF_AXON_COMPILED_MODEL_EXTRA_OUTPUT_CNT(compiled_model) \
195 (compiled_model->compiler_version >= 0x10200 ? compiled_model->extra_output_cnt : 0)
196
209 const nrf_axon_nn_compiled_model_s *the_model);
210
222 const nrf_axon_nn_compiled_model_s *the_model);
223
239 const nrf_axon_nn_compiled_model_s *compiled_model);
240
241
252 const nrf_axon_nn_compiled_model_s *compiled_model);
253
284 const nrf_axon_nn_compiled_model_s *compiled_model,
285 const int8_t *input_vector,
286 int8_t *output_buffer);
287
288
302
328
343 const nrf_axon_nn_compiled_model_s *compiled_model);
344
353
354/*
355 * @brief Starts an asynchronous inference on the provided model.
356
357 * In asynchonous mode, models are inferred in a separate thread, one after another.
358 * User provides input vector and output buffer information as the interlayer buffer
359 * is used by all models, so only when it is this model's turn to execute can its
360 * input be populated from the input_vector.
361 *
362 * Upon completion of inference the next job is queued before the user callback is invoked,
363 * so the results have to be copied by the driver to the output_buffer before invoking the
364 * user callback.
365 *
366 * @param[in] model_wrapper Model to run inference on, initialized via a one-time call to nrf_axon_nn_model_async_init.
367 * @param[in] input_vector Input to run inference on. It is not consumed immediately so has to be in memory that is valid as long as inference is occurring.
368 * @param[in] output_buffer buffer to copy inference results to.
369 * @param[in] inference_callback Function to invoke when inference has completed.
370 * @param[in] callback_context Opaque pointer provided to inference_callback.
371 * @retval[0] Inference successfully queued.
372 * @retval[NRF_AXON_RESULT_NOT_FINISHED] Model is still busy with an ealier inference
373 * @retval[<0] Error code.
374 */
377 const int8_t *input_vector,
378 int8_t *output_buffer,
379 void (*inference_callback)(nrf_axon_result_e result, void *callback_context),
380 void *callback_context);
381
397 const nrf_axon_nn_compiled_model_s *compiled_model,
398 const int8_t *packed_output,
399 const char **label, int32_t *score);
400
420 const nrf_axon_nn_compiled_model_s *compiled_model,
421 const int8_t *input_vector);
422
437 const nrf_axon_nn_compiled_model_s *compiled_model,
438 uint8_t output_ndx);
439
457 const nrf_axon_nn_compiled_model_s *compiled_model,
458 void *to_buffer);
459
460#ifdef __cplusplus
461} /* extern "C" { */
462#endif
nrf_axon_result_e
Axon driver return codes.
Definition nrf_axon_driver.h:86
uint32_t NRF_AXON_PLATFORM_BITWIDTH_UNSIGNED_TYPE
Definition nrf_axon_driver.h:76
int nrf_axon_nn_offset_to_output_ndx(const nrf_axon_nn_compiled_model_s *compiled_model, uint8_t output_ndx)
Returns the offset into the packed output buffer filled for the start of a particular output node ind...
int8_t nrf_axon_nn_model_1st_external_input_ndx(const nrf_axon_nn_compiled_model_s *the_model)
returns the nrf_axon_nn_compiled_model_input_s instance of the model's input that is external.
struct nrf_axon_compiled_model_output_tag_s nrf_axon_compiled_model_output_s
nrf_axon_result_e nrf_axon_nn_model_infer_sync(const nrf_axon_nn_compiled_model_s *compiled_model, const int8_t *input_vector, int8_t *output_buffer)
Blocking inference function of a compiled model.
nrf_axon_result_e nrf_axon_nn_model_async_init(nrf_axon_nn_model_async_inference_wrapper_s *model_wrapper, const nrf_axon_nn_compiled_model_s *compiled_model)
Initialize a model for asynchronous inference. Calls nrf_axon_nn_model_validate then binds the model ...
int nrf_axon_nn_model_init_vars(const nrf_axon_nn_compiled_model_s *compiled_model)
Initialize all the persistent var buffers in a streaming-style model (with VarHandle/ReadVariable/Ass...
struct nrf_axon_nn_compiled_model_tag_s nrf_axon_nn_compiled_model_s
nrf_axon_nn_async_inference_status_e
Asynchronous inference states.
Definition nrf_axon_nn_infer.h:294
@ NRF_AXON_NN_ASYNC_INFERENCE_STATUS_IDLE
Definition nrf_axon_nn_infer.h:296
@ NRF_AXON_NN_ASYNC_INFERENCE_STATUS_COMPLETE
Definition nrf_axon_nn_infer.h:300
@ NRF_AXON_NN_ASYNC_INFERENCE_STATUS_ACTIVE
Definition nrf_axon_nn_infer.h:298
nrf_axon_result_e nrf_axon_nn_model_infer_async(nrf_axon_nn_model_async_inference_wrapper_s *model_wrapper, const int8_t *input_vector, int8_t *output_buffer, void(*inference_callback)(nrf_axon_result_e result, void *callback_context), void *callback_context)
#define NRF_AXON_NN_MAX_MODEL_INPUTS
Definition nrf_axon_nn_infer.h:102
const nrf_axon_nn_compiled_model_input_s * nrf_axon_nn_model_1st_external_input(const nrf_axon_nn_compiled_model_s *the_model)
returns the index of the model's input that is external.
void nrf_axon_nn_copy_output_to_packed_buffer(const nrf_axon_nn_compiled_model_s *compiled_model, void *to_buffer)
Copies and packs the model inference output from the common interlayer buffer to the users dedicated ...
nrf_axon_nn_async_inference_status_e nrf_axon_nn_get_model_async_infer_status(const nrf_axon_nn_model_async_inference_wrapper_s *model_wrapper)
Returns the model inference status of an asynchronous inference.
int16_t nrf_axon_nn_get_classification(const nrf_axon_nn_compiled_model_s *compiled_model, const int8_t *packed_output, const char **label, int32_t *score)
Gets the inference results for a classification model.
nrf_axon_result_e nrf_axon_nn_populate_input_vector(const nrf_axon_nn_compiled_model_s *compiled_model, const int8_t *input_vector)
Copies model input from input_vector to the location in the interlayer buffer the model expects.
nrf_axon_result_e nrf_axon_nn_model_validate(const nrf_axon_nn_compiled_model_s *compiled_model)
Sanity check of a compiled model.
Internal structure supplied by user but managed by the driver to track execution progress.
Definition nrf_axon_driver.h:124
int8_t * ptr
Definition nrf_axon_nn_infer.h:78
uint16_t stride
Definition nrf_axon_nn_infer.h:95
nrf_axon_nn_model_layer_dimensions_s dimensions
Definition nrf_axon_nn_infer.h:79
uint32_t dequant_mult
Definition nrf_axon_nn_infer.h:87
uint8_t dequant_round
Definition nrf_axon_nn_infer.h:89
int8_t dequant_zp
Definition nrf_axon_nn_infer.h:91
Definition nrf_axon_nn_infer.h:76
int8_t * ptr
Definition nrf_axon_nn_infer.h:32
uint8_t quant_round
Definition nrf_axon_nn_infer.h:43
uint32_t quant_mult
Definition nrf_axon_nn_infer.h:39
nrf_axon_nn_model_layer_dimensions_s dimensions
Definition nrf_axon_nn_infer.h:34
uint16_t stride
Definition nrf_axon_nn_infer.h:41
int8_t quant_zp
Definition nrf_axon_nn_infer.h:45
bool is_external
Definition nrf_axon_nn_infer.h:48
Definition nrf_axon_nn_infer.h:30
int8_t * buf_ptr
Definition nrf_axon_nn_infer.h:151
struct nrf_axon_nn_compiled_model_tag_s::@3 persistent_vars
const nrf_axon_nn_model_persistent_var_s * vars
Definition nrf_axon_nn_infer.h:155
uint32_t model_const_size
Definition nrf_axon_nn_infer.h:143
const NRF_AXON_PLATFORM_BITWIDTH_UNSIGNED_TYPE * cmd_buffer_ptr
Definition nrf_axon_nn_infer.h:139
int8_t * output_ptr
Definition nrf_axon_nn_infer.h:125
uint32_t interlayer_buffer_needed
Definition nrf_axon_nn_infer.h:133
int8_t output_dequant_zp
Definition nrf_axon_nn_infer.h:173
uint32_t psum_buffer_needed
Definition nrf_axon_nn_infer.h:137
uint16_t output_stride
Definition nrf_axon_nn_infer.h:177
nrf_axon_nn_model_layer_dimensions_s output_dimensions
Definition nrf_axon_nn_infer.h:160
int8_t * packed_output_buf
Definition nrf_axon_nn_infer.h:129
uint16_t extra_output_cnt
Definition nrf_axon_nn_infer.h:187
bool is_layer_model
Definition nrf_axon_nn_infer.h:181
uint32_t compiler_version
Definition nrf_axon_nn_infer.h:107
uint32_t buf_size
Definition nrf_axon_nn_infer.h:153
uint8_t output_dequant_round
Definition nrf_axon_nn_infer.h:171
nrf_axon_nn_compiled_model_input_s inputs[2]
Definition nrf_axon_nn_infer.h:115
int8_t external_input_ndx
Definition nrf_axon_nn_infer.h:121
uint16_t count
Definition nrf_axon_nn_infer.h:157
const nrf_axon_compiled_model_output_s * extra_outputs
Definition nrf_axon_nn_infer.h:189
uint32_t min_driver_version_required
Definition nrf_axon_nn_infer.h:191
const char * model_name
Definition nrf_axon_nn_infer.h:109
uint32_t output_dequant_mult
Definition nrf_axon_nn_infer.h:169
uint32_t cmd_buffer_len
Definition nrf_axon_nn_infer.h:145
const char ** labels
Definition nrf_axon_nn_infer.h:113
const void * model_const_ptr
Definition nrf_axon_nn_infer.h:141
uint8_t input_cnt
Definition nrf_axon_nn_infer.h:117
Definition nrf_axon_nn_infer.h:103
const nrf_axon_nn_compiled_model_s * compiled_model
Definition nrf_axon_nn_infer.h:310
nrf_axon_nn_async_inference_status_e infer_status
Definition nrf_axon_nn_infer.h:326
nrf_axon_queued_cmd_info_wrapper_s queued_cmd_buf_wrapper
Definition nrf_axon_nn_infer.h:314
void * callback_context
Definition nrf_axon_nn_infer.h:318
nrf_axon_cmd_buffer_info_s cmd_buf_info
Definition nrf_axon_nn_infer.h:312
int8_t * output_buffer
Definition nrf_axon_nn_infer.h:322
Combines the compiled model info with other structures to support asynchronous inferencing....
Definition nrf_axon_nn_infer.h:308
uint16_t width
Definition nrf_axon_nn_infer.h:22
uint16_t height
Definition nrf_axon_nn_infer.h:21
uint16_t channel_cnt
Definition nrf_axon_nn_infer.h:23
uint8_t byte_width
Definition nrf_axon_nn_infer.h:24
Definition nrf_axon_nn_infer.h:20
int32_t initial_value
Definition nrf_axon_nn_infer.h:62
int8_t * buf_ptr
Definition nrf_axon_nn_infer.h:58
uint32_t buf_size
Definition nrf_axon_nn_infer.h:60
uint8_t byte_width
Definition nrf_axon_nn_infer.h:64
Definition nrf_axon_nn_infer.h:56
Used as a parameter to nrf_axon_queue_cmd_buf for asynchronous execution.
Definition nrf_axon_driver.h:176