From 33d212d81222c93a451d49e2cb239179fee8e185 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=98=A4=ED=98=95=EC=84=9D/On-Device=20Lab=28SR=29/Staff?= =?utf8?q?=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Mon, 14 Oct 2019 15:36:33 +0900 Subject: [PATCH] [nnfw-api] Introduce resize input API (#8034) * [nnfw-api] Introduce resize input API Introduce API for resize input: nnfw_apply_tensorinfo Internal implementation always return error - NYI Update related API's comment based on doxygen format Signed-off-by: Hyeongseok Oh * update comment --- runtimes/include/nnfw.h | 44 ++++++++++++++++++++++++-------- runtimes/neurun/api/nnfw_api.cc | 7 +++++ runtimes/neurun/api/nnfw_api_internal.cc | 6 +++++ runtimes/neurun/api/nnfw_api_internal.h | 2 ++ 4 files changed, 49 insertions(+), 10 deletions(-) diff --git a/runtimes/include/nnfw.h b/runtimes/include/nnfw.h index 5803866..7be5f30 100644 --- a/runtimes/include/nnfw.h +++ b/runtimes/include/nnfw.h @@ -83,12 +83,31 @@ NNFW_STATUS nnfw_close_session(nnfw_session *session); */ 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. +/** + * @brief Apply i-th input's tensor info to resize input tensor + * + * This function should be called before {@link nnfw_prepare} is invoked, and + * should be called after {@link nnfw_load_model_from_file} is invoked + * See {@link nnfw_prepare} for information applying updated tensor info + * If this function is called many times for same index, tensor info is overwritten + * + * @param[in] session Session to the input tensor info is to be set + * @param[in] index Index of input to be applied (0-indexed) + * @param[in] tensor_info Tensor info to be applied + * @return @c NNFW_STATUS_NO_ERROR if successful, otherwise return @c NNFW_STATUS_ERROR + */ +NNFW_STATUS nnfw_apply_tensorinfo(nnfw_session *session, uint32_t index, + nnfw_tensorinfo tensor_info); + +/** + * @brief Prepare session to be ready for inference + * + * This phase may finalize model compilation, scheduling, and additional settings. + * If {@link nnfw_apply_tensor} is called to apply input tensor info different with model + * before this function, tries to resize all tensors. * * @param[in] session the session to be prepared - * @return NNFW_STATUS_NO_ERROR if successful + * @return @c NNFW_STATUS_NO_ERROR if successful, otherwise return @c NNFW_STATUS_ERROR */ NNFW_STATUS nnfw_prepare(nnfw_session *session); @@ -150,14 +169,19 @@ NNFW_STATUS nnfw_input_size(nnfw_session *session, uint32_t *number); */ NNFW_STATUS nnfw_output_size(nnfw_session *session, uint32_t *number); -/* - * Get i-th input tensor info +/** + * @brief 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 + * Before {@link nnfw_prepare} is invoked, this function return tensor info in model, + * so updated tensor info by {@link nnfw_apply_tensorinfo} is not returned + * After {@link nnfw_prepare} is invoked, this function return updated tensor info + * if tensor info is updated by {@link nnfw_apply_tensorinfo} * - * @return NNFW_STATUS_NO_ERROR if successful + * @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 @c NNFW_STATUS_NO_ERROR if successful, otherwise return @c NNFW_STATUS_ERROR */ NNFW_STATUS nnfw_input_tensorinfo(nnfw_session *session, uint32_t index, nnfw_tensorinfo *tensor_info); diff --git a/runtimes/neurun/api/nnfw_api.cc b/runtimes/neurun/api/nnfw_api.cc index 347053b..f7dd205 100644 --- a/runtimes/neurun/api/nnfw_api.cc +++ b/runtimes/neurun/api/nnfw_api.cc @@ -200,6 +200,13 @@ NNFW_STATUS nnfw_register_custom_op_info(nnfw_session *session, const char *id, return session->register_custom_operation(id, info->eval_function); } +NNFW_STATUS nnfw_apply_tensorinfo(nnfw_session *session, uint32_t index, + nnfw_tensorinfo tensor_info) +{ + NNFW_RETURN_ERROR_IF_NULL(session); + return session->apply_tensorinfo(index, tensor_info); +} + /* * Set default backend * diff --git a/runtimes/neurun/api/nnfw_api_internal.cc b/runtimes/neurun/api/nnfw_api_internal.cc index 7800022..01caa34 100644 --- a/runtimes/neurun/api/nnfw_api_internal.cc +++ b/runtimes/neurun/api/nnfw_api_internal.cc @@ -217,6 +217,12 @@ static NNFW_TYPE datatype_to_nnfw_dtype(neurun::model::DataType dt) } } +NNFW_STATUS nnfw_session::apply_tensorinfo(uint32_t /*index*/, nnfw_tensorinfo /*ti*/) +{ + std::cerr << "Error: NYI" << std::endl; + return NNFW_STATUS_ERROR; +} + NNFW_STATUS nnfw_session::input_tensorinfo(uint32_t index, nnfw_tensorinfo *ti) { try diff --git a/runtimes/neurun/api/nnfw_api_internal.h b/runtimes/neurun/api/nnfw_api_internal.h index e9b1e2d..49cdba2 100644 --- a/runtimes/neurun/api/nnfw_api_internal.h +++ b/runtimes/neurun/api/nnfw_api_internal.h @@ -59,6 +59,8 @@ public: NNFW_STATUS input_size(uint32_t *number); NNFW_STATUS output_size(uint32_t *number); + NNFW_STATUS apply_tensorinfo(uint32_t index, nnfw_tensorinfo ti); + NNFW_STATUS input_tensorinfo(uint32_t index, nnfw_tensorinfo *ti); NNFW_STATUS output_tensorinfo(uint32_t index, nnfw_tensorinfo *ti); -- 2.7.4