Skip to content

Commit

Permalink
[onert] Update deprecated API implementation (Samsung#13173)
Browse files Browse the repository at this point in the history
This commit updates deprecated API implementation to use common function.
It includes unittest for deprecated API.

ONE-DCO-1.0-Signed-off-by: Hyeongseok Oh <[email protected]>
Co-authored-by: Jang Jiseob <[email protected]>
  • Loading branch information
hseok-oh and ragmani authored Jun 13, 2024
1 parent 313fb05 commit ead5705
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 35 deletions.
11 changes: 9 additions & 2 deletions runtime/onert/api/nnfw/include/nnfw_experimental.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,13 @@ NNFW_STATUS nnfw_output_tensorindex(nnfw_session *session, const char *tensornam
*/
NNFW_STATUS nnfw_set_backends_per_operation(nnfw_session *session, const char *backend_settings);

/*
* Prepare session to be ready for inference
/**
* @brief Prepare session to be ready for inference
*
* This phase may finalize model compilation, scheduling, and additional settings.
*
* @deprecated Deprecated since 1.22.1
*
* @param session the session to be prepared
* @return NNFW_STATUS_NO_ERROR if successful
*/
Expand All @@ -132,6 +135,8 @@ NNFW_STATUS nnfw_prepare_pipeline(nnfw_session *session, const char *map_file_pa
* function can be reused for many inferences. \p lengths must be greater or equal than the operand
* requires. if you give empty \p inputs to this function, then this function will join all threads.
*
* @deprecated Deprecated since 1.22.1
*
* @param[in] session Session to the input is to be set
* @param[in] inputs Raw buffers for input, it must be \p std::vector<void *> type pointer for
* multiple input model
Expand All @@ -148,6 +153,8 @@ NNFW_STATUS nnfw_push_pipeline_input(nnfw_session *session, void *inputs, void *
* This function must be called after {@link nnfw_prepare_pipeline}, \p outputs given to this
* function must be cleared for memory management.
*
* @deprecated Deprecated since 1.22.1
*
* @param[in] session Session from last outputs is to be extracted
* @param[out] outputs Raw buffer for outputs, it must be \p std::vector<void *> type pointer for
* multiple output model
Expand Down
18 changes: 7 additions & 11 deletions runtime/onert/api/nnfw/src/nnfw_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ NNFW_STATUS nnfw_register_custom_op_info(nnfw_session *session, const char *id,

NNFW_STATUS nnfw_apply_tensorinfo(nnfw_session *, uint32_t, nnfw_tensorinfo)
{
return NNFW_STATUS_DEPRECATED_API;
return nnfw_session::deprecated("nnfw_apply_tensorinfo: Deprecated");
}

NNFW_STATUS nnfw_set_input_tensorinfo(nnfw_session *session, uint32_t index,
Expand Down Expand Up @@ -365,23 +365,19 @@ NNFW_STATUS nnfw_set_backends_per_operation(nnfw_session *session, const char *b
return session->set_backends_per_operation(backend_settings);
}

NNFW_STATUS nnfw_prepare_pipeline(nnfw_session *session, const char *map_file_path)
NNFW_STATUS nnfw_prepare_pipeline(nnfw_session *, const char *)
{
NNFW_RETURN_ERROR_IF_NULL(session);
return session->prepare_pipeline(map_file_path);
return nnfw_session::deprecated("nnfw_prepare_pipeline: Deprecated");
}

NNFW_STATUS nnfw_push_pipeline_input(nnfw_session *session, void *inputs, void *lengths)
NNFW_STATUS nnfw_push_pipeline_input(nnfw_session *, void *, void *)
{
NNFW_RETURN_ERROR_IF_NULL(session);
return session->push_pipeline_input((std::vector<void *> *)inputs,
(std::vector<uint32_t> *)lengths);
return nnfw_session::deprecated("nnfw_push_pipeline_input: Deprecated");
}

NNFW_STATUS nnfw_pop_pipeline_output(nnfw_session *session, void *outputs)
NNFW_STATUS nnfw_pop_pipeline_output(nnfw_session *, void *)
{
NNFW_RETURN_ERROR_IF_NULL(session);
return session->pop_pipeline_output((std::vector<void *> *)outputs);
return nnfw_session::deprecated("nnfw_pop_pipeline_output: Deprecated");
}

NNFW_STATUS nnfw_set_workspace(nnfw_session *session, const char *dir)
Expand Down
24 changes: 6 additions & 18 deletions runtime/onert/api/nnfw/src/nnfw_api_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -507,12 +507,6 @@ NNFW_STATUS nnfw_session::prepare()
return NNFW_STATUS_NO_ERROR;
}

NNFW_STATUS nnfw_session::prepare_pipeline(const char *)
{
std::cerr << "Pipeline prepare_pipeline: deprecated feature " << std::endl;
return NNFW_STATUS_ERROR;
}

NNFW_STATUS nnfw_session::run()
{
if (!isStatePreparedOrFinishedRun())
Expand Down Expand Up @@ -866,18 +860,6 @@ NNFW_STATUS nnfw_session::output_tensorinfo(uint32_t index, nnfw_tensorinfo *ti)
return NNFW_STATUS_NO_ERROR;
}

NNFW_STATUS nnfw_session::push_pipeline_input(std::vector<void *> *, std::vector<uint32_t> *)
{
std::cerr << "Pipeline push_pipeline_input: deprecated feature " << std::endl;
return NNFW_STATUS_ERROR;
}

NNFW_STATUS nnfw_session::pop_pipeline_output(std::vector<void *> *)
{
std::cerr << "Pipeline pop_pipeline_output: deprecated feature " << std::endl;
return NNFW_STATUS_ERROR;
}

NNFW_STATUS nnfw_session::register_custom_operation(const std::string &id,
nnfw_custom_eval eval_func)
{
Expand Down Expand Up @@ -981,6 +963,12 @@ NNFW_STATUS nnfw_session::set_workspace(const char *dir)
return NNFW_STATUS_NO_ERROR;
}

NNFW_STATUS nnfw_session::deprecated(const char *msg)
{
std::cerr << msg << std::endl;
return NNFW_STATUS_DEPRECATED_API;
}

NNFW_STATUS nnfw_session::set_config(const char *key, const char *value)
{
if (!isStateModelLoaded())
Expand Down
6 changes: 2 additions & 4 deletions runtime/onert/api/nnfw/src/nnfw_api_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ struct nnfw_session
~nnfw_session();
NNFW_STATUS load_model_from_nnpackage(const char *package_file_path);
NNFW_STATUS prepare();
NNFW_STATUS prepare_pipeline(const char *map_file_path);
NNFW_STATUS run();

NNFW_STATUS run_async();
Expand All @@ -148,6 +147,8 @@ struct nnfw_session

NNFW_STATUS set_workspace(const char *dir);

static NNFW_STATUS deprecated(const char *msg);

//
// Internal-only API
//
Expand All @@ -160,9 +161,6 @@ struct nnfw_session
//
// Experimental API
//
NNFW_STATUS push_pipeline_input(std::vector<void *> *inputs, std::vector<uint32_t> *lengths);
NNFW_STATUS pop_pipeline_output(std::vector<void *> *outputs);

NNFW_STATUS register_custom_operation(const std::string &id, nnfw_custom_eval eval_func);
NNFW_STATUS input_tensorindex(const char *tensorname, uint32_t *index);
NNFW_STATUS output_tensorindex(const char *tensorname, uint32_t *index);
Expand Down
8 changes: 8 additions & 0 deletions tests/nnfw_api/src/NNPackageTests/SingleSession.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,11 @@ TEST_F(ValidationTestSingleSession, neg_internal_set_config)
ASSERT_EQ(nnfw_set_config(nullptr, "TRACING_MODE", "0"), NNFW_STATUS_UNEXPECTED_NULL);
ASSERT_EQ(nnfw_set_config(nullptr, "GRAPH_DOT_DUMP", "0"), NNFW_STATUS_UNEXPECTED_NULL);
}

TEST_F(ValidationTestSessionCreated, neg_deprecated_api)
{
EXPECT_EQ(nnfw_apply_tensorinfo(nullptr, 0, nnfw_tensorinfo{}), NNFW_STATUS_DEPRECATED_API);
EXPECT_EQ(nnfw_prepare_pipeline(nullptr, nullptr), NNFW_STATUS_DEPRECATED_API);
EXPECT_EQ(nnfw_push_pipeline_input(nullptr, nullptr, nullptr), NNFW_STATUS_DEPRECATED_API);
EXPECT_EQ(nnfw_pop_pipeline_output(nullptr, nullptr), NNFW_STATUS_DEPRECATED_API);
}

0 comments on commit ead5705

Please sign in to comment.