Developer World
Spresense SDK Library v3.3.0-375c679
runtime.h File Reference
#include <asmp/types.h>
#include "tensorflow/lite/c/common.h"
#include "tensorflow/lite/micro/spresense/debug_log_callback.h"

Go to the source code of this file.

Classes

struct  tflm_runtime
 
struct  tflm_config
 
struct  tflm_mallinfo
 

Typedefs

typedef struct tflm_runtime tflm_runtime_t
 
typedef struct tflm_config tflm_config_t
 
typedef struct tflm_mallinfo tflm_mallinfo_t
 

Functions

int tflm_initialize (tflm_config_t *config)
 
int tflm_finalize (void)
 
int tflm_runtime_initialize (tflm_runtime_t *rt, const void *network, int size)
 
int tflm_runtime_finalize (tflm_runtime_t *rt)
 
int tflm_runtime_forward (tflm_runtime_t *rt, const void *inputs[], unsigned char input_num)
 
int tflm_runtime_actual_arenasize (tflm_runtime_t *rt)
 
int tflm_runtime_input_num (tflm_runtime_t *rt)
 
int tflm_runtime_input_size (tflm_runtime_t *rt, unsigned char input_index)
 
int tflm_runtime_input_ndim (tflm_runtime_t *rt, unsigned char input_index)
 
int tflm_runtime_input_shape (tflm_runtime_t *rt, unsigned char input_index, unsigned char dim_index)
 
TfLiteTensor * tflm_runtime_input_variable (tflm_runtime_t *rt, unsigned char input_index)
 
int tflm_runtime_output_num (tflm_runtime_t *rt)
 
int tflm_runtime_output_size (tflm_runtime_t *rt, unsigned char output_index)
 
int tflm_runtime_output_ndim (tflm_runtime_t *rt, unsigned char output_index)
 
int tflm_runtime_output_shape (tflm_runtime_t *rt, unsigned char output_index, unsigned char dim_index)
 
TfLiteTensor * tflm_runtime_output_variable (tflm_runtime_t *rt, unsigned char output_index)
 
void * tflm_runtime_output_buffer (tflm_runtime_t *rt, unsigned char output_index)
 
int tflm_nuttx_mallinfo (tflm_mallinfo_t *info)
 
int tflm_asmp_mallinfo (unsigned char array_length, tflm_mallinfo_t *info_array)
 

Typedef Documentation

◆ tflm_config_t

structure to hold tflmrt runtime information

structure to configure tflmrt subsystem

◆ tflm_mallinfo_t

structure to obtain memory allocation information

Function Documentation

◆ tflm_initialize()

int tflm_initialize ( tflm_config_t config)

Initialize the whole tflmrt subsystem

Parameters
[in]configconfiguration of multicore processing.
If CONFIG_TFLM_RT_MPCOMM=y, tflm_config_t::cpu_num must be 1 or more,
otherwise tflm_config_t::cpu_num must be 1.
Returns
0 on success, otherwise returns error code in errno_t.
Note
this function must be called before any tflm_runtime_t object is initialized.

◆ tflm_finalize()

int tflm_finalize ( void  )

Finalize the whole tflmrt subsystem. This function frees all the resources allocated through tflm_initialize().

Returns
0 on success, otherwise returns error code in errno_t.
Note
this function must be called after all the tflm_runtime_t is finalized

◆ tflm_runtime_initialize()

int tflm_runtime_initialize ( tflm_runtime_t rt,
const void *  network,
int  size 
)

Instantiate a neural network as a tflm_runtime_t object.

Parameters
[in,out]rttflmrt_runtime_t object
[in]networkpointer to a memory into which network is loaded
[in]sizetensor arena size
Returns
0 on success, otherwise returns error code in errno_t.
Note
This function binds tflm_runtime_t and network,
so applications don't have to give the network object to the other functions except this.
However, the runtime holds reference to the network object.
Applications must NOT free it until tflm_runtime_finalize().

◆ tflm_runtime_finalize()

int tflm_runtime_finalize ( tflm_runtime_t rt)

Free all the memory allocated to a tflm_runtime_t object

Parameters
[in,out]rttflmrt_runtime_t object
Returns
0 on success, otherwise returns error code in errno_t.
Note
tflmrt are NOT involved in freeing nn_network_t.

◆ tflm_runtime_forward()

int tflm_runtime_forward ( tflm_runtime_t rt,
const void *  inputs[],
unsigned char  input_num 
)

Execute forward propagation after feeding input data.

Parameters
[in,out]rttflmrt_runtime_t object
[in]inputsan array of pointers to input buffers
[in]input_numlength of inputs
Returns
0 on success, otherwise returns error code in errno_t.
Note
feed input data taking the following points into account:
  • input_num equals to tflm_runtime_input_num()
  • length of each input buffer(i.e. inputs[i]) equals to tflm_runtime_input_size(rt, i)
  • internal representation of each input buffer(i.e. inputs[i]) can be obtained by tflm_runtime_input_variable(rt, i)

◆ tflm_runtime_actual_arenasize()

int tflm_runtime_actual_arenasize ( tflm_runtime_t rt)

Return the size of tensorflow arena size.

Parameters
[in,out]rttflmrt_runtime_t object
Returns
byes of actual arena memory size, otherwise -EINVAL.

◆ tflm_runtime_input_num()

int tflm_runtime_input_num ( tflm_runtime_t rt)

Return the number of inputs which this network needs.

Parameters
[in,out]rttflmrt_runtime_t object
Returns
number of inputs on success, otherwise -EINVAL.

◆ tflm_runtime_input_size()

int tflm_runtime_input_size ( tflm_runtime_t rt,
unsigned char  input_index 
)

Return the number of elements in a specified input.

Parameters
[in,out]rttflmrt_runtime_t object
[in]input_indexindex to specify an input
Returns
number of elements in the specified input on success, otherwise -EINVAL.

◆ tflm_runtime_input_ndim()

int tflm_runtime_input_ndim ( tflm_runtime_t rt,
unsigned char  input_index 
)

Return the number of a specified input's dimensions.

Parameters
[in,out]rttflmrt_runtime_t object
[in]input_indexindex to specify an input
Returns
number of the specified input's dimensions on success, otherwise -EINVAL.

◆ tflm_runtime_input_shape()

int tflm_runtime_input_shape ( tflm_runtime_t rt,
unsigned char  input_index,
unsigned char  dim_index 
)

Return the number of elements in a specified dimension of an input.

Parameters
[in,out]rttflmrt_runtime_t object
[in]input_indexindex to specify an input
[in]dim_indexindex to specify a dimension
Returns
number of elements in the specified dimension of the input on success, otherwise -EINVAL.

◆ tflm_runtime_input_variable()

TfLiteTensor * tflm_runtime_input_variable ( tflm_runtime_t rt,
unsigned char  input_index 
)

Get TfLiteTensor* corresponding to a specified input

Parameters
[in,out]rttflmrt_runtime_t object
[in]input_indexindex to specify an input
Returns
pointer to TfLiteTensor on success, otherwise NULL

◆ tflm_runtime_output_num()

int tflm_runtime_output_num ( tflm_runtime_t rt)

Return the number of outputs which this network emits.

Parameters
[in,out]rttflmrt_runtime_t object
Returns
number of outputs on success, otherwise -EINVAL.

◆ tflm_runtime_output_size()

int tflm_runtime_output_size ( tflm_runtime_t rt,
unsigned char  output_index 
)

Return the number of elements in a specified output.

Parameters
[in,out]rttflmrt_runtime_t object
[in]output_indexindex to specify an output
Returns
number of elements in the specified output on success, otherwise -EINVAL.

◆ tflm_runtime_output_ndim()

int tflm_runtime_output_ndim ( tflm_runtime_t rt,
unsigned char  output_index 
)

Return the number of a specified output's dimensions.

Parameters
[in,out]rttflmrt_runtime_t object
[in]output_indexindex to specify an input
Returns
number of the specified input's dimensions on success, otherwise -EINVAL.

◆ tflm_runtime_output_shape()

int tflm_runtime_output_shape ( tflm_runtime_t rt,
unsigned char  output_index,
unsigned char  dim_index 
)

Return the number of elements in a specified dimension of an output.

Parameters
[in,out]rttflmrt_runtime_t object
[in]output_indexindex to specify an output
[in]dim_indexindex to specify a dimension
Returns
number of elements in the specified dimension of the output on success, otherwise -EINVAL.

◆ tflm_runtime_output_variable()

TfLiteTensor * tflm_runtime_output_variable ( tflm_runtime_t rt,
unsigned char  output_index 
)

Get TfLiteTensor* corresponding to a specified output

Parameters
[in,out]rttflmrt_runtime_t object
[in]output_indexindex to specify an output
Returns
pointer to TfLiteTensor on success, otherwise NULL

◆ tflm_runtime_output_buffer()

void * tflm_runtime_output_buffer ( tflm_runtime_t rt,
unsigned char  output_index 
)

Return a pointer to a specified output

Parameters
[in,out]rttflmrt_runtime_t object
[in]output_indexindex to specify an output
Returns
pointer to corresponding the output buffer if output_index is valid, otherwise NULL.
Note
read output data taking the following points into account:
  • output_index must be less than tflm_runtime_output_num(rt)
  • length of the output buffer equals to tflm_runtime_output_size(rt, output_index)
  • internal representation of the output buffer can be obtained by tflm_runtime_output_variable(rt, output_index)

◆ tflm_nuttx_mallinfo()

int tflm_nuttx_mallinfo ( tflm_mallinfo_t info)

Obtain information about memory allocation in the Nuttx-side heap

Parameters
[out]infopointer to store memory allocation stats
Returns
0 on success. otherwise -EINVAL.

◆ tflm_asmp_mallinfo()

int tflm_asmp_mallinfo ( unsigned char  array_length,
tflm_mallinfo_t info_array 
)

Obtain information about memory allocation in the ASMP-side heap

Parameters
[in]array_lengthNumber of elements in info_array.
This value must be tflm_config_t::cpu_num
[out]info_arrayArray to store memory allocation stats
Returns
0 on success. -EPERM if CONFIG_TFLM_RT_MPCOMM=n