#include "AvgPool2D.h"
+#include <cassert>
+
namespace neurun
{
namespace graph
namespace Implicit
{
-// NO IMPLEMENTATION YET
+void Node::inputs(const operand::IndexSet &indexes)
+{
+ assert(indexes.size() == 1);
+
+ ::neurun::graph::operand::IO::Index index{0};
+ _op->param().ifm_index = indexes.at(index).asInt();
+}
+
+void Node::outputs(const operand::IndexSet &indexes)
+{
+ assert(indexes.size() == 1);
+
+ ::neurun::graph::operand::IO::Index index{0};
+ _op->param().ofm_index = indexes.at(index).asInt();
+}
} // namespace Implicit
} // namespace AvgPool2D
public:
virtual operand::IndexSet inputs() const override { return {_op->param().ifm_index}; }
virtual operand::IndexSet outputs() const override { return {_op->param().ofm_index}; }
+ virtual void inputs(const operand::IndexSet &indexes) override;
+ virtual void outputs(const operand::IndexSet &indexes) override;
virtual const ::internal::tflite::op::Node *op() const override { return _op.get(); }
private:
#include "Concat.h"
+#include <cassert>
+
namespace neurun
{
namespace graph
return set;
}
+void Node::inputs(const operand::IndexSet &indexes)
+{
+ std::vector<int32_t> inds;
+ for (auto index : indexes.list())
+ {
+ inds.emplace_back(index.asInt());
+ }
+ _op->param().ifm_indexes = inds;
+}
+
+void Node::outputs(const operand::IndexSet &indexes)
+{
+ assert(indexes.size() == 1);
+
+ ::neurun::graph::operand::IO::Index index{0};
+ _op->param().ofm_index = indexes.at(index).asInt();
+}
+
} // namespace Concat
} // namespace operation
} // namespace graph
public:
virtual operand::IndexSet inputs() const override;
virtual operand::IndexSet outputs() const override { return {_op->param().ofm_index}; }
+ virtual void inputs(const operand::IndexSet &indexes) override;
+ virtual void outputs(const operand::IndexSet &indexes) override;
virtual const ::internal::tflite::op::Node *op() const override { return _op.get(); }
private:
#include "Conv2D.h"
+#include <cassert>
+
namespace neurun
{
namespace graph
namespace Implicit
{
-// NO IMPLEMENTATION YET
+void Node::inputs(const operand::IndexSet &indexes)
+{
+ assert(indexes.size() == 1);
+
+ ::neurun::graph::operand::IO::Index index{0};
+ _op->param().ifm_index = indexes.at(index).asInt();
+}
+
+void Node::outputs(const operand::IndexSet &indexes)
+{
+ assert(indexes.size() == 1);
+
+ ::neurun::graph::operand::IO::Index index{0};
+ _op->param().ofm_index = indexes.at(index).asInt();
+}
} // namespace Implicit
} // namespace Conv2D
return {_op->param().ifm_index, _op->param().ker_index, _op->param().bias_index};
}
virtual operand::IndexSet outputs() const override { return {_op->param().ofm_index}; }
+ virtual void inputs(const operand::IndexSet &indexes) override;
+ virtual void outputs(const operand::IndexSet &indexes) override;
virtual const ::internal::tflite::op::Node *op() const override { return _op.get(); }
private:
#include "FullyConnected.h"
+#include <cassert>
+
namespace neurun
{
namespace graph
namespace FullyConnected
{
-// NO IMPLEMENTATION YET
+void Node::inputs(const operand::IndexSet &indexes)
+{
+ assert(indexes.size() == 1);
+
+ ::neurun::graph::operand::IO::Index index{0};
+ _op->param().input_index = indexes.at(index).asInt();
+}
+
+void Node::outputs(const operand::IndexSet &indexes)
+{
+ assert(indexes.size() == 1);
+
+ ::neurun::graph::operand::IO::Index index{0};
+ _op->param().output_index = indexes.at(index).asInt();
+}
} // namespace FullyConnected
} // namespace operation
return {_op->param().input_index, _op->param().weight_index, _op->param().bias_index};
}
virtual operand::IndexSet outputs() const override { return {_op->param().output_index}; }
+ virtual void inputs(const operand::IndexSet &indexes) override;
+ virtual void outputs(const operand::IndexSet &indexes) override;
virtual const ::internal::tflite::op::Node *op() const override { return _op.get(); }
private:
#include "MaxPool2D.h"
+#include <cassert>
+
namespace neurun
{
namespace graph
namespace Implicit
{
-// NO IMPLEMENTATION YET
+void Node::inputs(const operand::IndexSet &indexes)
+{
+ assert(indexes.size() == 1);
+
+ ::neurun::graph::operand::IO::Index index{0};
+ _op->param().ifm_index = indexes.at(index).asInt();
+}
+
+void Node::outputs(const operand::IndexSet &indexes)
+{
+ assert(indexes.size() == 1);
+
+ ::neurun::graph::operand::IO::Index index{0};
+ _op->param().ofm_index = indexes.at(index).asInt();
+}
} // namespace Implicit
} // namespace MaxPool2D
public:
virtual operand::IndexSet inputs() const override { return {_op->param().ifm_index}; }
virtual operand::IndexSet outputs() const override { return {_op->param().ofm_index}; }
+ virtual void inputs(const operand::IndexSet &indexes) override;
+ virtual void outputs(const operand::IndexSet &indexes) override;
virtual const ::internal::tflite::op::Node *op() const override { return _op.get(); }
private:
return set;
}
+void Node::inputs(const operand::IndexSet &indexes)
+{
+ std::vector<int32_t> inds;
+ for (auto index : indexes.list())
+ {
+ inds.emplace_back(index.asInt());
+ }
+ _op->param().ifm_indexes = inds;
+}
+
+void Node::outputs(const operand::IndexSet &indexes)
+{
+ std::vector<int32_t> inds;
+ for (auto index : indexes.list())
+ {
+ inds.emplace_back(index.asInt());
+ }
+ _op->param().ofm_indexes = inds;
+}
+
} // namespace NOP
} // namespace operation
} // namespace graph
public:
virtual operand::IndexSet inputs() const override;
virtual operand::IndexSet outputs() const override;
+ virtual void inputs(const operand::IndexSet &indexes) override;
+ virtual void outputs(const operand::IndexSet &indexes) override;
virtual const ::internal::tflite::op::Node *op() const override { return _op.get(); }
private:
public:
virtual operand::IndexSet inputs() const = 0;
virtual operand::IndexSet outputs() const = 0;
+ // It's for only input/output tensors but const data.
+ virtual void inputs(const operand::IndexSet &indexes) = 0;
+ virtual void outputs(const operand::IndexSet &indexes) = 0;
virtual const ::internal::tflite::op::Node *op() const = 0;
public:
#include "Reshape.h"
+#include <cassert>
+
namespace neurun
{
namespace graph
namespace Reshape
{
-// NO IMPLEMENTATION YET
+void Node::inputs(const operand::IndexSet &indexes)
+{
+ assert(indexes.size() == 1);
+
+ ::neurun::graph::operand::IO::Index index{0};
+ _op->param().input_index = indexes.at(index).asInt();
+}
+
+void Node::outputs(const operand::IndexSet &indexes)
+{
+ assert(indexes.size() == 1);
+
+ ::neurun::graph::operand::IO::Index index{0};
+ _op->param().output_index = indexes.at(index).asInt();
+}
} // namespace Reshape
} // namespace operation
return {_op->param().input_index, _op->param().shape_index};
}
virtual operand::IndexSet outputs() const override { return {_op->param().output_index}; }
+ virtual void inputs(const operand::IndexSet &indexes) override;
+ virtual void outputs(const operand::IndexSet &indexes) override;
virtual const ::internal::tflite::op::Node *op() const override { return _op.get(); }
private:
#include "Softmax.h"
+#include <cassert>
+
namespace neurun
{
namespace graph
namespace Softmax
{
-// NO IMPLEMENTATION YET
+void Node::inputs(const operand::IndexSet &indexes)
+{
+ assert(indexes.size() == 1);
+
+ ::neurun::graph::operand::IO::Index index{0};
+ _op->param().input_index = indexes.at(index).asInt();
+}
+
+void Node::outputs(const operand::IndexSet &indexes)
+{
+ assert(indexes.size() == 1);
+
+ ::neurun::graph::operand::IO::Index index{0};
+ _op->param().output_index = indexes.at(index).asInt();
+}
} // namespace Softmax
} // namespace operation
public:
virtual operand::IndexSet inputs() const override { return {_op->param().input_index}; }
virtual operand::IndexSet outputs() const override { return {_op->param().output_index}; }
+ virtual void inputs(const operand::IndexSet &indexes) override;
+ virtual void outputs(const operand::IndexSet &indexes) override;
virtual const ::internal::tflite::op::Node *op() const override { return _op.get(); }
private:
public:
const Param ¶m(void) const { return _param; }
+ Param ¶m(void) { return _param; }
public:
void accept(NodeVisitor &&) const override;
private:
- const Param _param;
+ Param _param;
};
} // namespace implicit
public:
const Param ¶m(void) const { return _param; }
+ Param ¶m(void) { return _param; }
public:
void accept(NodeVisitor &&) const override;
private:
- const Param _param;
+ Param _param;
};
} // namespace Concat
public:
const Param ¶m(void) const { return _param; }
+ Param ¶m(void) { return _param; }
public:
void accept(NodeVisitor &&) const override;
private:
- const Param _param;
+ Param _param;
};
} // namespace implicit
public:
const Param ¶m(void) const { return _param; }
+ Param ¶m(void) { return _param; }
public:
void accept(NodeVisitor &&) const override;
private:
- const Param _param;
+ Param _param;
};
} // namespace FullyConnected
public:
const Param ¶m(void) const { return _param; }
+ Param ¶m(void) { return _param; }
public:
void accept(NodeVisitor &&) const override;
private:
- const Param _param;
+ Param _param;
};
} // namespace implicit
public:
const Param ¶m(void) const { return _param; }
+ Param ¶m(void) { return _param; }
public:
void accept(NodeVisitor &&) const override;
private:
- const Param _param;
+ Param _param;
};
} // namespace NOP
public:
const Param ¶m(void) const { return _param; }
+ Param ¶m(void) { return _param; }
public:
void accept(NodeVisitor &&) const override;
private:
- const Param _param;
+ Param _param;
};
} // namespace Reshape
public:
const Param ¶m(void) const { return _param; }
+ Param ¶m(void) { return _param; }
public:
void accept(NodeVisitor &&) const override;
private:
- const Param _param;
+ Param _param;
};
} // namespace Softmax
public:
virtual neurun::graph::operand::IndexSet inputs() const { return {1, 2, 3, 4}; }
virtual neurun::graph::operand::IndexSet outputs() const { return {1, 2, 3}; }
+ virtual void inputs(const neurun::graph::operand::IndexSet &indexes) override {}
+ virtual void outputs(const neurun::graph::operand::IndexSet &indexes) override {}
virtual const ::internal::tflite::op::Node *op() const { return nullptr; }
};
--- /dev/null
+#include <gtest/gtest.h>
+
+#include "graph/Graph.h"
+#include "nnfw/std/memory.h"
+#include "graph/operation/Conv2D.h"
+#include "graph/operation/Concat.h"
+#include "graph/operand/Index.h"
+#include "graph/operand/IndexSet.h"
+
+#include <stdexcept>
+
+using Index = neurun::graph::operand::IO::Index;
+using IndexSet = neurun::graph::operand::IndexSet;
+
+TEST(graph_operation_setIO, operation_setIO_conv)
+{
+ neurun::graph::Graph graph;
+
+ neurun::internal::operand::Shape shape{1u};
+ shape.dim(0) = 3;
+
+ // Add Conv
+ std::vector<uint32_t> params;
+ for (int i = 0; i < 7; ++i)
+ {
+ params.emplace_back(graph.addOperand(shape).asInt());
+ }
+ uint32_t outoperand = graph.addOperand(shape).asInt();
+
+ using Param = internal::tflite::op::Conv2D::implicit::Param;
+ using Node = internal::tflite::op::Conv2D::implicit::Node;
+ using GraphNode = neurun::graph::operation::Conv2D::Implicit::Node;
+
+ auto conv = nnfw::make_unique<GraphNode>(
+ nnfw::make_unique<Node>(Param(7, params.data(), 1, &outoperand)));
+
+ ASSERT_EQ(conv->inputs().at(Index{0}).asInt(), params[0]);
+ conv->inputs({8});
+ ASSERT_NE(conv->inputs().at(Index{0}).asInt(), params[0]);
+ ASSERT_EQ(conv->inputs().at(Index{0}).asInt(), 8);
+}
+
+TEST(graph_operation_setIO, operation_setIO_concat)
+{
+ neurun::graph::Graph graph;
+
+ neurun::internal::operand::Shape shape{1u};
+ shape.dim(0) = 3;
+
+ // Add Concat
+ std::vector<uint32_t> params;
+ for (int i = 0; i < 7; ++i)
+ {
+ params.emplace_back(graph.addOperand(shape).asInt());
+ }
+ uint32_t outoperand = graph.addOperand(shape).asInt();
+
+ using Param = internal::tflite::op::Concat::Param;
+ using Node = internal::tflite::op::Concat::Node;
+ using GraphNode = neurun::graph::operation::Concat::Node;
+
+ auto concat = nnfw::make_unique<GraphNode>(
+ nnfw::make_unique<Node>(Param(7, params.data(), 1, &outoperand)));
+
+ ASSERT_EQ(concat->inputs().size(), 6);
+ ASSERT_EQ(concat->inputs().at(Index{0}).asInt(), params[0]);
+
+ concat->inputs({80, 6, 9, 11});
+ ASSERT_EQ(concat->inputs().size(), 4);
+ ASSERT_NE(concat->inputs().at(Index{0}).asInt(), params[0]);
+ ASSERT_EQ(concat->inputs().at(Index{0}).asInt(), 80);
+ ASSERT_EQ(concat->inputs().at(Index{2}).asInt(), 9);
+ ASSERT_THROW(concat->inputs().at(Index{5}), std::out_of_range);
+}
public:
virtual neurun::graph::operand::IndexSet inputs() const override { return {_input}; }
virtual neurun::graph::operand::IndexSet outputs() const override { return {_output}; }
+ virtual void inputs(const neurun::graph::operand::IndexSet &indexes) override {}
+ virtual void outputs(const neurun::graph::operand::IndexSet &indexes) override {}
virtual const ::internal::tflite::op::Node *op() const override { return nullptr; }
private: