ONE - On-device Neural Engine
Loading...
Searching...
No Matches
nnfw.h File Reference

This file describes runtime API. More...

#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  nnfw_tensorinfo
 tensor info describes the type and shape of tensors More...
 

Macros

#define NNFW_MAX_RANK   (6)
 Maximum rank expressible with nnfw.
 

Typedefs

typedef struct nnfw_session nnfw_session
 Session to query with runtime.
 
typedef struct nnfw_tensorinfo nnfw_tensorinfo
 tensor info describes the type and shape of tensors
 

Enumerations

enum  NNFW_TYPE {
  NNFW_TYPE_TENSOR_FLOAT32 = 0 , NNFW_TYPE_TENSOR_INT32 = 1 , NNFW_TYPE_TENSOR_QUANT8_ASYMM = 2 , NNFW_TYPE_TENSOR_BOOL = 3 ,
  NNFW_TYPE_TENSOR_UINT8 = 4 , NNFW_TYPE_TENSOR_INT64 = 5 , NNFW_TYPE_TENSOR_QUANT8_ASYMM_SIGNED = 6 , NNFW_TYPE_TENSOR_QUANT16_SYMM_SIGNED = 7
}
 Tensor types. More...
 
enum  NNFW_STATUS {
  NNFW_STATUS_NO_ERROR = 0 , NNFW_STATUS_ERROR = 1 , NNFW_STATUS_UNEXPECTED_NULL = 2 , NNFW_STATUS_INVALID_STATE = 3 ,
  NNFW_STATUS_OUT_OF_MEMORY = 4 , NNFW_STATUS_INSUFFICIENT_OUTPUT_SIZE = 5 , NNFW_STATUS_DEPRECATED_API = 6
}
 Result values returned from a call to an API function. More...
 
enum  NNFW_LAYOUT { NNFW_LAYOUT_NONE = 0 , NNFW_LAYOUT_CHANNELS_LAST = 1 , NNFW_LAYOUT_CHANNELS_FIRST = 2 }
 Data format of a tensor. More...
 
enum  NNFW_INFO_ID { NNFW_INFO_ID_VERSION = 0 }
 Information ID for retrieving information on nnfw (e.g. version) More...
 

Functions

NNFW_STATUS nnfw_create_session (nnfw_session **session)
 Create a new session instance.
 
NNFW_STATUS nnfw_close_session (nnfw_session *session)
 Close a session instance.
 
NNFW_STATUS nnfw_load_model_from_file (nnfw_session *session, const char *path)
 Load model from path to model or nnpackage.
 
NNFW_STATUS nnfw_apply_tensorinfo (nnfw_session *session, uint32_t index, nnfw_tensorinfo tensor_info)
 Apply i-th input's tensor info to resize input tensor.
 
NNFW_STATUS nnfw_set_input_tensorinfo (nnfw_session *session, uint32_t index, const nnfw_tensorinfo *tensor_info)
 Set input model's tensor info for resizing.
 
NNFW_STATUS nnfw_prepare (nnfw_session *session)
 Prepare session to be ready for inference.
 
NNFW_STATUS nnfw_run (nnfw_session *session)
 Run inference.
 
NNFW_STATUS nnfw_run_async (nnfw_session *session)
 Run inference asynchronously.
 
NNFW_STATUS nnfw_await (nnfw_session *session)
 Wait for asynchronous run to finish.
 
NNFW_STATUS nnfw_set_input (nnfw_session *session, uint32_t index, NNFW_TYPE type, const void *buffer, size_t length)
 Set input buffer.
 
NNFW_STATUS nnfw_set_output (nnfw_session *session, uint32_t index, NNFW_TYPE type, void *buffer, size_t length)
 Set output buffer.
 
NNFW_STATUS nnfw_input_size (nnfw_session *session, uint32_t *number)
 Get the number of inputs.
 
NNFW_STATUS nnfw_output_size (nnfw_session *session, uint32_t *number)
 Get the number of outputs.
 
NNFW_STATUS nnfw_set_input_layout (nnfw_session *session, uint32_t index, NNFW_LAYOUT layout)
 Set the layout of an input.
 
NNFW_STATUS nnfw_set_output_layout (nnfw_session *session, uint32_t index, NNFW_LAYOUT layout)
 Set the layout of an output.
 
NNFW_STATUS nnfw_input_tensorinfo (nnfw_session *session, uint32_t index, nnfw_tensorinfo *tensor_info)
 Get i-th input tensor info.
 
NNFW_STATUS nnfw_output_tensorinfo (nnfw_session *session, uint32_t index, nnfw_tensorinfo *tensor_info)
 Get i-th output tensor info.
 
NNFW_STATUS nnfw_set_available_backends (nnfw_session *session, const char *backends)
 Set available backends.
 
NNFW_STATUS nnfw_set_op_backend (nnfw_session *session, const char *op, const char *backend)
 Set the operation's backend.
 
NNFW_STATUS nnfw_query_info_u32 (nnfw_session *session, NNFW_INFO_ID id, uint32_t *val)
 Retrieve uint32 type of nnfw information for given information ID.
 
NNFW_STATUS nnfw_set_workspace (nnfw_session *session, const char *dir)
 Set runtime's workspace directory.
 

Detailed Description

This file describes runtime API.

Definition in file nnfw.h.

Macro Definition Documentation

◆ NNFW_MAX_RANK

#define NNFW_MAX_RANK   (6)

Maximum rank expressible with nnfw.

Definition at line 163 of file nnfw.h.

Typedef Documentation

◆ nnfw_session

typedef struct nnfw_session nnfw_session

Session to query with runtime.

nnfw_session is started and passed by calling nnfw_create_session. Each session has its own inference environment, such as model to inference, backend usage, etc.

Load model by calling nnfw_load_model_from_file

After loading, prepare inference by calling nnfw_prepare. Application can set runtime environment before prepare by calling nnfw_set_available_backends, and it is optional.

Application can inference by calling nnfw_run. Before inference, application has responsibility to set input tensor to set input data by calling nnfw_set_output, and output tensor to get output by calling nnfw_set_input

To support input and output setting, application can get input and output tensor information by calling

Application can inference many times using one session, but next inference can do after prior inference end

Application cannot use muitiple model using one session

Definition at line 60 of file nnfw.h.

◆ nnfw_tensorinfo

tensor info describes the type and shape of tensors

This structure is used to describe input and output tensors. Application can get input and output tensor type and shape described in model by using nnfw_input_tensorinfo and nnfw_output_tensorinfo

Maximum rank is 6 (NNFW_MAX_RANK). And tensor's dimension value is filled in 'dims' field from index 0. For example, if tensor's rank is 4, application can get dimension value from dims[0], dims[1], dims[2], and dims[3]

Enumeration Type Documentation

◆ NNFW_INFO_ID

Information ID for retrieving information on nnfw (e.g. version)

Enumerator
NNFW_INFO_ID_VERSION 

nnfw runtime version Its value is uint32 in 0xMMmmmmPP, where MM = major, mmmm = minor, PP = patch.

Definition at line 152 of file nnfw.h.

153{
NNFW_INFO_ID
Information ID for retrieving information on nnfw (e.g. version)
Definition nnfw.h:153
@ NNFW_INFO_ID_VERSION
Definition nnfw.h:157

◆ NNFW_LAYOUT

Data format of a tensor.

Enumerator
NNFW_LAYOUT_NONE 

Don't care layout

NNFW_LAYOUT_CHANNELS_LAST 

Channel last layout If rank is 4, layout is NHWC

NNFW_LAYOUT_CHANNELS_FIRST 

Channel first layout If rank is 4, layout is NCHW

Definition at line 133 of file nnfw.h.

134{
NNFW_LAYOUT
Data format of a tensor.
Definition nnfw.h:134
@ NNFW_LAYOUT_CHANNELS_LAST
Definition nnfw.h:141
@ NNFW_LAYOUT_CHANNELS_FIRST
Definition nnfw.h:146
@ NNFW_LAYOUT_NONE
Definition nnfw.h:136

◆ NNFW_STATUS

Result values returned from a call to an API function.

Enumerator
NNFW_STATUS_NO_ERROR 

Successful

NNFW_STATUS_ERROR 

An error code for general use. Mostly used when there is no specific value for that certain situation.

NNFW_STATUS_UNEXPECTED_NULL 

Unexpected null argument is given.

NNFW_STATUS_INVALID_STATE 

When a function was called but it is not valid for the current session state.

NNFW_STATUS_OUT_OF_MEMORY 

When it is out of memory

NNFW_STATUS_INSUFFICIENT_OUTPUT_SIZE 

When it was given an insufficient output buffer

NNFW_STATUS_DEPRECATED_API 

When API is deprecated

Definition at line 109 of file nnfw.h.

110{
NNFW_STATUS
Result values returned from a call to an API function.
Definition nnfw.h:110
@ NNFW_STATUS_INVALID_STATE
Definition nnfw.h:121
@ NNFW_STATUS_UNEXPECTED_NULL
Definition nnfw.h:119
@ NNFW_STATUS_NO_ERROR
Definition nnfw.h:112
@ NNFW_STATUS_DEPRECATED_API
Definition nnfw.h:127
@ NNFW_STATUS_INSUFFICIENT_OUTPUT_SIZE
Definition nnfw.h:125
@ NNFW_STATUS_ERROR
Definition nnfw.h:117
@ NNFW_STATUS_OUT_OF_MEMORY
Definition nnfw.h:123

◆ NNFW_TYPE

enum NNFW_TYPE

Tensor types.

The type of tensor represented in nnfw_tensorinfo

Enumerator
NNFW_TYPE_TENSOR_FLOAT32 

A tensor of 32 bit floating point

NNFW_TYPE_TENSOR_INT32 

A tensor of 32 bit signed integer

NNFW_TYPE_TENSOR_QUANT8_ASYMM 

A tensor of 8 bit unsigned integers that represent real numbers.

real_value = (integer_value - zeroPoint) * scale.

NNFW_TYPE_TENSOR_BOOL 

A tensor of boolean

NNFW_TYPE_TENSOR_UINT8 

A tensor of 8 bit unsigned integer

NNFW_TYPE_TENSOR_INT64 

A tensor of 64 bit signed integer

NNFW_TYPE_TENSOR_QUANT8_ASYMM_SIGNED 

A tensor of 8 bit signed integers that represent real numbers.

real_value = (integer_value - zeroPoint) * scale.

NNFW_TYPE_TENSOR_QUANT16_SYMM_SIGNED 

A tensor of 16 bit signed integers that represent real numbers.

real_value = (integer_value - zeroPoint) * scale.

Forced to have zeroPoint equal to 0.

Definition at line 67 of file nnfw.h.

68{
81
84
87
94
103
104} NNFW_TYPE;
NNFW_TYPE
Tensor types.
Definition nnfw.h:68
@ NNFW_TYPE_TENSOR_INT64
Definition nnfw.h:86
@ NNFW_TYPE_TENSOR_QUANT16_SYMM_SIGNED
Definition nnfw.h:102
@ NNFW_TYPE_TENSOR_QUANT8_ASYMM_SIGNED
Definition nnfw.h:93
@ NNFW_TYPE_TENSOR_BOOL
Definition nnfw.h:80
@ NNFW_TYPE_TENSOR_INT32
Definition nnfw.h:72
@ NNFW_TYPE_TENSOR_QUANT8_ASYMM
Definition nnfw.h:78
@ NNFW_TYPE_TENSOR_UINT8
Definition nnfw.h:83
@ NNFW_TYPE_TENSOR_FLOAT32
Definition nnfw.h:70

Function Documentation

◆ nnfw_apply_tensorinfo()

NNFW_STATUS nnfw_apply_tensorinfo ( nnfw_session session,
uint32_t  index,
nnfw_tensorinfo  tensor_info 
)

Apply i-th input's tensor info to resize input tensor.

This function should be called before nnfw_prepare is invoked, and should be called after nnfw_load_model_from_file is invoked See nnfw_prepare for information applying updated tensor info If this function is called many times for same index, tensor info is overwritten

Parameters
[in]sessionSession to the input tensor info is to be set
[in]indexIndex of input to be applied (0-indexed)
[in]tensor_infoTensor info to be applied
Returns
NNFW_STATUS_NO_ERROR if successful, otherwise return NNFW_STATUS_ERROR

Definition at line 155 of file nnfw_api.cc.

156{
157 return nnfw_session::deprecated("nnfw_apply_tensorinfo: Deprecated");
158}
static NNFW_STATUS deprecated(const char *msg)

References nnfw_session::deprecated().

◆ nnfw_await()

NNFW_STATUS nnfw_await ( nnfw_session session)

Wait for asynchronous run to finish.

This function must be called after calling nnfw_run_async, and can be called only once for a nnfw_run_async call.

When this function returns, it means that this session has finished the asynchronous run. Then the user can safely use the output data.

This function returns after the asynchronous inference is finished.

Parameters
[in]sessionThe session to run inference
Returns
NNFW_STATUS_NO_ERROR if successful

Definition at line 90 of file nnfw_api.cc.

91{
93 return session->await();
94}
SessionID session(const coco::Module *m)
Definition Session.cpp:48
#define NNFW_RETURN_ERROR_IF_NULL(p)
Definition nnfw_api.cc:51

References NNFW_RETURN_ERROR_IF_NULL.

Referenced by NNFW_SESSION::wait().

◆ nnfw_close_session()

NNFW_STATUS nnfw_close_session ( nnfw_session session)

Close a session instance.

After called, access to closed session by application will be invalid

Parameters
[in]sessionThe session to be closed
Returns
NNFW_STATUS_NO_ERROR if successful

Definition at line 60 of file nnfw_api.cc.

61{
62 delete session;
64}
@ NNFW_STATUS_NO_ERROR
Definition onert-micro.h:88

◆ nnfw_create_session()

NNFW_STATUS nnfw_create_session ( nnfw_session **  session)

Create a new session instance.

This only creates a session. Model is loaded after nnfw_load_model_from_file is invoked. And inference is performed after nnfw_run is invoked.

nnfw_close_session should be called once if session is no longer needed

Parameters
[out]sessionThe session to be created
Returns
NNFW_STATUS_NO_ERROR if successful

Definition at line 390 of file onert-micro.cpp.

390{ return nnfw_session::create(session); }
static NNFW_STATUS create(nnfw_session **session)
Factory method. It creates and initialize nnfw_session.

References nnfw_session::create().

◆ nnfw_input_size()

NNFW_STATUS nnfw_input_size ( nnfw_session session,
uint32_t *  number 
)

Get the number of inputs.

Application can call this function to get number of inputs defined in loaded model. This function should be called after nnfw_load_model_from_file is invoked to load model

Parameters
[in]sessionSession from input information is to be extracted
[out]numberVariable which the number of inputs is put into
Returns
NNFW_STATUS_NO_ERROR if successful

Definition at line 110 of file nnfw_api.cc.

111{
113 return session->input_size(number);
114}

References NNFW_RETURN_ERROR_IF_NULL.

Referenced by NNFW_SESSION::input_size().

◆ nnfw_input_tensorinfo()

NNFW_STATUS nnfw_input_tensorinfo ( nnfw_session session,
uint32_t  index,
nnfw_tensorinfo tensor_info 
)

Get i-th input tensor info.

Before nnfw_prepare is invoked, this function return tensor info in model, so updated tensor info by nnfw_apply_tensorinfo is not returned.

After nnfw_prepare is invoked, this function return updated tensor info if tensor info is updated by nnfw_apply_tensorinfo.

Parameters
[in]sessionSession from input information is to be extracted
[in]indexIndex of input
[out]tensor_infoTensor info (shape, type, etc)
Returns
NNFW_STATUS_NO_ERROR if successful

Definition at line 134 of file nnfw_api.cc.

136{
138 return session->input_tensorinfo(index, tensor_info);
139}

References NNFW_RETURN_ERROR_IF_NULL.

Referenced by NNFW_SESSION::input_tensorinfo(), main(), and NNFW_SESSION::set_input().

◆ nnfw_load_model_from_file()

NNFW_STATUS nnfw_load_model_from_file ( nnfw_session session,
const char *  path 
)

Load model from path to model or nnpackage.

The length of path must not exceed 1024 bytes including zero at the end.

Parameters
[in]sessionnnfw_session loading the given file/dir
[in]pathPath to the model file or nnpackage directory to be loaded
Returns
NNFW_STATUS_NO_ERROR if successful

Load model from path to model or nnpackage.

The length of package_file_path must not exceed 1024 bytes including zero at the end.

Parameters
[in]sessionnnfw_session loading the given nnpackage file/dir
[in]package_file_pathPath to the nnpackage file or unzipped directory to be loaded
Returns
NNFW_STATUS_NO_ERROR if successful

Definition at line 392 of file onert-micro.cpp.

393{
394 return session->load_model_from_file(package_file_path);
395}

References NNFW_RETURN_ERROR_IF_NULL.

◆ nnfw_output_size()

NNFW_STATUS nnfw_output_size ( nnfw_session session,
uint32_t *  number 
)

Get the number of outputs.

Application can call this function to get number of outputs defined in loaded model. This function should be called after nnfw_load_model_from_file is invoked to load model

Parameters
[in]sessionSession from output information is to be extracted
[out]numberVariable which the number of outputs is put into
Returns
NNFW_STATUS_NO_ERROR if successful

Definition at line 116 of file nnfw_api.cc.

117{
119 return session->output_size(number);
120}

References NNFW_RETURN_ERROR_IF_NULL.

Referenced by NNFW_SESSION::output_size().

◆ nnfw_output_tensorinfo()

NNFW_STATUS nnfw_output_tensorinfo ( nnfw_session session,
uint32_t  index,
nnfw_tensorinfo tensor_info 
)

Get i-th output tensor info.

After nnfw_load_model_from_file and before nnfw_prepare is invoked, it returns tensor info in the model.

After nnfw_prepare and before nnfw_run is invoked, this function returns updated tensor info if tensor info is updated by nnfw_set_input_tensorinfo.

After nnfw_run is invoked(at least once), it returns the updated tensor info during the latest execution.

Parameters
[in]sessionSession from output information is to be extracted
[in]indexIndex of output
[out]tensor_infoTensor info (shape, type, etc)
Returns
NNFW_STATUS_NO_ERROR if successful

Definition at line 141 of file nnfw_api.cc.

143{
145 return session->output_tensorinfo(index, tensor_info);
146}

References NNFW_RETURN_ERROR_IF_NULL.

Referenced by main(), NNFW_SESSION::output_tensorinfo(), and NNFW_SESSION::set_output().

◆ nnfw_prepare()

NNFW_STATUS nnfw_prepare ( nnfw_session session)

Prepare session to be ready for inference.

This phase may finalize model compilation, scheduling, and additional settings. If nnfw_apply_tensorinfo is called to apply input tensor info different with model before this function, tries to resize all tensors.

Parameters
[in]sessionthe session to be prepared
Returns
NNFW_STATUS_NO_ERROR if successful, otherwise return NNFW_STATUS_ERROR

Definition at line 72 of file nnfw_api.cc.

73{
75 return session->prepare();
76}

References NNFW_RETURN_ERROR_IF_NULL.

Referenced by main(), and NNFW_SESSION::NNFW_SESSION().

◆ nnfw_query_info_u32()

NNFW_STATUS nnfw_query_info_u32 ( nnfw_session session,
NNFW_INFO_ID  id,
uint32_t *  val 
)

Retrieve uint32 type of nnfw information for given information ID.

Retrieves the information of property given by information id

Note
: The input session could be null for global information (e.g. runtime version).*
Parameters
[in]sessionsession to be queried on.
[in]idID to be queried
[out]valuint32 value to be returned.
Returns
NNFW_STATUS_NO_ERROR if successful

Definition at line 178 of file nnfw_api.cc.

179{
180 (void)session;
181 switch (id)
182 {
184 if (val)
185 {
186 *val = NNFW_VERSION;
188 }
189 break;
190 default:
191 return NNFW_STATUS_ERROR;
192 }
193 // It should not be reached.
194 return NNFW_STATUS_ERROR;
195}
#define NNFW_VERSION
@ NNFW_STATUS_ERROR
Definition onert-micro.h:93

References NNFW_INFO_ID_VERSION, NNFW_STATUS_ERROR, NNFW_STATUS_NO_ERROR, and NNFW_VERSION.

◆ nnfw_run()

NNFW_STATUS nnfw_run ( nnfw_session session)

Run inference.

This function should be called after model is loaded by nnfw_load_model_from_file, session is prepared for inference by nnfw_prepare, set input and output buffers by nnfw_set_input and nnfw_set_output.

This function return after inference is finished.

Parameters
[in]sessionThe session to run inference
Returns
NNFW_STATUS_NO_ERROR if successful

Definition at line 78 of file nnfw_api.cc.

79{
81 return session->run();
82}

References NNFW_RETURN_ERROR_IF_NULL.

Referenced by main(), and NNFW_SESSION::run().

◆ nnfw_run_async()

NNFW_STATUS nnfw_run_async ( nnfw_session session)

Run inference asynchronously.

This function must be called after model is loaded by nnfw_load_model_from_file, session is prepared for inference by nnfw_prepare, set input and output buffers by nnfw_set_input and nnfw_set_output.

This function returns immediately after starting a thread to run the inference. To get the result of it or to do the next inference with nnfw_run or nnfw_run_async, nnfw_await must be called to ensure the current asynchronous inference has finished. Only one asynchronous inference is allowed at a time for a session. If this function is called while the previous one is still running, it returns an error.

Parameters
[in]sessionThe session to run inference
Returns
NNFW_STATUS_NO_ERROR if successful

Definition at line 84 of file nnfw_api.cc.

85{
87 return session->run_async();
88}

References NNFW_RETURN_ERROR_IF_NULL.

Referenced by NNFW_SESSION::run_async().

◆ nnfw_set_available_backends()

NNFW_STATUS nnfw_set_available_backends ( nnfw_session session,
const char *  backends 
)

Set available backends.

This function should be called before nnfw_prepare is invoked.

Supported backends differs on each platforms. For example, x86_64 supports "cpu" only. Multiple backends can be set and they must be separated by a semicolon (ex: "acl_cl;cpu"). For each backend string, libbackend_{backend}.so will be dynamically loaded during nnfw_prepare. Among the multiple backends, the 1st element is used as the default backend.

Parameters
[in]sessionsession to which avilable backends are set
[in]backendsavailable backends on which nnfw uses
Returns
NNFW_STATUS_NO_ERROR if successful

Definition at line 167 of file nnfw_api.cc.

168{
170 return session->set_available_backends(backends);
171}

References NNFW_RETURN_ERROR_IF_NULL.

Referenced by NNFW_SESSION::NNFW_SESSION().

◆ nnfw_set_input()

NNFW_STATUS nnfw_set_input ( nnfw_session session,
uint32_t  index,
NNFW_TYPE  type,
const void *  buffer,
size_t  length 
)

Set input buffer.

This function must be called after nnfw_prepare, buffer given to this function can be reused for many inferences. length must be greater or equal than the operand requires. To specify an optional input, you can either not call this for that input or call this with buffer of NULL and length of 0. If you set NNFW_TYPE_TENSOR_FLOAT32 type and model has quantized input type on given index, runtime will set quantized data type model input by converting from float buffer data internally.

Parameters
[in]sessionSession to the input is to be set
[in]indexIndex of input to be set (0-indexed)
[in]typeType of the input
[in]bufferRaw buffer for input
[in]lengthSize of bytes of input buffer
Returns
NNFW_STATUS_NO_ERROR if successful

Definition at line 96 of file nnfw_api.cc.

98{
100 return session->set_input(index, type, buffer, length);
101}

References NNFW_RETURN_ERROR_IF_NULL.

Referenced by main(), and NNFW_SESSION::set_input().

◆ nnfw_set_input_layout()

NNFW_STATUS nnfw_set_input_layout ( nnfw_session session,
uint32_t  index,
NNFW_LAYOUT  layout 
)

Set the layout of an input.

The input that does not call this has NNFW_LAYOUT_NHWC layout

Parameters
[in]sessionsession from inference input is to be extracted
[in]indexindex of input to be set (0-indexed)
[in]layoutlayout to set to target input
Returns
NNFW_STATUS_NO_ERROR if successful

Definition at line 122 of file nnfw_api.cc.

123{
125 return session->set_input_layout(index, layout);
126}

References NNFW_RETURN_ERROR_IF_NULL.

Referenced by NNFW_SESSION::set_input_layout().

◆ nnfw_set_input_tensorinfo()

NNFW_STATUS nnfw_set_input_tensorinfo ( nnfw_session session,
uint32_t  index,
const nnfw_tensorinfo tensor_info 
)

Set input model's tensor info for resizing.

This function can be called at any time after calling nnfw_load_model_from_file. Changing input tensor's shape will cause shape inference for the model. There are two different types of shape inference - static and dynamic. Which one to use is depend on the current state of the session. When it is called after calling nnfw_load_model_from_file and before calling nnfw_prepare, this info will be used when nnfw_prepare. And it will perform static shape inference for all tensors. When it is called after calling nnfw_prepare or even after nnfw_run, this info will be used when nnfw_run. And the shapes of the tensors are determined on the fly. If this function is called many times for the same index, it is overwritten. tensor_info's dtype field is ignored.

Parameters
[in]sessionSession to the input tensor info is to be set
[in]indexIndex of input to be set (0-indexed)
[in]tensor_infoTensor info to be set
Returns
NNFW_STATUS_NO_ERROR if successful, otherwise return NNFW_STATUS_ERROR

Definition at line 160 of file nnfw_api.cc.

162{
164 return session->set_input_tensorinfo(index, tensor_info);
165}

References NNFW_RETURN_ERROR_IF_NULL.

Referenced by NNFW_SESSION::set_input_tensorinfo().

◆ nnfw_set_op_backend()

NNFW_STATUS nnfw_set_op_backend ( nnfw_session session,
const char *  op,
const char *  backend 
)

Set the operation's backend.

This function should be called before nnfw_prepare is invoked.

The backend for op has higher priority than available backends specified by nnfw_set_available_backends.

Parameters
[in]sessionsession to be modified
[in]opoperation to be set
[in]backendbakcend on which operation run
Returns
NNFW_STATUS_NO_ERROR if successful

Definition at line 173 of file nnfw_api.cc.

174{
175 return nnfw_session::deprecated("nnfw_set_op_backend: Deprecated");
176}

References nnfw_session::deprecated().

Referenced by main().

◆ nnfw_set_output()

NNFW_STATUS nnfw_set_output ( nnfw_session session,
uint32_t  index,
NNFW_TYPE  type,
void *  buffer,
size_t  length 
)

Set output buffer.

This function must be called after nnfw_prepare, buffer given to this function can be reused for many inferences. length must be greater or equal than the operand requires. An output operand can have unspecified shape and deduced dynamically during the execution. You must provide buffer large enough. If you set NNFW_TYPE_TENSOR_FLOAT32 type and model has quantized output type on given index, runtime will set dequantized float buffer data from quantize data type model output internally.

Parameters
[in]sessionSession from inference output is to be extracted
[in]indexIndex of output to be set (0-indexed)
[in]typeType of the output
[out]bufferRaw buffer for output
[in]lengthSize of bytes of output buffer
Returns
NNFW_STATUS_NO_ERROR if successful

Definition at line 103 of file nnfw_api.cc.

105{
107 return session->set_output(index, type, buffer, length);
108}

References NNFW_RETURN_ERROR_IF_NULL.

Referenced by main(), and NNFW_SESSION::set_output().

◆ nnfw_set_output_layout()

NNFW_STATUS nnfw_set_output_layout ( nnfw_session session,
uint32_t  index,
NNFW_LAYOUT  layout 
)

Set the layout of an output.

The output that does not call this has NNFW_LAYOUT_NHWC layout

Parameters
[in]sessionsession from inference output is to be extracted
[in]indexindex of output to be set (0-indexed)
[in]layoutlayout to set to target output
Returns
NNFW_STATUS_NO_ERROR if successful

Definition at line 128 of file nnfw_api.cc.

129{
131 return session->set_output_layout(index, layout);
132}

References NNFW_RETURN_ERROR_IF_NULL.

Referenced by NNFW_SESSION::set_output_layout().

◆ nnfw_set_workspace()

NNFW_STATUS nnfw_set_workspace ( nnfw_session session,
const char *  dir 
)

Set runtime's workspace directory.

This function sets the directory to be used as a workspace. System should allow read and write access to the directory for the runtime. Default workspace is running directory of the application. This function should be called before nnfw_load_model_from_file is invoked.

Parameters
[in]sessionsession to be queried on.
[in]dirworkspace directory path
Returns
NNFW_STATUS_NO_ERROR if successful

Definition at line 230 of file nnfw_api.cc.

231{
233 return session->set_workspace(dir);
234}

References NNFW_RETURN_ERROR_IF_NULL.