Skip to content

Commit

Permalink
[onert] Add compilation apis
Browse files Browse the repository at this point in the history
This commit adds compliation APIs to nnfw_experimental.h file.

ONE-DCO-1.0-Signed-off-by: Jiyoung Yun <jy910.yun@samsung.com>
  • Loading branch information
jyoungyun committed Jan 22, 2024
1 parent d0cff18 commit 46645df
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 0 deletions.
45 changes: 45 additions & 0 deletions runtime/onert/api/include/nnfw_experimental.h
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,51 @@ NNFW_STATUS nnfw_set_quantized_model_path(nnfw_session *session, const char *pat
*/
NNFW_STATUS nnfw_quantize(nnfw_session *session);

/**
* @brief Preference for compilation
*/
typedef enum
{
/** Use the default configuration */
NNFW_COMPILE_PREF_DEFAULT,
/** Do best efforts to compile model for performance */
NNFW_COMPILE_PREF_PERFORMANCE_FIRST,
/** Do best efforts to compile model for reducing host memory usage */
NNFW_COMPILE_PREF_MEMORY_FIRST,
/** Do best efforts to compile model for reducing compilation time */
NNFW_COMPILE_PREF_COMPILE_TIME_FIRST,
} NNFW_COMPILE_PREF;

/**
* @brief Set preference for backend compilation
*
* @param[in] session nnfw_session the session to set preference
* @param[in] pref @c NNFW_COMPILE_PREF
* @return @c NNFW_STATUS_NO_ERROR if successful, otherwise return @c NNFW_STATUS_ERROR
*/
NNFW_STATUS nnfw_set_compile_preference(nnfw_session *session, NNFW_COMPILE_PREF pref);

/**
* @brief Set exported compiled model path
*
* This function should be called before {@link nnfw_compile} is invoked.
*
* TODO: If this function is not called, compiled model will not be exported
*
* @param[in] session nnfw_session to set compiled model path
* @param[in] path Compiled model path
* @return @c NNFW_STATUS_NO_ERROR if successful, otherwise return @c NNFW_STATUS_ERROR
*/
NNFW_STATUS nnfw_set_compiled_model_path(nnfw_session *session, const char *path);

/**
* @brief Compile the model
*
* @param[in] session nnfw_session the session which contains information about compilation
* @return @c NNFW_STATUS_NO_ERROR if successful, otherwise return @c NNFW_STATUS_ERROR
*/
NNFW_STATUS nnfw_compile(nnfw_session *session);

#ifdef __cplusplus
}
#endif
Expand Down
18 changes: 18 additions & 0 deletions runtime/onert/api/src/nnfw_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -478,3 +478,21 @@ NNFW_STATUS nnfw_quantize(nnfw_session *session)
NNFW_RETURN_ERROR_IF_NULL(session);
return session->quantize();
}

NNFW_STATUS nnfw_set_compile_preference(nnfw_session *session, NNFW_COMPILE_PREF pref)
{
NNFW_RETURN_ERROR_IF_NULL(session);
return session->set_compile_preference(pref);
}

NNFW_STATUS nnfw_set_compiled_model_path(nnfw_session *session, const char *path)
{
NNFW_RETURN_ERROR_IF_NULL(session);
return session->set_compiled_model_path(path);
}

NNFW_STATUS nnfw_compile(nnfw_session *session)
{
NNFW_RETURN_ERROR_IF_NULL(session);
return session->compile();
}
65 changes: 65 additions & 0 deletions runtime/onert/api/src/nnfw_api_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1833,3 +1833,68 @@ NNFW_STATUS nnfw_session::quantize()

return NNFW_STATUS_NO_ERROR;
}

NNFW_STATUS nnfw_session::set_compile_preference(NNFW_COMPILE_PREF pref)
{
try
{
if (!isStateModelLoaded())
{
std::cerr << "invalid state" << std::endl;
return NNFW_STATUS_INVALID_STATE;
}

// TODO Set preference to compile manager
UNUSED_RELEASE(pref);
}
catch (const std::exception &e)
{
std::cerr << "Error during nnfw_session::set_compile_preference : " << e.what() << std::endl;
return NNFW_STATUS_ERROR;
}

return NNFW_STATUS_NO_ERROR;
}

NNFW_STATUS nnfw_session::set_compiled_model_path(const char *path)
{
try
{
if (!isStateModelLoaded())
{
std::cerr << "invalid state" << std::endl;
return NNFW_STATUS_INVALID_STATE;
}

// TODO Set model path for compiled file
UNUSED_RELEASE(path);
}
catch (const std::exception &e)
{
std::cerr << "Error during nnfw_session::set_compiled_model_path : " << e.what() << std::endl;
return NNFW_STATUS_ERROR;
}

return NNFW_STATUS_NO_ERROR;
}

NNFW_STATUS nnfw_session::compile()
{
try
{
if (!isStateModelLoaded())
{
std::cerr << "invalid state" << std::endl;
return NNFW_STATUS_INVALID_STATE;
}

// TODO Compile model
}
catch (const std::exception &e)
{
std::cerr << "Error during nnfw_session::compile : " << e.what() << std::endl;
return NNFW_STATUS_ERROR;
}

return NNFW_STATUS_NO_ERROR;
}
4 changes: 4 additions & 0 deletions runtime/onert/api/src/nnfw_api_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ struct nnfw_session
NNFW_STATUS set_quantized_model_path(const char *path);
NNFW_STATUS quantize();

NNFW_STATUS set_compile_preference(NNFW_COMPILE_PREF pref);
NNFW_STATUS set_compiled_model_path(const char *path);
NNFW_STATUS compile();

private:
const onert::ir::IGraph *primary_subgraph();
uint32_t getInputSize();
Expand Down

0 comments on commit 46645df

Please sign in to comment.