--- /dev/null
+/*
+ * 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__
* 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};
}
}
--- /dev/null
+/*
+ * 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__
* 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};
}
}
--- /dev/null
+/*
+ * 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__
* 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};
}
}
#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"
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});