operand::Index Graph::addOperand(const operand::Shape &shape, const operand::TypeInfo &type)
{
- return _operands.append(shape, type);
+ return _model.operands.append(shape, type);
}
operation::Index Graph::addOperation(std::unique_ptr<operation::Node> &&node)
{
assert(isBuildingPhase());
- return _operations.append(std::move(node));
+ return _model.operations.append(std::move(node));
}
void Graph::setOperandValue(const operand::Index &ind, std::unique_ptr<operand::Data> &&data)
{
assert(isBuildingPhase());
- assert(_operands.exist(ind));
- _operands.at(ind).data(std::move(data));
+ assert(_model.operands.exist(ind));
+ _model.operands.at(ind).data(std::move(data));
}
void Graph::addInput(const operand::Index &ind)
{
assert(isBuildingPhase());
- _inputs.append(ind);
+ _model.inputs.append(ind);
}
void Graph::addOutput(const operand::Index &ind)
{
assert(isBuildingPhase());
- _outputs.append(ind);
+ _model.outputs.append(ind);
}
void Graph::finishBuilding(void)
// operand::LowerInfo holder
std::unordered_map<operand::Index, std::unique_ptr<operand::LowerInfo>> operands_lower_info;
- _operands.iterate([&](const operand::Index &index, const operand::Object &object) {
+ _model.operands.iterate([&](const operand::Index &index, const operand::Object &object) {
operands_lower_info[index] =
nnfw::make_unique<operand::LowerInfo>(operand::asShape4D(object.shape()));
});
- _backend_resolver = nnfw::make_unique<codegen::BackendResolver>(_operands);
+ _backend_resolver = nnfw::make_unique<codegen::BackendResolver>(_model.operands);
- _operations.iterate([&](const operation::Index &, operation::Node &node) {
+ _model.operations.iterate([&](const operation::Index &, operation::Node &node) {
auto backend = _backend_resolver->getBackend(typeid(node));
// Operation LowerInfo
// Add DefBackend constants same as UseBackend
// NOTE This assumes a constant operand is used by only one operation
- _operations.iterate([&](const operation::Index &, operation::Node &node) {
+ _model.operations.iterate([&](const operation::Index &, operation::Node &node) {
// LowerInfo for input operands
for (auto operand : node.getInputs())
{
});
// Set LowerInfo for each operand from the operand::LowerInfo holder
- _operands.iterate([&](const operand::Index &index, operand::Object &object) {
+ _model.operands.iterate([&](const operand::Index &index, operand::Object &object) {
object.lower_info(std::move(operands_lower_info[index]));
// Dump operand LowerInfo
template <bool is_const>
void Graph::DefaultIterator<is_const>::iterate(GraphRef graph, const IterFn &fn) const
{
- graph._operations.iterate([&](const operation::Index &, NodeRef node) -> void { fn(node); });
+ graph.operations().iterate([&](const operation::Index &, NodeRef node) -> void { fn(node); });
}
//
{
assert(!graph.isBuildingPhase()); // Restrict iteration condition
- std::vector<bool> visited(graph._operations.size(), false);
+ std::vector<bool> visited(graph.operations().size(), false);
std::function<void(const operation::Index &, NodeRef)> dfs_recursive =
[&](const operation::Index &index, NodeRef node) -> void {
for (auto output : node.getOutputs())
{
- const auto &operand = graph._operands.at(output);
+ const auto &operand = graph.operands().at(output);
for (const auto &use : operand.getUses().list())
{
- dfs_recursive(use, graph._operations.at(use));
+ dfs_recursive(use, graph.operations().at(use));
}
}
fn(node);
};
- graph._operations.iterate(dfs_recursive);
+ graph.operations().iterate(dfs_recursive);
// All of the operations(nodes) must have been visited.
assert(std::all_of(visited.begin(), visited.end(), [](bool v) { return v; }));
#include <functional>
#include "graph/operation/Node.h"
-#include "graph/operation/Set.h"
-#include "graph/operand/IndexSet.h"
-#include "graph/operand/Set.h"
+#include "graph/Model.h"
namespace neurun
{
// Accessors
public:
- const operand::IndexSet &getInputs() const { return _inputs; }
- const operand::IndexSet &getOutputs() const { return _outputs; }
- operand::IndexSet &getOutputs() { return _outputs; }
- const operand::Set &operands() const { return _operands; }
- operand::Set &operands() { return _operands; } // TODO Remove this non-const accessor
- const operation::Set &operations() const { return _operations; }
- operation::Set &operations() { return _operations; }
+ const operand::IndexSet &getInputs() const { return _model.inputs; }
+ const operand::IndexSet &getOutputs() const { return _model.outputs; }
+ operand::IndexSet &getOutputs() { return _model.outputs; }
+ const operand::Set &operands() const { return _model.operands; }
+ operand::Set &operands() { return _model.operands; } // TODO Remove this non-const accessor
+ const operation::Set &operations() const { return _model.operations; }
+ operation::Set &operations() { return _model.operations; }
const codegen::BackendResolver *backend_resolver() const { return _backend_resolver.get(); }
private:
Phase _phase{Phase::BUILDING};
- operation::Set _operations;
- operand::Set _operands;
- operand::IndexSet _inputs;
- operand::IndexSet _outputs;
+ Model _model;
// For LOWERED phase
private:
--- /dev/null
+/*
+ * 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.
+ */
+
+#ifndef __NEURUN_GRAPH_MODEL_H__
+#define __NEURUN_GRAPH_MODEL_H__
+
+#include "graph/operation/Set.h"
+#include "graph/operand/IndexSet.h"
+#include "graph/operand/Set.h"
+
+namespace neurun
+{
+namespace graph
+{
+
+struct Model
+{
+ operation::Set operations;
+ operand::Set operands;
+ operand::IndexSet inputs;
+ operand::IndexSet outputs;
+};
+
+} // namespace graph
+} // namespace neurun
+
+#endif // __NEURUN_GRAPH_MODEL_H__