diff options
Diffstat (limited to 'runtimes/include/nnfw.h')
-rw-r--r-- | runtimes/include/nnfw.h | 200 |
1 files changed, 200 insertions, 0 deletions
diff --git a/runtimes/include/nnfw.h b/runtimes/include/nnfw.h new file mode 100644 index 000000000..456781e70 --- /dev/null +++ b/runtimes/include/nnfw.h @@ -0,0 +1,200 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __NNFW_H__ +#define __NNFW_H__ + +#include <stddef.h> +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct nnfw_session nnfw_session; +typedef struct nnfw_tensorinfo nnfw_tensorinfo; + +typedef enum { + NNFW_TYPE_TENSOR_FLOAT32 = 0, + NNFW_TYPE_TENSOR_INT32 = 1, + /** + * A tensor of 8 bit integers that represent real numbers. + * + * real_value = (integer_value - zeroPoint) * scale. + */ + NNFW_TYPE_TENSOR_QUANT8_ASYMM = 2, + NNFW_TYPE_TENSOR_BOOL = 3, +} NNFW_TYPE; + +/** + * Result Values + */ +typedef enum { + NNFW_STATUS_NO_ERROR = 0, + NNFW_STATUS_ERROR = 1, +} NNFW_STATUS; + +/** + * tensor_info + */ +struct nnfw_tensorinfo +{ + NNFW_TYPE dtype; + int rank; + int dims[6]; // MAX rank is 6 +}; + +/* + * Create a new session instance + * + * @param[out] session the session to be created + * @return NNFW_STATUS_NO_ERROR if successful + */ +NNFW_STATUS nnfw_create_session(nnfw_session **session); + +/* + * Close a session instance + * + * @param[in] session the session to be closed + * @return NNFW_STATUS_NO_ERROR if successful + */ +NNFW_STATUS nnfw_close_session(nnfw_session *session); + +/* + * Load model from nnpackage file or directory + * + * @param[in] session nnfw_session loading the given nnpackage file/dir + * @param[in] package_file_path path to the nnpackage file or unzipped directory to be loaded + * + * @return NNFW_STATUS_NO_ERROR if successful + */ +NNFW_STATUS nnfw_load_model_from_file(nnfw_session *session, const char *package_file_path); + +/* + * Prepare session to be ready for inference + * This phase may finalize model compilation, scheduling, and additional settings. + * + * @param[in] session the session to be prepared + * @return NNFW_STATUS_NO_ERROR if successful + */ +NNFW_STATUS nnfw_prepare(nnfw_session *session); + +/* + * Run inference + * + * @param[in] session the session to run inference + * @return NNFW_STATUS_NO_ERROR if successful + */ +NNFW_STATUS nnfw_run(nnfw_session *session); + +/* + * Set input + * + * @param[in] session session to the input is to be set + * @param[in] index index of input to be set (0-indexed) + * @param[in] type type of the input + * @param[in] buffer raw buffer for input + * @param[in] length size of bytes of output + * + * @return NNFW_STATUS_NO_ERROR if successful + */ + +NNFW_STATUS nnfw_set_input(nnfw_session *session, uint32_t index, NNFW_TYPE type, + const void *buffer, size_t length); + +/* + * Set output + * + * @param[in] session session from inference output is to be extracted + * @param[in] index index of output to be set (0-indexed) + * @param[in] type type of the output + * @param[out] buffer raw buffer for output + * @param[in] length size of bytes of output + * + * @return NNFW_STATUS_NO_ERROR if successful + */ + +NNFW_STATUS nnfw_set_output(nnfw_session *session, uint32_t index, NNFW_TYPE type, void *buffer, + size_t length); + +/* + * Get the number of inputs + * + * @param[in] session session from input information is to be extracted + * @param[out] number variable which the number of inputs is put into + * + * @return NNFW_STATUS_NO_ERROR if successful + */ +NNFW_STATUS nnfw_input_size(nnfw_session *session, uint32_t *number); + +/* + * Get the number of outputs + * + * @param[in] session session from output information is to be extracted + * @param[out] number variable which the number of outputs is put into + * + * @return NNFW_STATUS_NO_ERROR if successful + */ +NNFW_STATUS nnfw_output_size(nnfw_session *session, uint32_t *number); + +/* + * Get i-th input tensor info + * + * @param[in] session session from input information is to be extracted + * @param[in] index index of input + * @param[out] tensor_info nnfw_tensor_info + * + * @return NNFW_STATUS_NO_ERROR if successful + */ +NNFW_STATUS nnfw_input_tensorinfo(nnfw_session *session, uint32_t index, + nnfw_tensorinfo *tensor_info); + +/* + * Get i-th output tensor info + * + * @param[in] session session from output information is to be extracted + * @param[in] index index of output + * @param[out] tensor_info nnfw_tensor_info + * + * @return NNFW_STATUS_NO_ERROR if successful + */ +NNFW_STATUS nnfw_output_tensorinfo(nnfw_session *session, uint32_t index, + nnfw_tensorinfo *tensor_info); + +/* + * Set default backend + * + * @param[in] session session to which a default backend is set + * @param[in] backend default backend + */ +NNFW_STATUS nnfw_set_default_backend(nnfw_session *session, const char *backend); + +/* + * Set the operation's backend + * + * @param[in] session session to be modified + * @param[in] op operation to be set + * @param[in] backend bakcend on which operation run + * + * @return NNFW_STATUS_NO_ERROR if successful + */ +NNFW_STATUS nnfw_set_op_backend(nnfw_session *session, const char *op, const char *backend); + +#ifdef __cplusplus +} +#endif + +#endif |