ONE - On-device Neural Engine
|
#include "nnfw.h"
#include "nnfw_experimental.h"
#include "nnfw_version.h"
#include "nnfw_session.h"
Go to the source code of this file.
Macros | |
#define | STATIC_ASSERT_ENUM_CHECK(ENUM, VAL) static_assert((ENUM) == (VAL), #ENUM " has changed") |
#define | NNFW_RETURN_ERROR_IF_NULL(p) |
Functions | |
STATIC_ASSERT_ENUM_CHECK (NNFW_TYPE_TENSOR_FLOAT32, 0) | |
STATIC_ASSERT_ENUM_CHECK (NNFW_TYPE_TENSOR_INT32, 1) | |
STATIC_ASSERT_ENUM_CHECK (NNFW_TYPE_TENSOR_QUANT8_ASYMM, 2) | |
STATIC_ASSERT_ENUM_CHECK (NNFW_TYPE_TENSOR_BOOL, 3) | |
STATIC_ASSERT_ENUM_CHECK (NNFW_TYPE_TENSOR_UINT8, 4) | |
STATIC_ASSERT_ENUM_CHECK (NNFW_TYPE_TENSOR_INT64, 5) | |
STATIC_ASSERT_ENUM_CHECK (NNFW_TYPE_TENSOR_QUANT8_ASYMM_SIGNED, 6) | |
STATIC_ASSERT_ENUM_CHECK (NNFW_TYPE_TENSOR_QUANT16_SYMM_SIGNED, 7) | |
STATIC_ASSERT_ENUM_CHECK (NNFW_STATUS_NO_ERROR, 0) | |
STATIC_ASSERT_ENUM_CHECK (NNFW_STATUS_ERROR, 1) | |
STATIC_ASSERT_ENUM_CHECK (NNFW_STATUS_UNEXPECTED_NULL, 2) | |
STATIC_ASSERT_ENUM_CHECK (NNFW_STATUS_INVALID_STATE, 3) | |
STATIC_ASSERT_ENUM_CHECK (NNFW_STATUS_OUT_OF_MEMORY, 4) | |
STATIC_ASSERT_ENUM_CHECK (NNFW_STATUS_INSUFFICIENT_OUTPUT_SIZE, 5) | |
STATIC_ASSERT_ENUM_CHECK (NNFW_LAYOUT_NONE, 0) | |
STATIC_ASSERT_ENUM_CHECK (NNFW_LAYOUT_CHANNELS_LAST, 1) | |
STATIC_ASSERT_ENUM_CHECK (NNFW_LAYOUT_CHANNELS_FIRST, 2) | |
STATIC_ASSERT_ENUM_CHECK (NNFW_INFO_ID_VERSION, 0) | |
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 nnpackage file or directory. | |
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_register_custom_op_info (nnfw_session *session, const char *id, custom_kernel_registration_info *info) |
NNFW_STATUS | nnfw_apply_tensorinfo (nnfw_session *, uint32_t, nnfw_tensorinfo) |
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_set_available_backends (nnfw_session *session, const char *backends) |
Set available backends. | |
NNFW_STATUS | nnfw_set_op_backend (nnfw_session *, const char *, const char *) |
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_input_tensorindex (nnfw_session *session, const char *tensorname, uint32_t *index) |
Get the input tensor index by name. | |
NNFW_STATUS | nnfw_output_tensorindex (nnfw_session *session, const char *tensorname, uint32_t *index) |
Get the input tensor index by name. | |
NNFW_STATUS | nnfw_set_backends_per_operation (nnfw_session *session, const char *backend_settings) |
Set the backend for each operation in the session. | |
NNFW_STATUS | nnfw_prepare_pipeline (nnfw_session *, const char *) |
Prepare session to be ready for inference. | |
NNFW_STATUS | nnfw_push_pipeline_input (nnfw_session *, void *, void *) |
Set input buffer. | |
NNFW_STATUS | nnfw_pop_pipeline_output (nnfw_session *, void *) |
Get last outputs of partitioned model in session. | |
NNFW_STATUS | nnfw_set_workspace (nnfw_session *session, const char *dir) |
Set runtime's workspace directory. | |
NNFW_STATUS | nnfw_train_get_traininfo (nnfw_session *session, nnfw_train_info *info) |
Get training information. | |
NNFW_STATUS | nnfw_train_set_traininfo (nnfw_session *session, const nnfw_train_info *info) |
Set training information. | |
NNFW_STATUS | nnfw_train_prepare (nnfw_session *session) |
Prepare session to be ready for training. | |
NNFW_STATUS | nnfw_train_input_tensorinfo (nnfw_session *session, uint32_t index, nnfw_tensorinfo *info) |
Get the training model input information. | |
NNFW_STATUS | nnfw_train_expected_tensorinfo (nnfw_session *session, uint32_t index, nnfw_tensorinfo *info) |
Get the training model expected output information. | |
NNFW_STATUS | nnfw_train_set_input (nnfw_session *session, uint32_t index, const void *input, const nnfw_tensorinfo *input_info) |
Set training input. | |
NNFW_STATUS | nnfw_train_set_expected (nnfw_session *session, uint32_t index, const void *expected, const nnfw_tensorinfo *expected_info) |
Set training expected output. | |
NNFW_STATUS | nnfw_train_set_output (nnfw_session *session, uint32_t index, NNFW_TYPE type, void *buffer, size_t length) |
Set training output buffer. | |
NNFW_STATUS | nnfw_train (nnfw_session *session, bool update_weights) |
Train the model. | |
NNFW_STATUS | nnfw_train_get_loss (nnfw_session *session, uint32_t index, float *loss) |
Get loss value for expected output. | |
NNFW_STATUS | nnfw_train_export_circle (nnfw_session *session, const char *path) |
Export current training model into circle model. | |
NNFW_STATUS | nnfw_train_import_checkpoint (nnfw_session *session, const char *path) |
Import circle checkpoint. | |
NNFW_STATUS | nnfw_train_export_checkpoint (nnfw_session *session, const char *path) |
Export circle checkpoint. | |
NNFW_STATUS | nnfw_set_quantization_type (nnfw_session *session, NNFW_QUANTIZE_TYPE qtype) |
Set quantization type. | |
NNFW_STATUS | nnfw_set_quantized_model_path (nnfw_session *session, const char *path) |
Set exported quantized model path. | |
NNFW_STATUS | nnfw_quantize (nnfw_session *session) |
Quantize circle model. | |
NNFW_STATUS | nnfw_set_codegen_model_path (nnfw_session *session, const char *path) |
Set exported codegen model path. | |
NNFW_STATUS | nnfw_codegen (nnfw_session *session, const char *target, NNFW_CODEGEN_PREF pref) |
Generate target-dependent code. | |
NNFW_STATUS | nnfw_set_odc_param_minmax_records_count (nnfw_session *session, int minmax_records_count) |
Set MinMax records count in auto compilation mode with on-device compiler. | |
NNFW_STATUS | nnfw_odc_delete_minmax_file (nnfw_session *session) |
Delete MinMax file for on-device compiler. | |
NNFW_STATUS | nnfw_run_with_auto_compilation (nnfw_session *session, const char *target, NNFW_CODEGEN_PREF pref) |
Run inference with auto compilation. | |
NNFW_STATUS | nnfw_set_prepare_config (nnfw_session *session, const NNFW_PREPARE_CONFIG key, const char *value) |
Set prepare configuration. | |
NNFW_STATUS | nnfw_reset_prepare_config (nnfw_session *session) |
Reset prepare configurations. | |
NNFW_STATUS | nnfw_set_execute_config (nnfw_session *session, const NNFW_RUN_CONFIG key, const char *value) |
Set execution (run or train) configuration. | |
NNFW_STATUS | nnfw_reset_execute_config (nnfw_session *session) |
Reset execution (run or train) configurations. | |
#define NNFW_RETURN_ERROR_IF_NULL | ( | p | ) |
Definition at line 51 of file nnfw_api.cc.
#define STATIC_ASSERT_ENUM_CHECK | ( | ENUM, | |
VAL | |||
) | static_assert((ENUM) == (VAL), #ENUM " has changed") |
Definition at line 25 of file nnfw_api.cc.
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
[in] | session | Session to the input tensor info is to be set |
[in] | index | Index of input to be applied (0-indexed) |
[in] | tensor_info | Tensor info to be applied |
NNFW_STATUS_NO_ERROR
if successful, otherwise return NNFW_STATUS_ERROR
Definition at line 155 of file nnfw_api.cc.
References nnfw_session::deprecated().
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.
[in] | session | The session to run inference |
NNFW_STATUS_NO_ERROR
if successful Definition at line 90 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
Referenced by NNFW_SESSION::wait().
NNFW_STATUS nnfw_close_session | ( | nnfw_session * | session | ) |
Close a session instance.
After called, access to closed session by application will be invalid
[in] | session | The session to be closed |
NNFW_STATUS_NO_ERROR
if successful Definition at line 60 of file nnfw_api.cc.
References NNFW_STATUS_NO_ERROR.
Referenced by NNFW_SESSION::close_session(), and main().
NNFW_STATUS nnfw_codegen | ( | nnfw_session * | session, |
const char * | target, | ||
NNFW_CODEGEN_PREF | pref | ||
) |
Generate target-dependent code.
This function opens a dynamic shared object. It searches for the object as flollows ld.so(8) search rules. If the nnfw_set_codegen_model_path
is not called before this function, the codegen model path is automatically defined and used using the same directory of the original model/package with the target backend extension.
[in] | session | nnfw_session the session which contains information about compilation |
[in] | target | Target backend to generate code This target string will be used to find a backend library. The name of target backend library should follow the following rules: 'lib' + {backend extension} + '-gen' + {lib extension} And the target string should be a name except 'lib' and {lib extension}. For example, if the backend extension is 'aaa', the backend library should be 'libaaa-gen.so', and the target string should be 'aaa-gen'. |
[in] | pref | NNFW_CODEGEN_PREF |
NNFW_STATUS_NO_ERROR
if successful, otherwise return NNFW_STATUS_ERROR
Definition at line 347 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
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
[out] | session | The session to be created |
Definition at line 58 of file nnfw_api.cc.
References nnfw_session::create().
Referenced by main(), and NNFW_SESSION::NNFW_SESSION().
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
[in] | session | Session from input information is to be extracted |
[out] | number | Variable which the number of inputs is put into |
NNFW_STATUS_NO_ERROR
if successful Definition at line 110 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
Referenced by NNFW_SESSION::input_size().
NNFW_STATUS nnfw_input_tensorindex | ( | nnfw_session * | session, |
const char * | tensorname, | ||
uint32_t * | index | ||
) |
Get the input tensor index by name.
This function finds an input tensor of the given name. If found, the index value is set to the address that index
points to, and returns NNFW_STATUS_NO_ERROR
. Otherwise, index
is unchanged and returns NNFW_STATUS_ERROR
.
[in] | session | the session object |
[in] | tensorname | the name of the tensor to find, a null terminated char pointer string |
[out] | index | the index to be ret |
NNFW_STATUS_NO_ERROR
if successful Definition at line 197 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
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
.
[in] | session | Session from input information is to be extracted |
[in] | index | Index of input |
[out] | tensor_info | Tensor info (shape, type, etc) |
NNFW_STATUS_NO_ERROR
if successful Definition at line 134 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
Referenced by NNFW_SESSION::input_tensorinfo(), main(), and NNFW_SESSION::set_input().
NNFW_STATUS nnfw_load_model_from_file | ( | nnfw_session * | session, |
const char * | package_file_path | ||
) |
Load model from nnpackage file or directory.
Load model from path to model or nnpackage.
The length of package_file_path
must not exceed 1024 bytes including zero at the end.
[in] | session | nnfw_session loading the given nnpackage file/dir |
[in] | package_file_path | Path to the nnpackage file or unzipped directory to be loaded |
NNFW_STATUS_NO_ERROR
if successful Definition at line 66 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
Referenced by main(), and NNFW_SESSION::NNFW_SESSION().
NNFW_STATUS nnfw_odc_delete_minmax_file | ( | nnfw_session * | session | ) |
Delete MinMax file for on-device compiler.
[in] | session | nnfw_session |
NNFW_STATUS_NO_ERROR
if successful, otherwise return NNFW_STATUS_ERROR
Definition at line 359 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
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
[in] | session | Session from output information is to be extracted |
[out] | number | Variable which the number of outputs is put into |
NNFW_STATUS_NO_ERROR
if successful Definition at line 116 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
Referenced by NNFW_SESSION::output_size().
NNFW_STATUS nnfw_output_tensorindex | ( | nnfw_session * | session, |
const char * | tensorname, | ||
uint32_t * | index | ||
) |
Get the input tensor index by name.
This function finds an input tensor of the given name. If found, the index value is set to the address that index
points to, and returns NNFW_STATUS_NO_ERROR
. Otherwise, index
is unchanged and returns NNFW_STATUS_ERROR
.
[in] | session | the session object |
[in] | tensorname | the name of the tensor to find, a null terminated char pointer string |
[out] | index | the index to be ret |
NNFW_STATUS_NO_ERROR
if successful Definition at line 203 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
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.
[in] | session | Session from output information is to be extracted |
[in] | index | Index of output |
[out] | tensor_info | Tensor info (shape, type, etc) |
NNFW_STATUS_NO_ERROR
if successful Definition at line 141 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
Referenced by main(), NNFW_SESSION::output_tensorinfo(), and NNFW_SESSION::set_output().
NNFW_STATUS nnfw_pop_pipeline_output | ( | nnfw_session * | session, |
void * | outputs | ||
) |
Get last outputs of partitioned model in session.
This function must be called after nnfw_prepare_pipeline
, outputs
given to this function must be cleared for memory management.
[in] | session | Session from last outputs is to be extracted |
[out] | outputs | Raw buffer for outputs, it must be std::vector<void *> type pointer for multiple output model |
NNFW_STATUS_NO_ERROR
if successful Definition at line 225 of file nnfw_api.cc.
References nnfw_session::deprecated().
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.
[in] | session | the session to be prepared |
NNFW_STATUS_NO_ERROR
if successful, otherwise return NNFW_STATUS_ERROR
Definition at line 72 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
Referenced by main(), and NNFW_SESSION::NNFW_SESSION().
NNFW_STATUS nnfw_prepare_pipeline | ( | nnfw_session * | session, |
const char * | map_file_path = nullptr |
||
) |
Prepare session to be ready for inference.
This phase may finalize model compilation, scheduling, and additional settings.
session | the session to be prepared |
Definition at line 215 of file nnfw_api.cc.
References nnfw_session::deprecated().
NNFW_STATUS nnfw_push_pipeline_input | ( | nnfw_session * | session, |
void * | inputs, | ||
void * | lengths | ||
) |
Set input buffer.
This function must be called after nnfw_prepare_pipeline
, inputs
given to this function can be reused for many inferences. lengths
must be greater or equal than the operand requires. if you give empty inputs
to this function, then this function will join all threads.
[in] | session | Session to the input is to be set |
[in] | inputs | Raw buffers for input, it must be std::vector<void *> type pointer for multiple input model |
[in] | lengths | Size of bytes of input buffers, it must be std::vector<uint32_t> type pointer for multiple input model |
NNFW_STATUS_NO_ERROR
if successful Definition at line 220 of file nnfw_api.cc.
References nnfw_session::deprecated().
NNFW_STATUS nnfw_quantize | ( | nnfw_session * | session | ) |
Quantize circle model.
[in] | session | nnfw_session to quantize |
ODC_STATUS_NO_ERROR
if successful, otherwise return ODC_STATUS_ERROR
Definition at line 335 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
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
[in] | session | session to be queried on. |
[in] | id | ID to be queried |
[out] | val | uint32 value to be returned. |
NNFW_STATUS_NO_ERROR
if successful Definition at line 178 of file nnfw_api.cc.
References NNFW_INFO_ID_VERSION, NNFW_STATUS_ERROR, NNFW_STATUS_NO_ERROR, and NNFW_VERSION.
NNFW_STATUS nnfw_register_custom_op_info | ( | nnfw_session * | session, |
const char * | id, | ||
custom_kernel_registration_info * | info | ||
) |
Definition at line 148 of file nnfw_api.cc.
References info, and NNFW_RETURN_ERROR_IF_NULL.
NNFW_STATUS nnfw_reset_execute_config | ( | nnfw_session * | session | ) |
Reset execution (run or train) configurations.
This function reset all execution configuration.
[in] | session | nnfw_session to reset all execution configurations |
NNFW_STATUS_NO_ERROR
if successful Definition at line 394 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
NNFW_STATUS nnfw_reset_prepare_config | ( | nnfw_session * | session | ) |
Reset prepare configurations.
This function reset all prepare configuration.
[in] | session | nnfw_session to reset all prepare configurations |
NNFW_STATUS_NO_ERROR
if successful Definition at line 381 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
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.
[in] | session | The session to run inference |
NNFW_STATUS_NO_ERROR
if successful Definition at line 78 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
Referenced by main(), and NNFW_SESSION::run().
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.
[in] | session | The session to run inference |
NNFW_STATUS_NO_ERROR
if successful Definition at line 84 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
Referenced by NNFW_SESSION::run_async().
NNFW_STATUS nnfw_run_with_auto_compilation | ( | nnfw_session * | session, |
const char * | target, | ||
NNFW_CODEGEN_PREF | pref | ||
) |
Run inference with auto compilation.
This function runs inference with automatic compilation and replaces the original model with a quantized or compiled model inside. During the inference the minmax statistics is collected and after that quantization is performed. If quantization was successful, try to code generating for target backend, otherwise run original float model. If compilation was successful, run compiled model, otherwise run quantized model. On-device compiler (ODC) provides quantization and compilation functionality. 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
.
Additionally the following parameters should be set up :
nnfw_set_quantization_type
nnfw_set_quantized_model_path
nnfw_set_odc_param_minmax_records_count
nnfw_odc_delete_minmax_file
nnfw_set_codegen_model_path
[in] | session | nnfw_session |
[in] | target | Target backend to generate code as in nnfw_codegen |
[in] | pref | NNFW_CODEGEN_PREF |
NNFW_STATUS_NO_ERROR
if successful, otherwise return NNFW_STATUS_ERROR
Definition at line 365 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
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.
[in] | session | session to which avilable backends are set |
[in] | backends | available backends on which nnfw uses |
NNFW_STATUS_NO_ERROR
if successful Definition at line 167 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
Referenced by NNFW_SESSION::NNFW_SESSION().
NNFW_STATUS nnfw_set_backends_per_operation | ( | nnfw_session * | session, |
const char * | backend_settings | ||
) |
Set the backend for each operation in the session.
This function assigns backends (acl_cl, acl_neon, cpu) to each operation in the session. If successful,the function returns NNFW_STATUS_NO_ERROR
. Otherwise, the function returns NNFW_STATUS_ERROR
.
[in] | session | the session object |
[in] | backend_settings | String containing backend assignments indexed by operation sequence |
NNFW_STATUS_NO_ERROR
if successful Definition at line 209 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
NNFW_STATUS nnfw_set_codegen_model_path | ( | nnfw_session * | session, |
const char * | path | ||
) |
Set exported codegen model path.
This function should be called before nnfw_codegen
is invoked.
[in] | session | nnfw_session to set codegen model path |
[in] | path | Target-dependent model path |
NNFW_STATUS_NO_ERROR
if successful, otherwise return NNFW_STATUS_ERROR
Definition at line 341 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
NNFW_STATUS nnfw_set_execute_config | ( | nnfw_session * | session, |
const NNFW_RUN_CONFIG | key, | ||
const char * | value | ||
) |
Set execution (run or train) configuration.
This function set execution configuration to dump execution data to workspace. If you enable configuration to dump execution data into workspace and want to change workspace, refer nnfw_set_workspace
to use workspace directory.
[in] | session | nnfw_session to set execution configuration |
[in] | key | execution configuration key |
[in] | value | execution configuration value if needed, otherwise set NULL |
NNFW_STATUS_NO_ERROR
if successful Definition at line 387 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
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.
[in] | session | Session to the input is to be set |
[in] | index | Index of input to be set (0-indexed) |
[in] | type | Type of the input |
[in] | buffer | Raw buffer for input |
[in] | length | Size of bytes of input buffer |
NNFW_STATUS_NO_ERROR
if successful Definition at line 96 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
Referenced by main(), and NNFW_SESSION::set_input().
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
[in] | session | session from inference input is to be extracted |
[in] | index | index of input to be set (0-indexed) |
[in] | layout | layout to set to target input |
Definition at line 122 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
Referenced by NNFW_SESSION::set_input_layout().
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.
[in] | session | Session to the input tensor info is to be set |
[in] | index | Index of input to be set (0-indexed) |
[in] | tensor_info | Tensor info to be set |
NNFW_STATUS_NO_ERROR
if successful, otherwise return NNFW_STATUS_ERROR
Definition at line 160 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
Referenced by NNFW_SESSION::set_input_tensorinfo().
NNFW_STATUS nnfw_set_odc_param_minmax_records_count | ( | nnfw_session * | session, |
int | minmax_records_count | ||
) |
Set MinMax records count in auto compilation mode with on-device compiler.
This function set MinMax records count for quantization in auto compilation mode. To enable automatic compilation mode, use nnfw_run_with_auto_compilation
[in] | session | nnfw_session |
[in] | minmax_records_count | minmax records count |
NNFW_STATUS_NO_ERROR
if successful, otherwise return NNFW_STATUS_ERROR
Definition at line 353 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
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
.
[in] | session | session to be modified |
[in] | op | operation to be set |
[in] | backend | bakcend on which operation run |
NNFW_STATUS_NO_ERROR
if successful Definition at line 173 of file nnfw_api.cc.
References nnfw_session::deprecated().
Referenced by main().
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.
[in] | session | Session from inference output is to be extracted |
[in] | index | Index of output to be set (0-indexed) |
[in] | type | Type of the output |
[out] | buffer | Raw buffer for output |
[in] | length | Size of bytes of output buffer |
NNFW_STATUS_NO_ERROR
if successful Definition at line 103 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
Referenced by main(), and NNFW_SESSION::set_output().
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
[in] | session | session from inference output is to be extracted |
[in] | index | index of output to be set (0-indexed) |
[in] | layout | layout to set to target output |
Definition at line 128 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
Referenced by NNFW_SESSION::set_output_layout().
NNFW_STATUS nnfw_set_prepare_config | ( | nnfw_session * | session, |
NNFW_PREPARE_CONFIG | key, | ||
const char * | value | ||
) |
Set prepare configuration.
This function set prepare configuration to decide additional compiling and scheduing feature. If you enable configuration to prepare dumping execution data into workspace, refer nnfw_set_workspace
to use workspace directory.
[in] | session | nnfw_session to set prepare configuration |
[in] | key | prepare configuration key |
[in] | value | prepare configuration value |
NNFW_STATUS_NO_ERROR
if successful Definition at line 374 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
NNFW_STATUS nnfw_set_quantization_type | ( | nnfw_session * | session, |
NNFW_QUANTIZE_TYPE | qtype | ||
) |
Set quantization type.
This function should be called before nnfw_quantize
is invoked.
[in] | session | nnfw_session to set quantization type |
[in] | pref | NNFW_QUANTIZE_TYPE |
NNFW_STATUS_NO_ERROR
if successful, NNFW_STATUS_UNEXPECTED_NULL
if session is null, otherwise return NNFW_STATUS_ERROR
Definition at line 323 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
NNFW_STATUS nnfw_set_quantized_model_path | ( | nnfw_session * | session, |
const char * | path | ||
) |
Set exported quantized model path.
This function should be called before nnfw_quantize
is invoked.
TODO: If this function is not called, quantized model will not be exported
[in] | session | nnfw_session to set quantized model path |
[in] | path | Quantized model path |
NNFW_STATUS_NO_ERROR
if successful, otherwise return NNFW_STATUS_ERROR
Definition at line 329 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
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.
[in] | session | session to be queried on. |
[in] | dir | workspace directory path |
NNFW_STATUS_NO_ERROR
if successful Definition at line 230 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
NNFW_STATUS nnfw_train | ( | nnfw_session * | session, |
bool | update_weights | ||
) |
Train the model.
nnfw_train_set_input
and nnfw_train_set_expected
for each input and expected outputIn order to use update_weights
as false, it should be called after nnfw_train_set_output
.
[in] | session | The session to be trained |
[in] | update_weights | If true, update weights of the model If false, do not update weights of the model (for validation) |
NNFW_STATUS_NO_ERROR
if successful Definition at line 291 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
NNFW_STATUS nnfw_train_expected_tensorinfo | ( | nnfw_session * | session, |
uint32_t | index, | ||
nnfw_tensorinfo * | info | ||
) |
Get the training model expected output information.
nnfw_train_prepare
[in] | session | The session to get the training model expected output information |
[in] | index | The index of training model expected output |
[out] | info | The shape and type of training model expected output |
NNFW_STATUS_NO_ERROR
if successful Definition at line 263 of file nnfw_api.cc.
References info, and NNFW_RETURN_ERROR_IF_NULL.
NNFW_STATUS nnfw_train_export_checkpoint | ( | nnfw_session * | session, |
const char * | path | ||
) |
Export circle checkpoint.
nnfw_train
[in] | session | The session to export a checkpoint |
[in] | path | The path to export a checkpoint |
NNFW_STATUS_NO_ERROR
if successful Definition at line 315 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
NNFW_STATUS nnfw_train_export_circle | ( | nnfw_session * | session, |
const char * | path | ||
) |
Export current training model into circle model.
Export circle model.
nnfw_train
[in] | session | The session to export inference model |
[in] | path | The path to export inference model |
NNFW_STATUS_NO_ERROR
if successful Definition at line 303 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
NNFW_STATUS nnfw_train_get_loss | ( | nnfw_session * | session, |
uint32_t | index, | ||
float * | loss | ||
) |
Get loss value for expected output.
nnfw_train
[in] | session | The session to get loss value |
[in] | index | The index of loss value [0, number of expected outputs) |
[out] | loss | The loss value |
NNFW_STATUS_NO_ERROR
if successful Definition at line 297 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
NNFW_STATUS nnfw_train_get_traininfo | ( | nnfw_session * | session, |
nnfw_train_info * | info | ||
) |
Get training information.
nnfw_load_model_from_file
For the field which is not set in training information, it returns training information filled with default value. The default value of each field is as follows : learning_rate = 0.0f, batch_size = 0, *_UNDEF for other enums
[in] | session | The session to get training information |
[out] | info | Training information |
NNFW_STATUS_NO_ERROR
if successful Definition at line 238 of file nnfw_api.cc.
References info, and NNFW_RETURN_ERROR_IF_NULL.
NNFW_STATUS nnfw_train_import_checkpoint | ( | nnfw_session * | session, |
const char * | path | ||
) |
Import circle checkpoint.
nnfw_train
[in] | session | The session to export a checkpoint |
[in] | path | The path to export a checkpoint |
NNFW_STATUS_NO_ERROR
if successful Definition at line 309 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
NNFW_STATUS nnfw_train_input_tensorinfo | ( | nnfw_session * | session, |
uint32_t | index, | ||
nnfw_tensorinfo * | info | ||
) |
Get the training model input information.
nnfw_train_prepare
[in] | session | The session to get the training model input information |
[in] | index | The index of training model input |
[out] | info | The shape and type of training model input |
NNFW_STATUS_NO_ERROR
if successful Definition at line 256 of file nnfw_api.cc.
References info, and NNFW_RETURN_ERROR_IF_NULL.
NNFW_STATUS nnfw_train_prepare | ( | nnfw_session * | session | ) |
Prepare session to be ready for training.
If training info is NOT set in session, this function returns @c NNFW_STATUS_ERROR . You should set training info using {@link nnfw_train_set_traininfo}.
[in] | session | The session to be prepared for training |
NNFW_STATUS_NO_ERROR
if successful Definition at line 250 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
NNFW_STATUS nnfw_train_set_expected | ( | nnfw_session * | session, |
uint32_t | index, | ||
const void * | expected, | ||
const nnfw_tensorinfo * | expected_info | ||
) |
Set training expected output.
nnfw_train_prepare
session | The session to be set training inputs and expected model outputs |
index | The index of training expected output |
expected | The expected buffers for training |
expected_info | The shape and type of expected buffer If it is nullptr, it will not change shape and batch size |
NNFW_STATUS_NO_ERROR
if successful Definition at line 277 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
NNFW_STATUS nnfw_train_set_input | ( | nnfw_session * | session, |
uint32_t | index, | ||
const void * | input, | ||
const nnfw_tensorinfo * | input_info | ||
) |
Set training input.
nnfw_train_prepare
[in] | session | The session to be set training inputs and expected model outputs |
[in] | index | The index of training input |
[in] | input | The input buffers for training |
[in] | input_info | The shape and type of input buffer If it is nullptr, it will not change shape and batch size |
NNFW_STATUS_NO_ERROR
if successful Definition at line 270 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
NNFW_STATUS nnfw_train_set_output | ( | nnfw_session * | session, |
uint32_t | index, | ||
NNFW_TYPE | type, | ||
void * | buffer, | ||
size_t | length | ||
) |
Set training output buffer.
This function must be called after nnfw_train_prepare
, buffer
given to this function can be reused for training. 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.
[in] | session | Session from inference output is to be extracted |
[in] | index | Index of output to be set (0-indexed) |
[in] | type | Type of the output |
[out] | buffer | Raw buffer for output |
[in] | length | Size of bytes of output buffer |
NNFW_STATUS_NO_ERROR
if successful Definition at line 284 of file nnfw_api.cc.
References NNFW_RETURN_ERROR_IF_NULL.
NNFW_STATUS nnfw_train_set_traininfo | ( | nnfw_session * | session, |
const nnfw_train_info * | info | ||
) |
Set training information.
nnfw_load_model_from_file
and before calling nnfw_train_prepare
[in] | session | The session to be set training information |
[in] | info | The training information |
NNFW_STATUS_NO_ERROR
if successful Definition at line 244 of file nnfw_api.cc.
References info, and NNFW_RETURN_ERROR_IF_NULL.
STATIC_ASSERT_ENUM_CHECK | ( | NNFW_INFO_ID_VERSION | , |
0 | |||
) |
STATIC_ASSERT_ENUM_CHECK | ( | NNFW_LAYOUT_CHANNELS_FIRST | , |
2 | |||
) |
STATIC_ASSERT_ENUM_CHECK | ( | NNFW_LAYOUT_CHANNELS_LAST | , |
1 | |||
) |
STATIC_ASSERT_ENUM_CHECK | ( | NNFW_LAYOUT_NONE | , |
0 | |||
) |
STATIC_ASSERT_ENUM_CHECK | ( | NNFW_STATUS_ERROR | , |
1 | |||
) |
STATIC_ASSERT_ENUM_CHECK | ( | NNFW_STATUS_INSUFFICIENT_OUTPUT_SIZE | , |
5 | |||
) |
STATIC_ASSERT_ENUM_CHECK | ( | NNFW_STATUS_INVALID_STATE | , |
3 | |||
) |
STATIC_ASSERT_ENUM_CHECK | ( | NNFW_STATUS_NO_ERROR | , |
0 | |||
) |
STATIC_ASSERT_ENUM_CHECK | ( | NNFW_STATUS_OUT_OF_MEMORY | , |
4 | |||
) |
STATIC_ASSERT_ENUM_CHECK | ( | NNFW_STATUS_UNEXPECTED_NULL | , |
2 | |||
) |
STATIC_ASSERT_ENUM_CHECK | ( | NNFW_TYPE_TENSOR_BOOL | , |
3 | |||
) |
STATIC_ASSERT_ENUM_CHECK | ( | NNFW_TYPE_TENSOR_FLOAT32 | , |
0 | |||
) |
STATIC_ASSERT_ENUM_CHECK | ( | NNFW_TYPE_TENSOR_INT32 | , |
1 | |||
) |
STATIC_ASSERT_ENUM_CHECK | ( | NNFW_TYPE_TENSOR_INT64 | , |
5 | |||
) |
STATIC_ASSERT_ENUM_CHECK | ( | NNFW_TYPE_TENSOR_QUANT16_SYMM_SIGNED | , |
7 | |||
) |
STATIC_ASSERT_ENUM_CHECK | ( | NNFW_TYPE_TENSOR_QUANT8_ASYMM | , |
2 | |||
) |
STATIC_ASSERT_ENUM_CHECK | ( | NNFW_TYPE_TENSOR_QUANT8_ASYMM_SIGNED | , |
6 | |||
) |
STATIC_ASSERT_ENUM_CHECK | ( | NNFW_TYPE_TENSOR_UINT8 | , |
4 | |||
) |