Move LoweredGraph to compiler as it contains backend dependent parts.
ONE-DCO-1.0-Signed-off-by: Hanjoung Lee <hanjoung.lee@samsung.com>
#include "ParentInfo.h"
#include <cassert>
-#include <ir/LoweredGraph.h>
+#include <compiler/LoweredGraph.h>
#include <util/logging.h>
#include "AclSubTensorAnalyzer.h"
#include "ParentInfo.h"
#include <cassert>
-#include <ir/LoweredGraph.h>
+#include <compiler/LoweredGraph.h>
#include <util/logging.h>
#include "AclSubTensorAnalyzer.h"
--- /dev/null
+/*
+ * Copyright (c) 2020 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 __ONERT_IR_LOWERED_GRAPH_H__
+#define __ONERT_IR_LOWERED_GRAPH_H__
+
+#include "ir/Graph.h"
+#include "ir/LowerInfoMap.h"
+#include "ir/OpSequences.h"
+#include "compiler/BackendResolver.h"
+#include "compiler/Compiler.h"
+
+namespace onert
+{
+namespace compiler
+{
+
+/**
+ * @brief Class that contains lowering information on graph.
+ * In addition, after lowering, operands in graph will be set to "dynamic"
+ * if the shape of output of an operation cannot be decided at compilation time.
+ */
+class LoweredGraph
+{
+public:
+ LoweredGraph(const ir::Graph &graph, const compiler::CompilerOptions &options);
+
+ ir::Graph &graph() { return _graph; }
+ const ir::Graph &graph() const { return _graph; }
+ const ir::LowerInfoMap *getLowerInfo() const { return &_lower_info_map; }
+ const ir::operation::LowerInfo *getLowerInfo(const ir::OpSequenceIndex &op_seq_index) const;
+ void setLowerInfo(const ir::OpSequenceIndex &op_seq_index,
+ std::unique_ptr<ir::operation::LowerInfo> &&lower_info);
+ void removeLowerInfo(const ir::OpSequenceIndex &op_seq_index);
+ const ir::operand::LowerInfo *getLowerInfo(const ir::OperandIndex &index) const;
+ ir::operand::LowerInfo *getLowerInfo(const ir::OperandIndex &index);
+ void setLowerInfo(const ir::OperandIndex &index,
+ std::unique_ptr<ir::operand::LowerInfo> &&lower_info);
+ void removeLowerInfo(const ir::OperandIndex &index);
+ ir::OpSequences &op_seqs() { return _op_seqs; }
+ const ir::OpSequences &op_seqs() const { return _op_seqs; }
+ void iterateTopolOpSeqs(
+ const std::function<void(const ir::OpSequenceIndex &, const ir::OpSequence &)> &fn) const;
+ void
+ iterateTopolOpSeqs(const std::function<void(const ir::OpSequenceIndex &, ir::OpSequence &)> &fn);
+ const backend::BackendContexts &backend_contexts() { return _backend_contexts; }
+ const backend::BackendContexts &backend_contexts() const { return _backend_contexts; }
+ std::shared_ptr<ir::OperationIndexMap<int64_t>> indexed_ranks() { return _indexed_ranks; }
+
+private:
+ void
+ makeOpSequences(ir::OperandIndexMap<std::unique_ptr<ir::operand::LowerInfo>> &operands_lower_info,
+ const compiler::CompilerOptions &options,
+ const compiler::BackendResolver &backend_resolver);
+
+ void manipulateLowerInfo(
+ ir::OperandIndexMap<std::unique_ptr<ir::operand::LowerInfo>> &operands_lower_info,
+ bool is_primary);
+ void dumpLowerInfo();
+ bool mergeable(const ir::OpSequenceIndex &op_seq_index, const ir::OperationIndex &node_index,
+ ir::Layout layout, const compiler::BackendResolver &backend_resolver);
+ ir::OpSequenceIndex appendFreshSingleOpSequence(const ir::OperationIndex &node_index,
+ const ir::Operation &node);
+
+private:
+ ir::Graph _graph;
+ backend::BackendContexts _backend_contexts;
+ std::shared_ptr<ir::OperationIndexMap<int64_t>> _indexed_ranks;
+ ir::LowerInfoMap _lower_info_map;
+ // Pass(for Perm) can accept only graph so that Graph has OpSequences as a member
+ ir::OpSequences _op_seqs;
+};
+
+} // namespace compiler
+} // namespace onert
+
+#endif // __ONERT_IR_LOWERED_GRAPH_H__
#include "ir/OperationVisitor.h"
#include "ir/OpSequence.h"
-#include "ir/LoweredGraph.h"
+#include "compiler/LoweredGraph.h"
#include "ir/Index.h"
#include <memory>
public:
StaticShapeInferer(
const ir::SubgraphIndex &subg_idx,
- const std::unordered_map<ir::SubgraphIndex, std::unique_ptr<ir::LoweredGraph>> &lowered_subgs)
+ const std::unordered_map<ir::SubgraphIndex, std::unique_ptr<compiler::LoweredGraph>>
+ &lowered_subgs)
: _lowered_subgs(lowered_subgs), _operands(lowered_subgs.at(subg_idx)->graph().operands()),
_operations(lowered_subgs.at(subg_idx)->graph().operations()),
_return_has_dynamic_tensor(false)
void handleSimpleUnaryOp(const ir::Operation &op, const ir::OperandIndex input_idx);
private:
- const std::unordered_map<ir::SubgraphIndex, std::unique_ptr<ir::LoweredGraph>> &_lowered_subgs;
+ const std::unordered_map<ir::SubgraphIndex, std::unique_ptr<compiler::LoweredGraph>>
+ &_lowered_subgs;
// _operands and _operations can be changed by controlflow operation
ir::Operands &_operands; // operands of current subgraph
ir::Operations &_operations; // operations of current subgraph
+++ /dev/null
-/*
- * Copyright (c) 2020 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 __ONERT_IR_LOWERED_GRAPH_H__
-#define __ONERT_IR_LOWERED_GRAPH_H__
-
-#include "ir/Graph.h"
-#include "ir/LowerInfoMap.h"
-#include "ir/OpSequences.h"
-#include "compiler/BackendResolver.h"
-#include "compiler/Compiler.h"
-
-namespace onert
-{
-namespace ir
-{
-
-/**
- * @brief Class that contains lowering information on graph.
- * In addition, after lowering, operands in graph will be set to "dynamic"
- * if the shape of output of an operation cannot be decided at compilation time.
- */
-class LoweredGraph
-{
-public:
- LoweredGraph(const Graph &graph, const compiler::CompilerOptions &options);
-
- Graph &graph() { return _graph; }
- const Graph &graph() const { return _graph; }
- const LowerInfoMap *getLowerInfo() const { return &_lower_info_map; }
- const operation::LowerInfo *getLowerInfo(const OpSequenceIndex &op_seq_index) const;
- void setLowerInfo(const OpSequenceIndex &op_seq_index,
- std::unique_ptr<operation::LowerInfo> &&lower_info);
- void removeLowerInfo(const OpSequenceIndex &op_seq_index);
- const operand::LowerInfo *getLowerInfo(const OperandIndex &index) const;
- operand::LowerInfo *getLowerInfo(const OperandIndex &index);
- void setLowerInfo(const OperandIndex &index, std::unique_ptr<operand::LowerInfo> &&lower_info);
- void removeLowerInfo(const OperandIndex &index);
- OpSequences &op_seqs() { return _op_seqs; }
- const OpSequences &op_seqs() const { return _op_seqs; }
- void iterateTopolOpSeqs(
- const std::function<void(const OpSequenceIndex &, const OpSequence &)> &fn) const;
- void iterateTopolOpSeqs(const std::function<void(const OpSequenceIndex &, OpSequence &)> &fn);
- const backend::BackendContexts &backend_contexts() { return _backend_contexts; }
- const backend::BackendContexts &backend_contexts() const { return _backend_contexts; }
- std::shared_ptr<ir::OperationIndexMap<int64_t>> indexed_ranks() { return _indexed_ranks; }
-
-private:
- void makeOpSequences(OperandIndexMap<std::unique_ptr<operand::LowerInfo>> &operands_lower_info,
- const compiler::CompilerOptions &options,
- const compiler::BackendResolver &backend_resolver);
-
- void
- manipulateLowerInfo(OperandIndexMap<std::unique_ptr<operand::LowerInfo>> &operands_lower_info,
- bool is_primary);
- void dumpLowerInfo();
- bool mergeable(const OpSequenceIndex &op_seq_index, const OperationIndex &node_index,
- Layout layout, const compiler::BackendResolver &backend_resolver);
- OpSequenceIndex appendFreshSingleOpSequence(const OperationIndex &node_index,
- const Operation &node);
-
-private:
- Graph _graph;
- backend::BackendContexts _backend_contexts;
- std::shared_ptr<ir::OperationIndexMap<int64_t>> _indexed_ranks;
- LowerInfoMap _lower_info_map;
- // Pass(for Perm) can accept only graph so that Graph has OpSequences as a member
- OpSequences _op_seqs;
-};
-
-} // namespace ir
-} // namespace onert
-
-#endif // __ONERT_IR_LOWERED_GRAPH_H__
#include "ir/operation/Pool2D.h"
#include "ir/operation/Reshape.h"
#include "ir/operation/StridedSlice.h"
-#include "ir/LoweredGraph.h"
+#include "compiler/LoweredGraph.h"
#include "ir/Index.h"
#include "ir/Layout.h"
#include "ir/OperationVisitor.h"
auto dump_level = static_cast<dumper::dot::DotDumper::Level>(_options.graph_dump_level);
// Lower: Assign backend
- std::unordered_map<ir::SubgraphIndex, std::unique_ptr<ir::LoweredGraph>> lowered_subgs;
+ std::unordered_map<ir::SubgraphIndex, std::unique_ptr<compiler::LoweredGraph>> lowered_subgs;
_subgraphs->iterate([&](const ir::SubgraphIndex &index, ir::Graph &subg) {
_options.is_primary_subgraph = (index == ir::SubgraphIndex{0});
onert::dumper::dot::DotDumper dot_dumper(subg, dump_level);
dot_dumper.dump(nnfw::misc::str("before_lower_subg-", index.value()));
// Lower: Assign backend
- lowered_subgs[index] = std::make_unique<ir::LoweredGraph>(subg, _options);
+ lowered_subgs[index] = std::make_unique<compiler::LoweredGraph>(subg, _options);
// Check backend(s) for subgraph support FP16
bool backends_support_fp16 = true;
std::placeholders::_3, true);
}
-exec::IExecutor *ExecutorFactory::create(std::unique_ptr<ir::LoweredGraph> lowered_graph,
+exec::IExecutor *ExecutorFactory::create(std::unique_ptr<compiler::LoweredGraph> lowered_graph,
const compiler::CompilerOptions &options,
const std::shared_ptr<exec::ExecutorMap> &executor_map)
{
return _map.at(options.executor)(std::move(lowered_graph), options, executor_map);
}
-void ExecutorFactory::initializeBackendContext(ir::LoweredGraph *lowered_graph)
+void ExecutorFactory::initializeBackendContext(compiler::LoweredGraph *lowered_graph)
{
struct Entry
{
}
}
-void ExecutorFactory::runTensorRegistration(ir::LoweredGraph *lowered_graph,
+void ExecutorFactory::runTensorRegistration(compiler::LoweredGraph *lowered_graph,
const std::vector<ir::OpSequenceIndex> &order)
{
for (const auto index : order)
}
std::vector<std::shared_ptr<backend::ITensor>>
-ExecutorFactory::initializeModelIOTensors(ir::LoweredGraph &lowered_graph,
+ExecutorFactory::initializeModelIOTensors(compiler::LoweredGraph &lowered_graph,
const ir::OperandIndexSequence &indices)
{
std::vector<std::shared_ptr<backend::ITensor>> ret;
return ret;
}
-void ExecutorFactory::prepareExternalTensors(ir::LoweredGraph &lowered_graph,
+void ExecutorFactory::prepareExternalTensors(compiler::LoweredGraph &lowered_graph,
TensorBuilders &tensor_builders)
{
lowered_graph.op_seqs().iterate(
}
exec::IExecutor *
-ExecutorFactory::createLinearExecutor(std::unique_ptr<ir::LoweredGraph> lowered_graph,
+ExecutorFactory::createLinearExecutor(std::unique_ptr<compiler::LoweredGraph> lowered_graph,
const compiler::CompilerOptions &options,
const std::shared_ptr<exec::ExecutorMap> &executor_map)
{
}
exec::IExecutor *ExecutorFactory::createDataflowExecutor(
- std::unique_ptr<ir::LoweredGraph> lowered_graph, const compiler::CompilerOptions &options,
+ std::unique_ptr<compiler::LoweredGraph> lowered_graph, const compiler::CompilerOptions &options,
const std::shared_ptr<exec::ExecutorMap> &executor_map, bool parallel)
{
const auto &backend_contexts = lowered_graph->backend_contexts();
#include "backend/ITensor.h"
#include "exec/IExecutor.h"
-#include "ir/LoweredGraph.h"
+#include "compiler/LoweredGraph.h"
#include "TensorBuilders.h"
namespace onert
static ExecutorFactory &get();
public:
- exec::IExecutor *create(std::unique_ptr<ir::LoweredGraph> lowered_graph,
+ exec::IExecutor *create(std::unique_ptr<compiler::LoweredGraph> lowered_graph,
const compiler::CompilerOptions &options,
const std::shared_ptr<exec::ExecutorMap> &executor_map);
ExecutorFactory();
private:
- static void initializeBackendContext(ir::LoweredGraph *lowered_graph);
- static void runTensorRegistration(ir::LoweredGraph *lowered_graph,
+ static void initializeBackendContext(compiler::LoweredGraph *lowered_graph);
+ static void runTensorRegistration(compiler::LoweredGraph *lowered_graph,
const std::vector<ir::OpSequenceIndex> &order);
static std::vector<std::shared_ptr<backend::ITensor>>
- initializeModelIOTensors(ir::LoweredGraph &lowered_graph,
+ initializeModelIOTensors(compiler::LoweredGraph &lowered_graph,
const ir::OperandIndexSequence &indices);
- static void prepareExternalTensors(ir::LoweredGraph &lowered_graph,
+ static void prepareExternalTensors(compiler::LoweredGraph &lowered_graph,
TensorBuilders &tensor_builders);
static exec::IExecutor *
- createLinearExecutor(std::unique_ptr<ir::LoweredGraph> lowered_graph,
+ createLinearExecutor(std::unique_ptr<compiler::LoweredGraph> lowered_graph,
const compiler::CompilerOptions &options,
const std::shared_ptr<exec::ExecutorMap> &executor_map);
static exec::IExecutor *
- createDataflowExecutor(std::unique_ptr<ir::LoweredGraph> lowered_graph,
+ createDataflowExecutor(std::unique_ptr<compiler::LoweredGraph> lowered_graph,
const compiler::CompilerOptions &options,
const std::shared_ptr<exec::ExecutorMap> &executor_map, bool parallel);
private:
- std::unordered_map<
- std::string, std::function<exec::IExecutor *(
- std::unique_ptr<ir::LoweredGraph>, const compiler::CompilerOptions &options,
- const std::shared_ptr<exec::ExecutorMap> &executor_map)>>
+ std::unordered_map<std::string, std::function<exec::IExecutor *(
+ std::unique_ptr<compiler::LoweredGraph>,
+ const compiler::CompilerOptions &options,
+ const std::shared_ptr<exec::ExecutorMap> &executor_map)>>
_map;
};
namespace compiler
{
-Fp32ToFp16Converter::Fp32ToFp16Converter(ir::LoweredGraph &lowered_graph)
+Fp32ToFp16Converter::Fp32ToFp16Converter(compiler::LoweredGraph &lowered_graph)
: _lowered_graph{lowered_graph}
{
VERBOSE(Fp32ToFp16Converter) << "Fp16 Enable on" << std::endl;
#ifndef __ONERT_COMPILER_FP32_TO_FP16_CONVERTER_H__
#define __ONERT_COMPILER_FP32_TO_FP16_CONVERTER_H__
-#include "ir/LoweredGraph.h"
+#include "compiler/LoweredGraph.h"
namespace onert
{
class Fp32ToFp16Converter
{
public:
- Fp32ToFp16Converter(ir::LoweredGraph &lowered_graph);
+ Fp32ToFp16Converter(compiler::LoweredGraph &lowered_graph);
public:
void run();
void convertOperandsOfOpSequence(ir::OpSequence &op_seq);
private:
- ir::LoweredGraph &_lowered_graph;
+ compiler::LoweredGraph &_lowered_graph;
OpSeqIndexList _list_fp32_to_fp16;
OpSeqIndexList _list_fp16_to_fp32;
};
namespace compiler
{
-std::vector<ir::OpSequenceIndex> Linear::linearize(const ir::LoweredGraph &lowered_graph)
+std::vector<ir::OpSequenceIndex> Linear::linearize(const compiler::LoweredGraph &lowered_graph)
{
std::vector<ir::OpSequenceIndex> order;
lowered_graph.iterateTopolOpSeqs(
return order;
}
-void Linear::dump(const ir::LoweredGraph &lowered_graph,
+void Linear::dump(const compiler::LoweredGraph &lowered_graph,
const std::vector<ir::OpSequenceIndex> &order)
{
{
}
}
-void Linear::planTensors(const ir::LoweredGraph &lowered_graph,
+void Linear::planTensors(const compiler::LoweredGraph &lowered_graph,
const std::vector<ir::OpSequenceIndex> &order)
{
const auto &graph = lowered_graph.graph();
#include "ir/OpSequences.h"
#include "ir/Index.h"
#include "backend/ITensorBuilder.h"
-#include "ir/LoweredGraph.h"
+#include "compiler/LoweredGraph.h"
namespace onert
{
class Linear
{
public:
- static std::vector<ir::OpSequenceIndex> linearize(const ir::LoweredGraph &lowered_graph);
- static void dump(const ir::LoweredGraph &lowered_graph,
+ static std::vector<ir::OpSequenceIndex> linearize(const compiler::LoweredGraph &lowered_graph);
+ static void dump(const compiler::LoweredGraph &lowered_graph,
const std::vector<ir::OpSequenceIndex> &order);
- static void planTensors(const ir::LoweredGraph &lowered_graph,
+ static void planTensors(const compiler::LoweredGraph &lowered_graph,
const std::vector<ir::OpSequenceIndex> &order);
};
* limitations under the License.
*/
-#include "ir/LoweredGraph.h"
+#include "compiler/LoweredGraph.h"
#include <assert.h>
#include <sstream>
#include "compiler/pass/PermutationInsertionPass.h"
#include "compiler/pass/PermutationEliminationPass.h"
#include "ir/GraphIterator.h"
-#include "verifier/Verifier.h"
+#include "ir/verifier/Verifier.h"
#include "backend/Backend.h"
#include "backend/IConfig.h"
#include "compiler/BackendResolver.h"
namespace onert
{
-namespace ir
+namespace compiler
{
-LoweredGraph::LoweredGraph(const Graph &graph, const compiler::CompilerOptions &options)
- : _graph{graph}
+LoweredGraph::LoweredGraph(const ir::Graph &graph, const CompilerOptions &options) : _graph{graph}
{
bool linear_executor = (options.executor == "Linear");
// Build backend contexts
- auto &backend_manager = compiler::BackendManager::get();
+ auto &backend_manager = BackendManager::get();
// Always create Controlflow backend context
auto cf_backend = backend_manager.getControlflow();
// TODO Move "schedule" phase out of here
// Schedule
- std::unique_ptr<compiler::BackendResolver> backend_resolver;
+ std::unique_ptr<BackendResolver> backend_resolver;
if (options.he_scheduler)
{
- auto scheduler = compiler::HEScheduler(_backend_contexts, options);
+ auto scheduler = HEScheduler(_backend_contexts, options);
backend_resolver = scheduler.schedule(_graph);
_indexed_ranks = scheduler.getIndexedRanks();
}
else
{
- auto scheduler = compiler::ManualScheduler(_backend_contexts, options);
+ auto scheduler = ManualScheduler(_backend_contexts, options);
backend_resolver = scheduler.schedule(_graph);
}
{
// operand::LowerInfo holder
- OperandIndexMap<std::unique_ptr<operand::LowerInfo>> operands_lower_info;
+ ir::OperandIndexMap<std::unique_ptr<ir::operand::LowerInfo>> operands_lower_info;
- _graph.operands().iterate([&](const OperandIndex &index, const Operand &) {
- operands_lower_info[index] = std::make_unique<operand::LowerInfo>();
+ _graph.operands().iterate([&](const ir::OperandIndex &index, const ir::Operand &) {
+ operands_lower_info[index] = std::make_unique<ir::operand::LowerInfo>();
});
// Make op_seqs while checking whether a node can be merged into a op_seq.
makeOpSequences(operands_lower_info, options, *backend_resolver);
- _op_seqs.iterate([&](const OpSequenceIndex &, OpSequence &op_seq) {
+ _op_seqs.iterate([&](const ir::OpSequenceIndex &, ir::OpSequence &op_seq) {
assert(op_seq.operations().size() > 0);
std::reverse(std::begin(op_seq.operations()), std::end(op_seq.operations()));
});
VERBOSE(OpSequences) << "dump without permutation" << std::endl;
dumpOpSequences(_op_seqs, _graph.operations());
- compiler::pass::ConstantInsertionPass ci_pass(*this);
+ pass::ConstantInsertionPass ci_pass(*this);
ci_pass.run();
- compiler::pass::ConstantLoweringPass cl_pass(*this);
+ pass::ConstantLoweringPass cl_pass(*this);
cl_pass.run();
// Set LowerInfo for each operand from the operand::LowerInfo holder
// Run Permutation Passes
{
- compiler::pass::PermutationOperationPass po_pass(*this);
+ pass::PermutationOperationPass po_pass(*this);
po_pass.run();
- compiler::pass::PermutationInsertionPass pi_pass(*this);
+ pass::PermutationInsertionPass pi_pass(*this);
pi_pass.run();
- compiler::pass::PermutationEliminationPass pe_pass(*this);
+ pass::PermutationEliminationPass pe_pass(*this);
pe_pass.run();
VERBOSE(OpSequences) << "dump with permutation" << std::endl;
// Graph verifications
{
- assert(verifier::DAGChecker().verify(_graph));
- assert(verifier::EdgeConsistencyChecker().verify(_graph));
+ assert(ir::verifier::DAGChecker().verify(_graph));
+ assert(ir::verifier::EdgeConsistencyChecker().verify(_graph));
}
}
-const operation::LowerInfo *LoweredGraph::getLowerInfo(const OpSequenceIndex &op_seq_index) const
+const ir::operation::LowerInfo *
+LoweredGraph::getLowerInfo(const ir::OpSequenceIndex &op_seq_index) const
{
auto itr = _lower_info_map.op_seq.find(op_seq_index);
if (itr == _lower_info_map.op_seq.end())
return itr->second.get();
}
-void LoweredGraph::setLowerInfo(const OpSequenceIndex &op_seq_index,
- std::unique_ptr<operation::LowerInfo> &&lower_info)
+void LoweredGraph::setLowerInfo(const ir::OpSequenceIndex &op_seq_index,
+ std::unique_ptr<ir::operation::LowerInfo> &&lower_info)
{
_lower_info_map.op_seq.insert(std::make_pair(op_seq_index, std::move(lower_info)));
}
-void LoweredGraph::removeLowerInfo(const OpSequenceIndex &op_seq_index)
+void LoweredGraph::removeLowerInfo(const ir::OpSequenceIndex &op_seq_index)
{
auto &op_seq_lower_info = _lower_info_map.op_seq;
assert(op_seq_lower_info.find(op_seq_index) != op_seq_lower_info.end());
}
}
-const operand::LowerInfo *LoweredGraph::getLowerInfo(const OperandIndex &index) const
+const ir::operand::LowerInfo *LoweredGraph::getLowerInfo(const ir::OperandIndex &index) const
{
auto itr = _lower_info_map.operand.find(index);
if (itr == _lower_info_map.operand.end())
return itr->second.get();
}
-operand::LowerInfo *LoweredGraph::getLowerInfo(const OperandIndex &index)
+ir::operand::LowerInfo *LoweredGraph::getLowerInfo(const ir::OperandIndex &index)
{
auto itr = _lower_info_map.operand.find(index);
if (itr == _lower_info_map.operand.end())
return itr->second.get();
}
-void LoweredGraph::setLowerInfo(const OperandIndex &index,
- std::unique_ptr<operand::LowerInfo> &&lower_info)
+void LoweredGraph::setLowerInfo(const ir::OperandIndex &index,
+ std::unique_ptr<ir::operand::LowerInfo> &&lower_info)
{
_lower_info_map.operand.insert(std::make_pair(index, std::move(lower_info)));
}
-void LoweredGraph::removeLowerInfo(const OperandIndex &index)
+void LoweredGraph::removeLowerInfo(const ir::OperandIndex &index)
{
_lower_info_map.operand.erase(index);
}
void LoweredGraph::iterateTopolOpSeqs(
- const std::function<void(const OpSequenceIndex &, const OpSequence &)> &fn) const
+ const std::function<void(const ir::OpSequenceIndex &, const ir::OpSequence &)> &fn) const
{
- // Topological Sorting for OpSequences
- std::vector<OpSequenceIndex> topol_sorted;
- PostDfsIterator<true>{}.iterateOpSeqs(
- *this,
- [&](const OpSequenceIndex &index, const OpSequence &) { topol_sorted.emplace_back(index); });
+ // Topological Sorting for ir::OpSequences
+ std::vector<ir::OpSequenceIndex> topol_sorted;
+ ir::PostDfsIterator<true>{}.iterateOpSeqs(
+ *this, [&](const ir::OpSequenceIndex &index, const ir::OpSequence &) {
+ topol_sorted.emplace_back(index);
+ });
std::reverse(topol_sorted.begin(), topol_sorted.end());
for (const auto op_seq_idx : topol_sorted)
{
}
void LoweredGraph::iterateTopolOpSeqs(
- const std::function<void(const OpSequenceIndex &, OpSequence &)> &fn)
+ const std::function<void(const ir::OpSequenceIndex &, ir::OpSequence &)> &fn)
{
- // Topological Sorting for OpSequences
- std::vector<OpSequenceIndex> topol_sorted;
- PostDfsIterator<false>{}.iterateOpSeqs(
- *this, [&](const OpSequenceIndex &index, OpSequence &) { topol_sorted.emplace_back(index); });
+ // Topological Sorting for ir::OpSequences
+ std::vector<ir::OpSequenceIndex> topol_sorted;
+ ir::PostDfsIterator<false>{}.iterateOpSeqs(
+ *this, [&](const ir::OpSequenceIndex &index, ir::OpSequence &) {
+ topol_sorted.emplace_back(index);
+ });
std::reverse(topol_sorted.begin(), topol_sorted.end());
for (const auto op_seq_idx : topol_sorted)
{
}
}
-OpSequenceIndex LoweredGraph::appendFreshSingleOpSequence(const OperationIndex &node_index,
- const Operation &node)
+ir::OpSequenceIndex LoweredGraph::appendFreshSingleOpSequence(const ir::OperationIndex &node_index,
+ const ir::Operation &node)
{
// Create a fresh op_seq with one operation, and append it to op_seqs
// Create a fresh op_seq
- auto op_seq = std::make_unique<OpSequence>(_graph.layout());
+ auto op_seq = std::make_unique<ir::OpSequence>(_graph.layout());
// Add an operation
op_seq->appendOperation(node_index);
}
void LoweredGraph::makeOpSequences(
- OperandIndexMap<std::unique_ptr<operand::LowerInfo>> &operands_lower_info,
- const compiler::CompilerOptions &options, const compiler::BackendResolver &backend_resolver)
+ ir::OperandIndexMap<std::unique_ptr<ir::operand::LowerInfo>> &operands_lower_info,
+ const CompilerOptions &options, const BackendResolver &backend_resolver)
{
// if SUBG_MAX_NODE == 0, no limit on nodes of a op_seq
const int op_seq_max_node = options.op_seq_max_node;
assert(op_seq_max_node >= 0);
bool is_profiling = options.he_profiling_mode;
- OpSequence *op_seq = nullptr;
- OpSequenceIndex op_seq_index;
+ ir::OpSequence *op_seq = nullptr;
+ ir::OpSequenceIndex op_seq_index;
// NOTE: The below method appends nodes while making one op_seq if needed. If something better
// ways, happy to update this code.
- PostDfsConstIterator{}.iterate(
- _graph, [&](const OperationIndex &node_index, const Operation &node) {
+ ir::PostDfsConstIterator{}.iterate(
+ _graph, [&](const ir::OperationIndex &node_index, const ir::Operation &node) {
// LowerInfo for in/output operands
auto backend = backend_resolver.getBackend(node_index);
for (auto operand : node.getInputs() | ir::Remove::UNDEFINED)
{
auto &&lower_info = operands_lower_info.at(operand);
- lower_info->addUsePermuteFactor(operand::PermuteFactor{backend, backend_layout});
+ lower_info->addUsePermuteFactor(ir::operand::PermuteFactor{backend, backend_layout});
}
for (auto operand : node.getOutputs())
{
auto &&lower_info = operands_lower_info.at(operand);
- lower_info->addDefPermuteFactor(operand::PermuteFactor{backend, backend_layout});
+ lower_info->addDefPermuteFactor(ir::operand::PermuteFactor{backend, backend_layout});
}
bool new_op_seq = (op_seq == nullptr ||
{
auto new_op_seq_index = appendFreshSingleOpSequence(node_index, node);
- // OpSequence LowerInfo
+ // ir::OpSequence LowerInfo
setLowerInfo(new_op_seq_index,
- std::make_unique<operation::LowerInfo>(backend, backend_layout));
+ std::make_unique<ir::operation::LowerInfo>(backend, backend_layout));
op_seq_index = new_op_seq_index;
op_seq = &(_op_seqs.at(new_op_seq_index));
}
void LoweredGraph::manipulateLowerInfo(
- OperandIndexMap<std::unique_ptr<operand::LowerInfo>> &operands_lower_info, bool is_primary)
+ ir::OperandIndexMap<std::unique_ptr<ir::operand::LowerInfo>> &operands_lower_info,
+ bool is_primary)
{
- const auto controlflow_backend = compiler::BackendManager::get().getControlflow();
+ const auto controlflow_backend = BackendManager::get().getControlflow();
// TODO Rather than handling primary graph specially,
// let the permute inserted and remove it later
if (is_primary)
{
// TODO Rather than using NHWC Get frontend layout of this node from IR
- auto factor = operand::PermuteFactor{controlflow_backend, Layout::NHWC};
+ auto factor = ir::operand::PermuteFactor{controlflow_backend, ir::Layout::NHWC};
for (auto index : _graph.getInputs() | ir::Remove::UNDEFINED)
{
auto &&lower_info = operands_lower_info.at(index);
else
{
// In case of that an operand is Graph's input and not input or output of any operation
- lower_info->addDefPermuteFactor(operand::PermuteFactor{
+ lower_info->addDefPermuteFactor(ir::operand::PermuteFactor{
controlflow_backend,
- Layout::NHWC // TODO Get frontend layout of this node from IR
+ ir::Layout::NHWC // TODO Get frontend layout of this node from IR
});
}
}
if (lower_info->def_factors().size() == 0)
{
// In case of that an operand is Graph's output and not input or output of any operation
- lower_info->addDefPermuteFactor(operand::PermuteFactor{
+ lower_info->addDefPermuteFactor(ir::operand::PermuteFactor{
controlflow_backend,
- Layout::NHWC // TODO Get frontend layout of this node from IR
+ ir::Layout::NHWC // TODO Get frontend layout of this node from IR
});
}
}
// Set LowerInfo for each operand from the operand::LowerInfo holder
- _graph.operands().iterate([&](const OperandIndex &index, Operand &) {
+ _graph.operands().iterate([&](const ir::OperandIndex &index, ir::Operand &) {
setLowerInfo(index, std::move(operands_lower_info[index]));
});
}
std::map<uint32_t, std::string> dumps;
- _graph.operands().iterate([&](const OperandIndex &index, Operand &object) {
+ _graph.operands().iterate([&](const ir::OperandIndex &index, ir::Operand &object) {
std::stringstream sstream;
if (!getLowerInfo(index)->def_factors().empty() || !getLowerInfo(index)->use_factors().empty())
{
- auto factors_to_string = [](const operand::PermuteFactorSet &factors) {
+ auto factors_to_string = [](const ir::operand::PermuteFactorSet &factors) {
std::string str;
for (auto factor : factors)
{
return "{ " + str + "}";
};
- auto operation_index_to_string = [](const OperationIndexSet &operations) {
+ auto operation_index_to_string = [](const ir::OperationIndexSet &operations) {
std::string str;
for (auto op : operations)
{
sstream << (shape.dim(i)) << " ";
}
sstream << "}" << std::endl;
- sstream << " - Def Operations : " << def_ops << std::endl;
- sstream << " - Use Operations : " << use_ops << std::endl;
+ sstream << " - Def ir::Operations : " << def_ops << std::endl;
+ sstream << " - Use ir::Operations : " << use_ops << std::endl;
sstream << " - Lower Info" << std::endl;
sstream << " - Def Backends : " << def_layouts << std::endl;
sstream << " - Use Backends : " << use_layouts << std::endl;
}
}
-bool LoweredGraph::mergeable(const OpSequenceIndex &op_seq_index, const OperationIndex &node_index,
- Layout layout, const compiler::BackendResolver &backend_resolver)
+bool LoweredGraph::mergeable(const ir::OpSequenceIndex &op_seq_index,
+ const ir::OperationIndex &node_index, ir::Layout layout,
+ const BackendResolver &backend_resolver)
{
// Are they mergeable?
// 1. the same backend id and layout?
// Branched?
{
- std::unordered_set<OperationIndex> branched_set;
+ std::unordered_set<ir::OperationIndex> branched_set;
// Check for branching up
- for (const auto &input : op_seq.getInputs() | Remove::DUPLICATED | ir::Remove::UNDEFINED)
+ for (const auto &input : op_seq.getInputs() | ir::Remove::DUPLICATED | ir::Remove::UNDEFINED)
{
const auto &input_obj = _graph.operands().at(input);
auto def = input_obj.getDef();
branched_set.clear();
// Check for branching down
- for (const auto &output : node.getOutputs() | Remove::DUPLICATED)
+ for (const auto &output : node.getOutputs() | ir::Remove::DUPLICATED)
{
// TODO Fix this workaround for the case of model outputs that are used by another operation
// This is needed since the branching is decided by operation, but for model outputs,
const auto &node_outputs = node.getOutputs();
// op_seq's operations are in order so that we just check the first and the last
- std::vector<OperationIndex> op_seq_ops{op_seq.operations()[0]};
+ std::vector<ir::OperationIndex> op_seq_ops{op_seq.operations()[0]};
if (op_seq.operations().size() > 1)
op_seq_ops.emplace_back(op_seq.operations()[op_seq.operations().size() - 1]);
return false;
}
-} // namespace ir
+} // namespace compiler
} // namespace onert
#define __ONERT_IR_PASS_LOWERED_OPERAND_PASS_H__
#include "OperandPass.h"
-#include "ir/LoweredGraph.h"
+#include "compiler/LoweredGraph.h"
namespace onert
{
class LoweredOperandPass : public OperandPass
{
public:
- LoweredOperandPass(ir::LoweredGraph &lowered_graph)
+ LoweredOperandPass(compiler::LoweredGraph &lowered_graph)
: OperandPass{lowered_graph.graph()}, _lowered_graph{lowered_graph}
{
// DO NOTHING
void callback(const ir::OperandIndex &i, ir::Operand &o) override = 0;
protected:
- ir::LoweredGraph &_lowered_graph;
+ compiler::LoweredGraph &_lowered_graph;
};
} // namespace pass
#define __ONERT_IR_PASS_LOWERED_OPERATION_PASS_H__
#include "OperationPass.h"
-#include "ir/LoweredGraph.h"
+#include "compiler/LoweredGraph.h"
namespace onert
{
class LoweredOperationPass : public OperationPass
{
public:
- LoweredOperationPass(ir::LoweredGraph &lowered_graph)
+ LoweredOperationPass(LoweredGraph &lowered_graph)
: OperationPass{lowered_graph.graph()}, _lowered_graph{lowered_graph}
{
// DO NOTHING
void callback(const ir::OperationIndex &i, ir::Operation &o) override = 0;
protected:
- ir::LoweredGraph &_lowered_graph;
+ LoweredGraph &_lowered_graph;
};
} // namespace pass
*/
#include "ir/Graph.h"
-#include "ir/LoweredGraph.h"
+#include "compiler/LoweredGraph.h"
#ifndef __ONERT_DUMPER_DOT_DOT_DUMPER_H__
#define __ONERT_DUMPER_DOT_DOT_DUMPER_H__
: _lowered_graph{nullptr}, _graph(graph), _level{level}
{
}
- DotDumper(const ir::LoweredGraph *lowered_graph, Level level)
+ DotDumper(const compiler::LoweredGraph *lowered_graph, Level level)
: _lowered_graph{lowered_graph}, _graph(_lowered_graph->graph()), _level{level}
{
}
void dump(const std::string &tag);
private:
- const ir::LoweredGraph *_lowered_graph;
+ const compiler::LoweredGraph *_lowered_graph;
const ir::Graph &_graph;
Level _level;
};
}
DataflowExecutor::DataflowExecutor(
- std::unique_ptr<ir::LoweredGraph> lowered_graph,
+ std::unique_ptr<compiler::LoweredGraph> lowered_graph,
const std::vector<std::shared_ptr<backend::ITensor>> &input_tensors,
const std::vector<std::shared_ptr<backend::ITensor>> &output_tensors,
const compiler::TensorBuilders &tensor_builders, compiler::CodeMap &&code_map)
* @param tensor_builders Tensor builders that are currently used
* @param code_map OpSequence and its code map
*/
- DataflowExecutor(std::unique_ptr<ir::LoweredGraph> lowered_graph,
+ DataflowExecutor(std::unique_ptr<compiler::LoweredGraph> lowered_graph,
const std::vector<std::shared_ptr<backend::ITensor>> &input_tensors,
const std::vector<std::shared_ptr<backend::ITensor>> &output_tensors,
const compiler::TensorBuilders &tensor_builders, compiler::CodeMap &&code_map);
namespace exec
{
-ExecutorBase::ExecutorBase(std::unique_ptr<ir::LoweredGraph> &&lowered_graph,
+ExecutorBase::ExecutorBase(std::unique_ptr<compiler::LoweredGraph> &&lowered_graph,
const std::vector<std::shared_ptr<backend::ITensor>> &input_tensors,
const std::vector<std::shared_ptr<backend::ITensor>> &output_tensors,
const compiler::TensorBuilders &tensor_builders)
#include "Sink.h"
#include "ShapeConverter.h"
#include "exec/IExecutor.h"
-#include "ir/LoweredGraph.h"
+#include "compiler/LoweredGraph.h"
#include "ir/LowerInfoMap.h"
#include "backend/IConfig.h"
#include "backend/Backend.h"
* @param graph Graph object
* @param tensor_builders Tensor builders that are currently used
*/
- ExecutorBase(std::unique_ptr<ir::LoweredGraph> &&lowered_graph,
+ ExecutorBase(std::unique_ptr<compiler::LoweredGraph> &&lowered_graph,
const std::vector<std::shared_ptr<backend::ITensor>> &input_tensors,
const std::vector<std::shared_ptr<backend::ITensor>> &output_tensors,
const compiler::TensorBuilders &tensor_builders);
protected:
ExecutionObservee _subject;
std::shared_ptr<ir::OperationIndexMap<int64_t>> _indexed_ranks;
- std::unique_ptr<ir::LoweredGraph> _lowered_graph;
+ std::unique_ptr<compiler::LoweredGraph> _lowered_graph;
const ir::Graph &_graph;
std::vector<std::shared_ptr<backend::ITensor>> _input_tensors;
std::vector<std::shared_ptr<backend::ITensor>> _output_tensors;
* @param tensor_builders Tensor builders that are currently used
* @param code_map OpSequence and its code map
*/
- LinearExecutor(std::unique_ptr<ir::LoweredGraph> lowered_graph,
+ LinearExecutor(std::unique_ptr<compiler::LoweredGraph> lowered_graph,
const std::vector<std::shared_ptr<backend::ITensor>> &input_tensors,
const std::vector<std::shared_ptr<backend::ITensor>> &output_tensors,
const compiler::TensorBuilders &tensor_builders, compiler::CodeMap &&code_map,
}
ParallelExecutor::ParallelExecutor(
- std::unique_ptr<ir::LoweredGraph> lowered_graph,
+ std::unique_ptr<compiler::LoweredGraph> lowered_graph,
const std::vector<std::shared_ptr<backend::ITensor>> &input_tensors,
const std::vector<std::shared_ptr<backend::ITensor>> &output_tensors,
const compiler::TensorBuilders &tensor_builders, compiler::CodeMap &&code_map)
* @param tensor_builders Tensor builders that are currently used
* @param code_map OpSequence and its code map
*/
- ParallelExecutor(std::unique_ptr<ir::LoweredGraph> lowered_graph,
+ ParallelExecutor(std::unique_ptr<compiler::LoweredGraph> lowered_graph,
const std::vector<std::shared_ptr<backend::ITensor>> &input_tensors,
const std::vector<std::shared_ptr<backend::ITensor>> &output_tensors,
const compiler::TensorBuilders &tensor_builders, compiler::CodeMap &&code_map);
#include "GraphIterator.h"
#include "ir/OperationIndexMap.h"
-#include "ir/LoweredGraph.h"
+#include "compiler/LoweredGraph.h"
namespace onert
{
namespace onert
{
+namespace compiler
+{
+class LoweredGraph;
+} // namespace compiler
+} // namespace onert
+
+namespace onert
+{
namespace ir
{
class Graph;
class Operation;
-class LoweredGraph;
class OpSequence;
template <bool is_const> class Iterator
using NodeRef = typename Iterator<is_const>::NodeRef;
using IterFn = typename Iterator<is_const>::IterFn;
using LoweredGraphRef =
- typename std::conditional<is_const, const LoweredGraph &, LoweredGraph &>::type;
+ typename std::conditional<is_const, const typename compiler::LoweredGraph &,
+ typename compiler::LoweredGraph &>::type;
using OpSequenceRef = typename std::conditional<is_const, const OpSequence &, OpSequence &>::type;
using OpSeqIndexRef = const OpSequenceIndex &;
using OpSeqIterFn = std::function<void(OpSeqIndexRef, OpSequenceRef)>;