diff options
Diffstat (limited to 'runtimes/neurun/src/backend/BackendManager.cc')
-rw-r--r-- | runtimes/neurun/src/backend/BackendManager.cc | 118 |
1 files changed, 0 insertions, 118 deletions
diff --git a/runtimes/neurun/src/backend/BackendManager.cc b/runtimes/neurun/src/backend/BackendManager.cc deleted file mode 100644 index 5d19d4015..000000000 --- a/runtimes/neurun/src/backend/BackendManager.cc +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) 2018 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 <dlfcn.h> -#include "BackendManager.h" - -#include "backend/interface/IConfig.h" -#include "backend/interface/ITensorBuilder.h" -#include "backend/interface/IStageGenerator.h" -#include "util/logging.h" -#include "util/config/ConfigManager.h" - -namespace neurun -{ -namespace backend -{ - -Backend::Backend(const std::shared_ptr<neurun::backend::IConfig> &backend_config, - const std::shared_ptr<neurun::backend::IStageGenerator> &stage_gen) - : _config(backend_config), _stage_gen(stage_gen) -{ - backend_config->initialize(); -} - -const std::shared_ptr<neurun::backend::IConfig> Backend::config() const { return _config; } - -const std::shared_ptr<neurun::backend::IStageGenerator> Backend::stage_gen() const -{ - return _stage_gen; -} - -const std::shared_ptr<neurun::backend::ITensorBuilder> Backend::tensor_builder() const -{ - return _stage_gen->tensor_builder(); -} - -template <typename T, class... Types> -void BackendManager::loadObjectFromPlugin(std::shared_ptr<T> &object_of_plugin_class, - const std::string obj_creator_func_name, void *handle, - Types &&... args) -{ - T *(*allocate_obj)(Types && ... Args); - // load object creator function - allocate_obj = (T * (*)(Types && ... Args))dlsym(handle, obj_creator_func_name.c_str()); - if (allocate_obj == nullptr) - { - fprintf(stderr, "BackendManager: unable to open function %s: %s\n", - obj_creator_func_name.c_str(), dlerror()); - abort(); - } - - object_of_plugin_class.reset(allocate_obj(args...)); -} - -void BackendManager::loadBackend(const std::string &backend, - const neurun::model::operand::Set &operands) -{ - const std::string backend_plugin = "libbackend_" + backend + ".so"; - void *handle = dlopen(backend_plugin.c_str(), RTLD_LAZY | RTLD_LOCAL); - if (handle == nullptr) - { - fprintf(stderr, "BackendManager::loadBackend failed to load plugin of %s backend: %s\n", - backend.c_str(), dlerror()); - abort(); - } - 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); - - // 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}; -} - -BackendManager::BackendManager(const neurun::model::operand::Set &operands) -{ - const auto backends = config::ConfigManager::instance().get<std::string>("BACKENDS"); - size_t prev_pos = 0; - auto pos = backends.find(";"); - while (pos != std::string::npos) - { - loadBackend(backends.substr(prev_pos, pos - prev_pos), operands); - prev_pos = pos + 1; - pos = backends.find(";", prev_pos); - } - // if backends doesn't terminate with ";" - if (prev_pos < backends.size()) - { - loadBackend(backends.substr(prev_pos), operands); - } -} - -Backend *BackendManager::get(const std::string &key) { return &_gen_map.at(key); } - -} // namespace backend -} // namespace neurun |