ONE - On-device Neural Engine
Loading...
Searching...
No Matches
nnfw_experimental.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef __NNFW_EXPERIMENTAL_H__
18#define __NNFW_EXPERIMENTAL_H__
19
20#include "nnfw.h"
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26// Used for custom kernel development
27
28/*
29 * operand type, used only for custom operations
30 */
31typedef struct
32{
36
37/*
38 * Used as input to custom operation eval function
39 */
48
49/*
50 * Custom kernel evaluation function
51 *
52 * param[in] params custom operation parameters
53 * param[in] userdata pointer to user-specified buffer( kernel instance specific )
54 */
55typedef void (*nnfw_custom_eval)(nnfw_custom_kernel_params *params, char *userdata,
56 size_t userdata_size);
57
58/*
59 * custom operation registration info
60 */
65
68
84NNFW_STATUS nnfw_input_tensorindex(nnfw_session *session, const char *tensorname, uint32_t *index);
85
101NNFW_STATUS nnfw_output_tensorindex(nnfw_session *session, const char *tensorname, uint32_t *index);
102
117NNFW_STATUS nnfw_set_backends_per_operation(nnfw_session *session, const char *backend_settings);
118
129NNFW_STATUS nnfw_prepare_pipeline(nnfw_session *session, const char *map_file_path = nullptr);
130
148NNFW_STATUS nnfw_push_pipeline_input(nnfw_session *session, void *inputs, void *lengths);
149
164NNFW_STATUS nnfw_pop_pipeline_output(nnfw_session *session, void *outputs);
165
182// Essential APIs for training
190
200
207
208typedef struct nnfw_loss_info
209{
213
228
234typedef struct nnfw_train_info
235{
237 float learning_rate = 0.001f;
239 uint32_t batch_size = 1;
251
259
274
286
299
311NNFW_STATUS nnfw_train_set_input(nnfw_session *session, uint32_t index, const void *input,
312 const nnfw_tensorinfo *input_info);
313
325NNFW_STATUS nnfw_train_set_expected(nnfw_session *session, uint32_t index, const void *expected,
326 const nnfw_tensorinfo *expected_info);
327
344NNFW_STATUS nnfw_train_set_output(nnfw_session *session, uint32_t index, NNFW_TYPE type,
345 void *buffer, size_t length);
346
360NNFW_STATUS nnfw_train(nnfw_session *session, bool update_weights);
361
371NNFW_STATUS nnfw_train_get_loss(nnfw_session *session, uint32_t index, float *loss);
372
382NNFW_STATUS nnfw_train_export_circle(nnfw_session *session, const char *path);
383
393NNFW_STATUS nnfw_train_import_checkpoint(nnfw_session *session, const char *path);
394
404NNFW_STATUS nnfw_train_export_checkpoint(nnfw_session *session, const char *path);
405
407// Optional APIs for training
409
421
433
435// Not planned to be implemented
437
447// NNFW_STATUS nnfw_set_training_mode(nnfw_session *session, bool train);
448
478
491
503NNFW_STATUS nnfw_set_quantized_model_path(nnfw_session *session, const char *path);
504
512
528
538NNFW_STATUS nnfw_set_codegen_model_path(nnfw_session *session, const char *path);
539
559NNFW_STATUS nnfw_codegen(nnfw_session *session, const char *target, NNFW_CODEGEN_PREF pref);
560
572 int minmax_records_count);
573
581
610NNFW_STATUS nnfw_run_with_auto_compilation(nnfw_session *session, const char *target,
611 NNFW_CODEGEN_PREF pref);
612
614// APIs for configuration
616
628
642 const char *value);
643
653
673
687 const char *value);
688
698
699#ifdef __cplusplus
700}
701#endif
702
703#endif // __NNFW_EXPERIMENTAL_H__
volatile const char info[]
This file describes runtime API.
NNFW_STATUS nnfw_prepare_pipeline(nnfw_session *session, const char *map_file_path=nullptr)
Prepare session to be ready for inference.
Definition nnfw_api.cc:215
NNFW_STATUS nnfw_set_prepare_config(nnfw_session *session, NNFW_PREPARE_CONFIG key, const char *value)
Set prepare configuration.
Definition nnfw_api.cc:374
NNFW_STATUS nnfw_train_get_loss(nnfw_session *session, uint32_t index, float *loss)
Get loss value for expected output.
NNFW_STATUS nnfw_register_custom_op_info(nnfw_session *session, const char *id, custom_kernel_registration_info *info)
Definition nnfw_api.cc:148
NNFW_STATUS nnfw_run_with_auto_compilation(nnfw_session *session, const char *target, NNFW_CODEGEN_PREF pref)
Run inference with auto compilation.
Definition nnfw_api.cc:365
NNFW_STATUS nnfw_train_export_checkpoint(nnfw_session *session, const char *path)
Export circle checkpoint.
NNFW_TRAIN_LOSS_REDUCTION
@ NNFW_TRAIN_LOSS_REDUCTION_UNDEFINED
@ NNFW_TRAIN_LOSS_REDUCTION_SUM
@ NNFW_TRAIN_LOSS_REDUCTION_SUM_OVER_BATCH_SIZE
NNFW_STATUS nnfw_train_set_expected(nnfw_session *session, uint32_t index, const void *expected, const nnfw_tensorinfo *expected_info)
Set training expected output.
Definition nnfw_api.cc:277
void(* nnfw_custom_eval)(nnfw_custom_kernel_params *params, char *userdata, size_t userdata_size)
NNFW_STATUS nnfw_output_tensorindex(nnfw_session *session, const char *tensorname, uint32_t *index)
Get the input tensor index by name.
Definition nnfw_api.cc:203
NNFW_TRAIN_OPTIMIZER
@ NNFW_TRAIN_OPTIMIZER_ADAM
@ NNFW_TRAIN_OPTIMIZER_SGD
@ NNFW_TRAIN_OPTIMIZER_UNDEFINED
NNFW_CODEGEN_PREF
Preference for target-dependent code generation.
@ NNFW_CODEGEN_PREF_DEFAULT
@ NNFW_CODEGEN_PREF_MEMORY_FIRST
@ NNFW_CODEGEN_PREF_COMPILE_TIME_FIRST
@ NNFW_CODEGEN_PREF_PERFORMANCE_FIRST
NNFW_STATUS nnfw_train_prepare(nnfw_session *session)
Prepare session to be ready for training.
NNFW_STATUS nnfw_train(nnfw_session *session, bool update_weights)
Train the model.
NNFW_TRAIN_NUM_OF_TRAINABLE_OPS_SPECIAL_VALUES
Special values of num_of_trainable_ops. Positive values are used to indicate layers to be trained fro...
@ NNFW_TRAIN_TRAINABLE_NONE
@ NNFW_TRAIN_TRAINABLE_ALL
@ NNFW_TRAIN_TRAINABLE_INCORRECT_STATE
NNFW_STATUS nnfw_set_quantization_type(nnfw_session *session, NNFW_QUANTIZE_TYPE qtype)
Set quantization type.
Definition nnfw_api.cc:323
NNFW_STATUS nnfw_train_set_traininfo(nnfw_session *session, const nnfw_train_info *info)
Set training information.
NNFW_STATUS nnfw_train_get_traininfo(nnfw_session *session, nnfw_train_info *info)
Get training information.
Definition nnfw_api.cc:238
NNFW_STATUS nnfw_input_tensorindex(nnfw_session *session, const char *tensorname, uint32_t *index)
Get the input tensor index by name.
Definition nnfw_api.cc:197
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.
Definition nnfw_api.cc:353
NNFW_STATUS nnfw_codegen(nnfw_session *session, const char *target, NNFW_CODEGEN_PREF pref)
Generate target-dependent code.
Definition nnfw_api.cc:347
NNFW_QUANTIZE_TYPE
Convert between training mode and inference mode.
@ NNFW_QUANTIZE_TYPE_WO_I16_SYM
@ NNFW_QUANTIZE_TYPE_U8_ASYM
@ NNFW_QUANTIZE_TYPE_I16_SYM
@ NNFW_QUANTIZE_TYPE_NOT_SET
@ NNFW_QUANTIZE_TYPE_WO_I8_SYM
NNFW_RUN_CONFIG
Configuration key for execution.
@ NNFW_RUN_CONFIG_PROFILE
@ NNFW_RUN_CONFIG_TRACE
@ NNFW_RUN_CONFIG_DUMP_MINMAX
NNFW_STATUS nnfw_quantize(nnfw_session *session)
Quantize circle model.
Definition nnfw_api.cc:335
NNFW_STATUS nnfw_train_set_input(nnfw_session *session, uint32_t index, const void *input, const nnfw_tensorinfo *input_info)
Set training input.
Definition nnfw_api.cc:270
NNFW_STATUS nnfw_reset_prepare_config(nnfw_session *session)
Reset prepare configurations.
Definition nnfw_api.cc:381
NNFW_STATUS nnfw_reset_execute_config(nnfw_session *session)
Reset execution (run or train) configurations.
Definition nnfw_api.cc:394
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_set_execute_config(nnfw_session *session, const NNFW_RUN_CONFIG key, const char *value)
Set execution (run or train) configuration.
Definition nnfw_api.cc:387
NNFW_STATUS nnfw_train_import_checkpoint(nnfw_session *session, const char *path)
Import circle checkpoint.
NNFW_STATUS nnfw_push_pipeline_input(nnfw_session *session, void *inputs, void *lengths)
Set input buffer.
Definition nnfw_api.cc:220
NNFW_STATUS nnfw_set_backends_per_operation(nnfw_session *session, const char *backend_settings)
Set the backend for each operation in the session.
Definition nnfw_api.cc:209
NNFW_STATUS nnfw_odc_delete_minmax_file(nnfw_session *session)
Delete MinMax file for on-device compiler.
Definition nnfw_api.cc:359
NNFW_STATUS nnfw_pop_pipeline_output(nnfw_session *session, void *outputs)
Get last outputs of partitioned model in session.
Definition nnfw_api.cc:225
NNFW_TRAIN_LOSS
@ NNFW_TRAIN_LOSS_MEAN_SQUARED_ERROR
@ NNFW_TRAIN_LOSS_UNDEFINED
@ NNFW_TRAIN_LOSS_CATEGORICAL_CROSSENTROPY
NNFW_STATUS nnfw_set_codegen_model_path(nnfw_session *session, const char *path)
Set exported codegen model path.
Definition nnfw_api.cc:341
NNFW_STATUS nnfw_set_quantized_model_path(nnfw_session *session, const char *path)
Set exported quantized model path.
Definition nnfw_api.cc:329
NNFW_STATUS nnfw_train_input_tensorinfo(nnfw_session *session, uint32_t index, nnfw_tensorinfo *info)
Get the training model input information.
Definition nnfw_api.cc:256
NNFW_PREPARE_CONFIG
Configuration key for prepare (compile and schedule)
@ NNFW_PREPARE_CONFIG_PROFILE
NNFW_STATUS nnfw_train_expected_tensorinfo(nnfw_session *session, uint32_t index, nnfw_tensorinfo *info)
Get the training model expected output information.
Definition nnfw_api.cc:263
NNFW_STATUS nnfw_train_export_circle(nnfw_session *session, const char *path)
Export circle model.
NNFW_STATUS
Result values returned from a call to an API function.
Definition onert-micro.h:86
NNFW_TRAIN_LOSS_REDUCTION
NNFW_TRAIN_OPTIMIZER
NNFW_TRAIN_LOSS
NNFW_TYPE
Definition onert-micro.h:75
NNFW_TRAIN_LOSS_REDUCTION reduction_type
NNFW_TRAIN_LOSS loss
nnfw_tensorinfo type
tensor info describes the type and shape of tensors
Training information to prepare training.
uint32_t batch_size
nnfw_loss_info loss_info
NNFW_TRAIN_OPTIMIZER opt