#ifndef __NEURUN_MODEL_OPERATIONS_H__
#define __NEURUN_MODEL_OPERATIONS_H__
-#include <memory>
-
#include "model/Index.h"
#include "model/Operation.h"
-
-#include <unordered_map>
+#include "util/ObjectManager.h"
namespace neurun
{
namespace model
{
-class Operations
+class Operations : public util::ObjectManager<OperationIndex, Operation>
{
-public:
- Operations() : _index_count(0) {}
-
-public:
- OperationIndex append(std::unique_ptr<Operation> &&node);
- void remove(const OperationIndex &index) { _nodes.erase(index); };
-
-public:
- const Operation &at(const OperationIndex &) const;
- Operation &at(const OperationIndex &);
- bool exist(const OperationIndex &) const;
- uint32_t size() const { return _nodes.size(); }
- void iterate(const std::function<void(const OperationIndex &, const Operation &)> &fn) const;
- void iterate(const std::function<void(const OperationIndex &, Operation &)> &fn);
-
-private:
- const OperationIndex generateIndex();
-
-private:
- std::unordered_map<OperationIndex, std::unique_ptr<Operation>> _nodes;
- OperationIndex _index_count;
};
} // namespace model
#ifndef __NEURUN_UTIL_OBJECT_MANAGER_H__
#define __NEURUN_UTIL_OBJECT_MANAGER_H__
+#include <unordered_map>
+#include <memory>
+
namespace neurun
{
namespace util
model::OperationIndex Graph::addOperation(std::unique_ptr<model::Operation> &&node)
{
assert(isBuildingPhase());
- return _model->operations.append(std::move(node));
+ return _model->operations.push(std::move(node));
}
void Graph::setOperandValue(const model::OperandIndex &ind, std::unique_ptr<model::Data> &&data)
auto insert_node = nnfw::cpp14::make_unique<PermuteNode>(operand_index, out_operand_index,
input_backend, output_backend);
- auto node_index = _graph.operations().append(std::move(insert_node));
+ auto node_index = _graph.operations().push(std::move(insert_node));
const auto &node = _graph.operations().at(node_index);
// Subgraph
+++ /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.
- */
-
-#include "model/Operations.h"
-
-#include <cassert>
-
-namespace neurun
-{
-namespace model
-{
-
-const OperationIndex Operations::generateIndex()
-{
- assert(_index_count.valid());
-
- return _index_count++;
-}
-
-OperationIndex Operations::append(std::unique_ptr<Operation> &&node)
-{
- auto index = generateIndex();
-
- _nodes[index] = std::move(node);
- return index;
-}
-
-const Operation &Operations::at(const OperationIndex &index) const { return *(_nodes.at(index)); }
-
-Operation &Operations::at(const OperationIndex &index) { return *(_nodes.at(index)); }
-
-bool Operations::exist(const OperationIndex &index) const
-{
- return _nodes.find(index) != _nodes.end();
-}
-
-void Operations::iterate(
- const std::function<void(const OperationIndex &, const Operation &)> &fn) const
-{
- for (auto it = _nodes.begin(); it != _nodes.end(); ++it)
- {
- fn(it->first, *it->second);
- }
-}
-
-void Operations::iterate(const std::function<void(const OperationIndex &, Operation &)> &fn)
-{
- for (auto it = _nodes.begin(); it != _nodes.end(); ++it)
- {
- fn(it->first, *it->second);
- }
-}
-
-} // namespace model
-} // namespace neurun
OperationFactory::Param param{inputCount, inputs, outputCount, outputs};
auto node = factory.create(type, param, _model->operands);
- _model->operations.append(std::unique_ptr<neurun::model::Operation>{node});
+ _model->operations.push(std::unique_ptr<neurun::model::Operation>{node});
}
catch (const std::exception &e)
{
OperationFactory::Param param{inputCount, inputs, outputCount, outputs};
auto node = factory.create(type, param, _model->operands);
- _model->operations.append(std::unique_ptr<neurun::model::Operation>{node});
+ _model->operations.push(std::unique_ptr<neurun::model::Operation>{node});
}
catch (const std::exception &e)
{
// MockNode1
auto operand_index1 = model->operands.emplace(shape, type);
- auto mocknode_index1 = model->operations.append(
+ auto mocknode_index1 = model->operations.push(
nnfw::cpp14::make_unique<MockNode>(IndexSet{input_operand}, IndexSet{operand_index1}));
// MockNode2
auto operand_index2 = model->operands.emplace(shape, type);
- auto mocknode_index2 = model->operations.append(
+ auto mocknode_index2 = model->operations.push(
nnfw::cpp14::make_unique<MockNode>(IndexSet{input_operand}, IndexSet{operand_index2}));
// MockNode3(two input)
- auto multiinput_index = model->operations.append(nnfw::cpp14::make_unique<MockNode>(
+ auto multiinput_index = model->operations.push(nnfw::cpp14::make_unique<MockNode>(
IndexSet{operand_index1, operand_index2}, IndexSet{output_operand}));
neurun::graph::Graph graph{std::move(model)};
TEST(graph_operation_Set, operation_test)
{
Operations ops;
- ops.append(
+ ops.push(
std::unique_ptr<Operation>(new neurun_test::graph::SimpleMockNode({1, 2, 3, 4}, {5, 6, 7})));
OperationIndex idx{0u};
ASSERT_EQ(ops.at(idx).getInputs().size(), 4);
model->inputs.append(operand1);
model->outputs.append(operand2);
- model->operations.append(
+ model->operations.push(
nnfw::cpp14::make_unique<MockNode>(IndexSet{operand1}, IndexSet{operand2}));
neurun::graph::Graph graph{std::move(model)};
param.activation = neurun::model::Activation::NONE;
auto input_set = OperandIndexSequence{operand_lhs, operand_rhs};
auto output_set = OperandIndexSequence{operand_result};
- model->operations.append(
+ model->operations.push(
nnfw::cpp14::make_unique<operation::AddNode>(input_set, output_set, param));
// Identify model inputs and outputs
param1.activation = neurun::model::Activation::NONE;
auto input_set1 = OperandIndexSequence{operand_lhs, operand_rhs1};
auto output_set1 = OperandIndexSequence{operand_result1};
- model->operations.append(
+ model->operations.push(
nnfw::cpp14::make_unique<operation::AddNode>(input_set1, output_set1, param1));
operation::AddNode::Param param2;
param2.activation = neurun::model::Activation::NONE;
auto input_set2 = OperandIndexSequence{operand_result1, operand_rhs2};
auto output_set2 = OperandIndexSequence{operand_result2};
- model->operations.append(
+ model->operations.push(
nnfw::cpp14::make_unique<operation::AddNode>(input_set2, output_set2, param2));
// Identify model inputs and outputs