summaryrefslogtreecommitdiff
path: root/runtimes
diff options
context:
space:
mode:
author이한종/On-Device Lab(SR)/Engineer/삼성전자 <hanjoung.lee@samsung.com>2019-04-01 09:40:25 +0900
committer박세희/On-Device Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>2019-04-01 09:40:25 +0900
commit4822b1d45f8c93d93fcfdb5493131e947bdb1bd1 (patch)
tree8587adae0ea40b8c8fa3e451728e04a8e7bb9637 /runtimes
parentac0a83de9a75ca3e00a6ef704090b0151a94ee24 (diff)
downloadnnfw-4822b1d45f8c93d93fcfdb5493131e947bdb1bd1.tar.gz
nnfw-4822b1d45f8c93d93fcfdb5493131e947bdb1bd1.tar.bz2
nnfw-4822b1d45f8c93d93fcfdb5493131e947bdb1bd1.zip
[neurun] Simplify Backend C Interface (#4891)
C API was 3 functions that creates each components of a Backend. This commit revises it to have only one API function `neurun_backend_create` which packs all the components. Signed-off-by: Hanjoung Lee <hanjoung.lee@samsung.com>
Diffstat (limited to 'runtimes')
-rw-r--r--runtimes/neurun/backend/acl_cl/Backend.h50
-rw-r--r--runtimes/neurun/backend/acl_cl/PluginClassesAllocator.cc28
-rw-r--r--runtimes/neurun/backend/acl_neon/Backend.h50
-rw-r--r--runtimes/neurun/backend/acl_neon/PluginClassesAllocator.cc28
-rw-r--r--runtimes/neurun/backend/cpu/Backend.h50
-rw-r--r--runtimes/neurun/backend/cpu/PluginClassesAllocator.cc28
-rw-r--r--runtimes/neurun/core/src/backend/BackendManager.cc28
7 files changed, 182 insertions, 80 deletions
diff --git a/runtimes/neurun/backend/acl_cl/Backend.h b/runtimes/neurun/backend/acl_cl/Backend.h
new file mode 100644
index 000000000..d94d1eeff
--- /dev/null
+++ b/runtimes/neurun/backend/acl_cl/Backend.h
@@ -0,0 +1,50 @@
+/*
+ * 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 __NEURUN_BACKEND_ACL_CL_BACKEND_H__
+#define __NEURUN_BACKEND_ACL_CL_BACKEND_H__
+
+#include <memory>
+#include <backend/Backend.h>
+#include <model/operand/Set.h>
+
+#include "Config.h"
+#include "StageGenerator.h"
+
+namespace neurun
+{
+namespace backend
+{
+namespace acl_cl
+{
+
+class Backend : public ::neurun::backend::Backend
+{
+public:
+ Backend(const neurun::model::operand::Set &operand_ctx)
+ : ::neurun::backend::Backend{
+ std::make_shared<Config>(),
+ std::make_shared<StageGenerator>(operand_ctx, std::make_shared<TensorBuilder>())}
+ {
+ // DO NOTHING
+ }
+};
+
+} // namespace acl_cl
+} // namespace backend
+} // namespace neurun
+
+#endif // __NEURUN_BACKEND_ACL_CL_BACKEND_H__
diff --git a/runtimes/neurun/backend/acl_cl/PluginClassesAllocator.cc b/runtimes/neurun/backend/acl_cl/PluginClassesAllocator.cc
index f33e71d33..3a92bfa09 100644
--- a/runtimes/neurun/backend/acl_cl/PluginClassesAllocator.cc
+++ b/runtimes/neurun/backend/acl_cl/PluginClassesAllocator.cc
@@ -14,30 +14,14 @@
* limitations under the License.
*/
-#include <memory>
-#include "TensorBuilder.h"
-#include "StageGenerator.h"
-#include "Config.h"
-#include "util/logging.h"
+#include <util/logging.h>
-extern "C" {
-neurun::backend::acl_cl::TensorBuilder *allocate_TensorBuilder()
-{
- VERBOSE(allocate_TensorBuilder) << "loaded from acl_cl\n";
- return new neurun::backend::acl_cl::TensorBuilder;
-}
+#include "Backend.h"
-neurun::backend::acl_cl::StageGenerator *allocate_StageGenerator(
- const neurun::model::operand::Set &operand_ctx,
- const std::shared_ptr<neurun::backend::acl_cl::TensorBuilder> &tensor_builder)
-{
- VERBOSE(allocate_StageGenerator) << "loaded from acl_cl\n";
- return new neurun::backend::acl_cl::StageGenerator(operand_ctx, tensor_builder);
-}
-
-neurun::backend::acl_cl::Config *allocate_Config()
+extern "C" {
+neurun::backend::Backend neurun_backend_create(const neurun::model::operand::Set &operand_ctx)
{
- VERBOSE(allocate_Config) << "loaded from acl_cl\n";
- return new neurun::backend::acl_cl::Config;
+ VERBOSE(neurun_backend_create) << "loaded from acl_cl\n";
+ return neurun::backend::acl_cl::Backend{operand_ctx};
}
}
diff --git a/runtimes/neurun/backend/acl_neon/Backend.h b/runtimes/neurun/backend/acl_neon/Backend.h
new file mode 100644
index 000000000..e958d9564
--- /dev/null
+++ b/runtimes/neurun/backend/acl_neon/Backend.h
@@ -0,0 +1,50 @@
+/*
+ * 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 __NEURUN_BACKEND_ACL_NEON_BACKEND_H__
+#define __NEURUN_BACKEND_ACL_NEON_BACKEND_H__
+
+#include <memory>
+#include <backend/Backend.h>
+#include <model/operand/Set.h>
+
+#include "Config.h"
+#include "StageGenerator.h"
+
+namespace neurun
+{
+namespace backend
+{
+namespace acl_neon
+{
+
+class Backend : public ::neurun::backend::Backend
+{
+public:
+ Backend(const neurun::model::operand::Set &operand_ctx)
+ : ::neurun::backend::Backend{
+ std::make_shared<Config>(),
+ std::make_shared<StageGenerator>(operand_ctx, std::make_shared<TensorBuilder>())}
+ {
+ // DO NOTHING
+ }
+};
+
+} // namespace acl_neon
+} // namespace backend
+} // namespace neurun
+
+#endif // __NEURUN_BACKEND_ACL_NEON_BACKEND_H__
diff --git a/runtimes/neurun/backend/acl_neon/PluginClassesAllocator.cc b/runtimes/neurun/backend/acl_neon/PluginClassesAllocator.cc
index 2206fb33e..fdcdd94da 100644
--- a/runtimes/neurun/backend/acl_neon/PluginClassesAllocator.cc
+++ b/runtimes/neurun/backend/acl_neon/PluginClassesAllocator.cc
@@ -14,30 +14,14 @@
* limitations under the License.
*/
-#include <memory>
-#include "TensorBuilder.h"
-#include "StageGenerator.h"
-#include "Config.h"
-#include "util/logging.h"
+#include <util/logging.h>
-extern "C" {
-neurun::backend::acl_neon::TensorBuilder *allocate_TensorBuilder()
-{
- VERBOSE(allocate_TensorBuilder) << "loaded from acl_neon\n";
- return new neurun::backend::acl_neon::TensorBuilder;
-}
+#include "Backend.h"
-neurun::backend::acl_neon::StageGenerator *allocate_StageGenerator(
- const neurun::model::operand::Set &operand_ctx,
- const std::shared_ptr<neurun::backend::acl_neon::TensorBuilder> &tensor_builder)
-{
- VERBOSE(allocate_StageGenerator) << "loaded from acl_neon\n";
- return new neurun::backend::acl_neon::StageGenerator(operand_ctx, tensor_builder);
-}
-
-neurun::backend::acl_neon::Config *allocate_Config()
+extern "C" {
+neurun::backend::Backend neurun_backend_create(const neurun::model::operand::Set &operand_ctx)
{
- VERBOSE(allocate_Config) << "loaded from acl_neon\n";
- return new neurun::backend::acl_neon::Config;
+ VERBOSE(neurun_backend_create) << "loaded from acl_neon\n";
+ return neurun::backend::acl_neon::Backend{operand_ctx};
}
}
diff --git a/runtimes/neurun/backend/cpu/Backend.h b/runtimes/neurun/backend/cpu/Backend.h
new file mode 100644
index 000000000..e7878d292
--- /dev/null
+++ b/runtimes/neurun/backend/cpu/Backend.h
@@ -0,0 +1,50 @@
+/*
+ * 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 __NEURUN_BACKEND_CPU_BACKEND_H__
+#define __NEURUN_BACKEND_CPU_BACKEND_H__
+
+#include <memory>
+#include <backend/Backend.h>
+#include <model/operand/Set.h>
+
+#include "Config.h"
+#include "StageGenerator.h"
+
+namespace neurun
+{
+namespace backend
+{
+namespace cpu
+{
+
+class Backend : public ::neurun::backend::Backend
+{
+public:
+ Backend(const neurun::model::operand::Set &operand_ctx)
+ : ::neurun::backend::Backend{
+ std::make_shared<Config>(),
+ std::make_shared<StageGenerator>(operand_ctx, std::make_shared<TensorBuilder>())}
+ {
+ // DO NOTHING
+ }
+};
+
+} // namespace cpu
+} // namespace backend
+} // namespace neurun
+
+#endif // __NEURUN_BACKEND_CPU_BACKEND_H__
diff --git a/runtimes/neurun/backend/cpu/PluginClassesAllocator.cc b/runtimes/neurun/backend/cpu/PluginClassesAllocator.cc
index 26d4d8858..a29ad86aa 100644
--- a/runtimes/neurun/backend/cpu/PluginClassesAllocator.cc
+++ b/runtimes/neurun/backend/cpu/PluginClassesAllocator.cc
@@ -14,30 +14,14 @@
* limitations under the License.
*/
-#include <memory>
-#include "TensorBuilder.h"
-#include "StageGenerator.h"
-#include "Config.h"
-#include "util/logging.h"
+#include <util/logging.h>
-extern "C" {
-neurun::backend::cpu::TensorBuilder *allocate_TensorBuilder()
-{
- VERBOSE(allocate_TensorBuilder) << "loaded from CPU\n";
- return new neurun::backend::cpu::TensorBuilder;
-}
+#include "Backend.h"
-neurun::backend::cpu::StageGenerator *
-allocate_StageGenerator(const neurun::model::operand::Set &operand_ctx,
- const std::shared_ptr<neurun::backend::cpu::TensorBuilder> &tensor_builder)
-{
- VERBOSE(allocate_StageGenerator) << "loaded from CPU\n";
- return new neurun::backend::cpu::StageGenerator(operand_ctx, tensor_builder);
-}
-
-neurun::backend::cpu::Config *allocate_Config()
+extern "C" {
+neurun::backend::Backend neurun_backend_create(const neurun::model::operand::Set &operand_ctx)
{
- VERBOSE(allocate_Config) << "loaded from CPU\n";
- return new neurun::backend::cpu::Config;
+ VERBOSE(neurun_backend_create) << "loaded from CPU\n";
+ return neurun::backend::cpu::Backend{operand_ctx};
}
}
diff --git a/runtimes/neurun/core/src/backend/BackendManager.cc b/runtimes/neurun/core/src/backend/BackendManager.cc
index 4e0c90cbc..0e847d0fb 100644
--- a/runtimes/neurun/core/src/backend/BackendManager.cc
+++ b/runtimes/neurun/core/src/backend/BackendManager.cc
@@ -17,9 +17,8 @@
#include <dlfcn.h>
#include "BackendManager.h"
+#include "backend/Backend.h"
#include "backend/IConfig.h"
-#include "backend/ITensorBuilder.h"
-#include "backend/IStageGenerator.h"
#include "util/logging.h"
#include "util/config/ConfigManager.h"
@@ -60,19 +59,20 @@ void BackendManager::loadBackend(const std::string &backend,
VERBOSE(BackendManager::loadBackend) << "loaded " << backend_plugin << " as a plugin of "
<< backend << " backend\n";
- // load Config
- std::shared_ptr<neurun::backend::IConfig> config;
- loadObjectFromPlugin(config, std::string("allocate_Config"), handle);
-
- // load TensorBuilder
- std::shared_ptr<neurun::backend::ITensorBuilder> tensor_builder;
- loadObjectFromPlugin(tensor_builder, std::string("allocate_TensorBuilder"), handle);
+ {
+ using backend_create_t = neurun::backend::Backend (*)(const neurun::model::operand::Set &);
- // load StageGenerator
- std::shared_ptr<neurun::backend::IStageGenerator> stage_gen;
- loadObjectFromPlugin(stage_gen, std::string("allocate_StageGenerator"), handle, operands,
- tensor_builder);
- _gen_map[config->id()] = {config, stage_gen};
+ // load object creator function
+ backend_create_t backend_create = (backend_create_t)dlsym(handle, "neurun_backend_create");
+ if (backend_create == nullptr)
+ {
+ fprintf(stderr, "BackendManager: unable to open function neurun_backend_create : %s\n",
+ dlerror());
+ abort();
+ }
+ auto backend_object = backend_create(operands);
+ _gen_map[backend_object.config()->id()] = backend_object;
+ }
// Save backend handle (avoid warning by handle lost without dlclose())
_handle_map.insert({backend, handle});