summaryrefslogtreecommitdiff
path: root/runtimes/neurun/core/src/compiler/Compiler.cc
diff options
context:
space:
mode:
Diffstat (limited to 'runtimes/neurun/core/src/compiler/Compiler.cc')
-rw-r--r--runtimes/neurun/core/src/compiler/Compiler.cc122
1 files changed, 122 insertions, 0 deletions
diff --git a/runtimes/neurun/core/src/compiler/Compiler.cc b/runtimes/neurun/core/src/compiler/Compiler.cc
new file mode 100644
index 000000000..6a378faa9
--- /dev/null
+++ b/runtimes/neurun/core/src/compiler/Compiler.cc
@@ -0,0 +1,122 @@
+/*
+ * 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 "compiler/Compiler.h"
+
+#include "BackendResolver.h"
+#include "ParamChecker.h"
+#include "ExecutorFactory.h"
+
+#include "compiler/IScheduler.h"
+#include "compiler/ManualScheduler.h"
+#include "compiler/HEScheduler.h"
+#include "backend/ExecTime.h"
+#include "graph/operation/LowerInfo.h"
+#include "dumper/dot/DotDumper.h"
+#include "compiler/Linear.h"
+#include "exec/interp/ExecManager.h"
+#include "backend/ExecTime.h"
+#include "util/ConfigSource.h"
+
+namespace neurun
+{
+
+namespace compiler
+{
+
+void Compiler::compile(void)
+{
+ _state = State::STARTED;
+
+ if (!checkCompilable())
+ {
+ _executor = std::make_shared<exec::interp::ExecManager>(_graph->shareModel());
+ return;
+ }
+
+ /***************************************************
+ * Backend independent analysis & optimization phase
+ ***************************************************/
+ // Schedule
+ std::unique_ptr<BackendResolver> br;
+ std::shared_ptr<model::OperationIndexMap<int64_t>> indexed_ranks;
+ if (util::getConfigBool(util::config::USE_SCHEDULER))
+ {
+ auto scheduler =
+ compiler::HEScheduler(_graph->operands(), backend::BackendManager::instance().getAll(),
+ _graph->getKernelRegistry());
+ br = scheduler.schedule(*_graph);
+ indexed_ranks = scheduler.getIndexedRanks();
+ }
+ else
+ {
+ auto scheduler = compiler::ManualScheduler();
+ br = scheduler.schedule(*_graph);
+ }
+ _graph->setBackendResolver(std::move(br));
+ /*************************************************************
+ * Backend independent analysis & optimization phase finished
+ *************************************************************/
+
+ // dump graph to .dot
+ auto dump_level =
+ static_cast<dumper::dot::DotDumper::Level>(util::getConfigInt(util::config::GRAPH_DOT_DUMP));
+ neurun::dumper::dot::DotDumper dot_dumper(*_graph, dump_level);
+ dot_dumper.dump("before_lower");
+
+ // Lower: decide backend
+ _graph->lower();
+ _state = State::LOWERED;
+
+ dot_dumper.dump("after_lower");
+
+ const std::string executor_str = util::getConfigString(util::config::EXECUTOR);
+
+ _executor =
+ std::shared_ptr<exec::IExecutor>{ExecutorFactory::instance().create(executor_str, *_graph)};
+ _executor->setIndexedRanks(indexed_ranks);
+ /********************************
+ * Code generation phase finished
+ ********************************/
+ _state = State::COMPILED;
+}
+
+bool Compiler::checkCompilable()
+{
+ // Disable compile phase
+ // When ready to use interpreter backend, remove this config and use backend setting
+ const auto env_disable_compile = util::getConfigBool(util::config::DISABLE_COMPILE);
+ if (env_disable_compile)
+ {
+ return false;
+ }
+
+ // TODO check unspecified operand shape
+
+ // Check compilable parameter
+ ParamChecker paramChecker{_graph};
+ paramChecker();
+ if (paramChecker.haveNoneConstParam())
+ {
+ return false;
+ }
+
+ return true;
+}
+
+} // namespace compiler
+
+} // namespace neurun