--- /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_CORE_COMPILER_I_SCHEDULER_H__
+#define __NEURUN_CORE_COMPILER_I_SCHEDULER_H__
+
+#include "BackendResolver.h"
+#include "graph/Graph.h"
+
+namespace neurun
+{
+namespace compiler
+{
+
+struct IScheduler
+{
+ virtual ~IScheduler() = default;
+
+ virtual std::unique_ptr<BackendResolver> schedule(const graph::Graph &graph) = 0;
+};
+
+} // namespace compiler
+} // namespace neurun
+
+#endif // __NEURUN_CORE_COMPILER_I_SCHEDULER_H__
--- /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.
+ */
+
+#include "ManualScheduler.h"
+#include "backend/Backend.h"
+#include "backend/BackendManager.h"
+#include "backend/IConfig.h"
+#include "util/config/ConfigManager.h"
+
+namespace neurun
+{
+namespace compiler
+{
+
+std::unique_ptr<BackendResolver> ManualScheduler::schedule(const graph::Graph &graph)
+{
+ auto backend_manager = std::make_shared<backend::BackendManager>(graph.operands());
+ auto backend_resolver = nnfw::cpp14::make_unique<compiler::BackendResolver>(backend_manager);
+
+ // 1. Backend for All operations
+ const auto backend_all_str =
+ config::ConfigManager::instance().get<std::string>(config::OP_BACKEND_ALLOPS);
+ auto backend_all = backend_manager->get(backend_all_str);
+
+ VERBOSE(Lower) << "Use backend for all ops: " << backend_all_str << std::endl;
+
+ graph.operations().iterate([&](const model::OperationIndex &index, const model::Operation &) {
+ backend_resolver->setBackend(index, backend_all);
+ });
+
+ // 2. Backend per operation type
+ std::unordered_map<std::type_index, backend::Backend *> op_type_map;
+#define OP(InternalName, IsNnApi) \
+ if (IsNnApi) \
+ { \
+ const auto &backend_str = \
+ config::ConfigManager::instance().get<std::string>(config::OP_BACKEND_##InternalName); \
+ if (!backend_str.empty()) \
+ { \
+ auto backend = backend_manager->get(backend_str); \
+ VERBOSE(Lower) << "backend for " << #InternalName << ": " << backend_str << std::endl; \
+ op_type_map[typeid(model::operation::InternalName)] = backend; \
+ } \
+ }
+#include "model/Operations.lst"
+#undef OP
+ graph.operations().iterate([&](const model::OperationIndex &index, const model::Operation &) {
+ auto itr = op_type_map.find(typeid(index));
+ if (itr != op_type_map.end())
+ {
+ backend_resolver->setBackend(index, itr->second);
+ }
+ });
+
+ // 3. Backend per operation
+ // TODO TBD
+
+ // Dump final assignment
+ backend_resolver->iterate(
+ [&](const model::OperationIndex &index, const backend::Backend *backend) {
+ VERBOSE(Lower) << "backend for operation #" << index.value() << ": "
+ << backend->config()->id() << std::endl;
+ });
+
+ return backend_resolver;
+}
+
+} // namespace compiler
+} // namespace neurun
--- /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_CORE_COMPILER_MANUAL_SCHEDULER_H__
+#define __NEURUN_CORE_COMPILER_MANUAL_SCHEDULER_H__
+
+#include "IScheduler.h"
+
+namespace neurun
+{
+namespace compiler
+{
+
+class ManualScheduler : public IScheduler
+{
+public:
+ std::unique_ptr<BackendResolver> schedule(const graph::Graph &graph) override;
+};
+
+} // namespace compiler
+} // namespace neurun
+
+#endif // __NEURUN_CORE_COMPILER_MANUAL_SCHEDULER_H__
#include "graph/operand/LowerInfo.h"
#include "operand/Shape4DConvert.h"
#include "compiler/BackendResolver.h"
+#include "compiler/IScheduler.h"
+#include "compiler/ManualScheduler.h"
#include "backend/IConfig.h"
#include "pass/PermutationInsertionPass.h"
#include "pass/PermutationEliminationPass.h"
nnfw::cpp14::make_unique<operand::LowerInfo>(graph::operand::asShape4D(object.shape()));
});
- auto backend_manager = std::make_shared<backend::BackendManager>(_model->operands);
- _backend_resolver = nnfw::cpp14::make_unique<compiler::BackendResolver>(backend_manager);
-
- // BackendResolver building
- // TODO When IScheduler interface is introduced, this building should be done in a derivative of
- // IScheduler
+ // Schedule
{
- // 1. Backend for All operations
- const auto backend_all_str =
- config::ConfigManager::instance().get<std::string>(config::OP_BACKEND_ALLOPS);
- auto backend_all = backend_manager->get(backend_all_str);
-
- VERBOSE(Lower) << "Use backend for all ops: " << backend_all_str << std::endl;
-
- _model->operations.iterate([&](const model::OperationIndex &index, model::Operation &) {
- _backend_resolver->setBackend(index, backend_all);
- });
-
- // 2. Backend per operation type
- std::unordered_map<std::type_index, backend::Backend *> op_type_map;
-#define OP(InternalName, IsNnApi) \
- if (IsNnApi) \
- { \
- const auto &backend_str = \
- config::ConfigManager::instance().get<std::string>(config::OP_BACKEND_##InternalName); \
- if (!backend_str.empty()) \
- { \
- auto backend = backend_manager->get(backend_str); \
- VERBOSE(Lower) << "backend for " << #InternalName << ": " << backend_str << std::endl; \
- op_type_map[typeid(model::operation::InternalName)] = backend; \
- } \
- }
-#include "model/Operations.lst"
-#undef OP
- _model->operations.iterate([&](const model::OperationIndex &index, model::Operation &) {
- auto itr = op_type_map.find(typeid(index));
- if (itr != op_type_map.end())
- {
- _backend_resolver->setBackend(index, itr->second);
- }
- });
-
- // 3. Backend per operation
- // TODO TBD
-
- // Dump final assignment
- _backend_resolver->iterate(
- [&](const model::OperationIndex &index, const backend::Backend *backend) {
- VERBOSE(Lower) << "backend for operation #" << index.value() << ": "
- << backend->config()->id() << std::endl;
- });
+ std::unique_ptr<compiler::IScheduler> scheduler =
+ nnfw::cpp14::make_unique<compiler::ManualScheduler>();
+ _backend_resolver = scheduler->schedule(*this);
}
_lower_info_map = nnfw::cpp14::make_unique<LowerInfoMap>();