nnfw API implementation skeleton (#5527)
author이춘석/On-Device Lab(SR)/Staff Engineer/삼성전자 <chunseok.lee@samsung.com>
Tue, 2 Jul 2019 05:33:28 +0000 (14:33 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Tue, 2 Jul 2019 05:33:28 +0000 (14:33 +0900)
- c++ wrapper for nnfw.h in api/wrapper
- empty implementation

Signed-off-by: Chunseok Lee <chunseok.lee@samsung.com>
runtimes/neurun/frontend/api/CMakeLists.txt [new file with mode: 0644]
runtimes/neurun/frontend/api/nnfw_dev.cc [new file with mode: 0644]
runtimes/neurun/frontend/api/wrapper/nnfw_api.cc [new file with mode: 0644]
runtimes/neurun/frontend/api/wrapper/nnfw_api.hpp [new file with mode: 0644]

diff --git a/runtimes/neurun/frontend/api/CMakeLists.txt b/runtimes/neurun/frontend/api/CMakeLists.txt
new file mode 100644 (file)
index 0000000..6dc4738
--- /dev/null
@@ -0,0 +1,8 @@
+file(GLOB_RECURSE API_SRC "*.cc")
+
+set(NEURUN_DEV nnfw-dev)
+add_library(${NEURUN_DEV} SHARED ${API_SRC})
+
+target_link_libraries(${NEURUN_DEV} nnapi-header)
+target_link_libraries(${NEURUN_DEV} ${LIB_NEURUN})
+install(TARGETS ${NEURUN_DEV} DESTINATION lib)
diff --git a/runtimes/neurun/frontend/api/nnfw_dev.cc b/runtimes/neurun/frontend/api/nnfw_dev.cc
new file mode 100644 (file)
index 0000000..584a1e3
--- /dev/null
@@ -0,0 +1,119 @@
+/*
+ * 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.
+ */
+
+#include "wrapper/nnfw_api.hpp"
+
+/*
+ * Create a new session instance
+ *
+ * @param session the session to be created
+ * @return NNFW_STATUS_NO_ERROR if successful
+ */
+NNFW_STATUS nnfw_create_session(nnfw_session **session)
+{
+  *session = new nnfw_session();
+
+  return NNFW_STATUS_NO_ERROR;
+}
+
+/*
+ * Close a session instance
+ *
+ * @param session the session to be closed
+ * @return NNFW_STATUS_NO_ERROR if successful
+ */
+NNFW_STATUS nnfw_close_session(nnfw_session *session)
+{
+  delete session;
+  return NNFW_STATUS_NO_ERROR;
+}
+
+/*
+ * Load model from nnpackage file or directory
+ *
+ * @param session nnfw_session loading the given nnpackage file/dir
+ * @param 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 *pacakge_file_path)
+{
+  session->load_model_from_file(pacakge_file_path);
+  return NNFW_STATUS_NO_ERROR;
+}
+
+/*
+ * Prepare session to be ready for inference
+ * This phase may finalize model compilation, scheduling, and additional settings.
+ *
+ * @param session the session to be prepared
+ * @return NNFW_STATUS_NO_ERROR if successful
+ */
+NNFW_STATUS nnfw_prepare(nnfw_session *session)
+{
+  session->prepare();
+  return NNFW_STATUS_NO_ERROR;
+}
+
+/*
+ * Run inference
+ *
+ * @param session the session to run inference
+ * @return NNFW_STATUS_NO_ERROR if successful
+ */
+NNFW_STATUS nnfw_run(nnfw_session *session)
+{
+  session->run();
+  return NNFW_STATUS_NO_ERROR;
+}
+
+/*
+ * Set input
+ *
+ * @param session session to the input is to be set
+ * @param index index of input to be set (0-indexed)
+ * @param type type of the input
+ * @param buffer raw buffer for input
+ * @param length size of bytes of output
+ *
+ * @return NNFW_STATUS_NO_ERROR if successful
+ */
+
+NNFW_STATUS nnfw_set_input(nnfw_session *session, int index, NNFW_TYPE type, const void *buffer,
+                           size_t length)
+{
+  session->set_input(index, type, buffer, length);
+  return NNFW_STATUS_NO_ERROR;
+}
+
+/*
+ * Set output
+ *
+ * @param session session from inference output is to be extracted
+ * @param index index of output to be set (0-indexed)
+ * @param type type of the output
+ * @param buffer raw buffer for output
+ * @param length size of bytes of output
+ *
+ * @return NNFW_STATUS_NO_ERROR if successful
+ */
+
+NNFW_STATUS nnfw_set_output(nnfw_session *session, int index, NNFW_TYPE type, void *buffer,
+                            size_t length)
+{
+  session->set_output(index, type, buffer, length);
+  return NNFW_STATUS_NO_ERROR;
+}
diff --git a/runtimes/neurun/frontend/api/wrapper/nnfw_api.cc b/runtimes/neurun/frontend/api/wrapper/nnfw_api.cc
new file mode 100644 (file)
index 0000000..eab135b
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * 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.
+ */
+
+#include "nnfw_api.hpp"
+
+nnfw_session::nnfw_session() : _graph{nullptr}, _executor{nullptr}
+{
+  // DO NOTHING
+}
+
+NNFW_STATUS nnfw_session::load_model_from_file(const char *package_file_path)
+{
+  // TODO : construct _graph
+  return NNFW_STATUS_NO_ERROR;
+}
+
+NNFW_STATUS nnfw_session::prepare()
+{
+  // TODO : construct _executor
+  return NNFW_STATUS_NO_ERROR;
+}
+
+NNFW_STATUS nnfw_session::run()
+{
+  // TODO : add run routine
+  return NNFW_STATUS_NO_ERROR;
+}
+
+NNFW_STATUS nnfw_session::set_input(int index, NNFW_TYPE type, const void *buffer, size_t length)
+{
+  // TODO : add set input routine
+  return NNFW_STATUS_NO_ERROR;
+}
+
+NNFW_STATUS nnfw_session::set_output(int index, NNFW_TYPE type, void *buffer, size_t length)
+{
+  // TODO : add set output routine
+  return NNFW_STATUS_NO_ERROR;
+}
diff --git a/runtimes/neurun/frontend/api/wrapper/nnfw_api.hpp b/runtimes/neurun/frontend/api/wrapper/nnfw_api.hpp
new file mode 100644 (file)
index 0000000..bcc8a59
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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 __API_NNFW_INTERNAL_HPP__
+#define __API_NNFW_INTERNAL_HPP__
+
+#include "nnfw.h"
+#include "compiler/Compiler.h"
+#include "exec/IExecutor.h"
+#include "graph/Graph.h"
+
+
+struct nnfw_session {
+public:
+  nnfw_session();
+
+  NNFW_STATUS load_model_from_file(const char* package_file_path);
+  NNFW_STATUS prepare();
+  NNFW_STATUS run();
+
+  NNFW_STATUS set_input(int index,NNFW_TYPE type, const void *buffer,
+                        size_t length);
+  NNFW_STATUS set_output(int index,NNFW_TYPE type, void *buffer,
+                         size_t length);
+
+private:
+  std::shared_ptr<neurun::graph::Graph> _graph;
+  std::shared_ptr<neurun::exec::IExecutor> _executor;
+};
+
+
+#endif //__API_NNFW_INTERNAL_HPP__