summaryrefslogtreecommitdiff
path: root/runtimes/neurun/test/graph/operation/SetIO.cc
diff options
context:
space:
mode:
Diffstat (limited to 'runtimes/neurun/test/graph/operation/SetIO.cc')
-rw-r--r--runtimes/neurun/test/graph/operation/SetIO.cc86
1 files changed, 49 insertions, 37 deletions
diff --git a/runtimes/neurun/test/graph/operation/SetIO.cc b/runtimes/neurun/test/graph/operation/SetIO.cc
index a475bdcc9..88e111e97 100644
--- a/runtimes/neurun/test/graph/operation/SetIO.cc
+++ b/runtimes/neurun/test/graph/operation/SetIO.cc
@@ -17,72 +17,84 @@
#include <gtest/gtest.h>
#include "graph/Graph.h"
-#include "cpp14/memory.h"
+#include "model/Model.h"
+#include "model/Index.h"
+#include "model/OperandIndexSequence.h"
#include "model/operation/Conv2DNode.h"
#include "model/operation/ConcatNode.h"
-#include "model/operand/Index.h"
-#include "model/operand/IndexSet.h"
+
+#include <cpp14/memory.h>
#include <stdexcept>
-using Index = neurun::model::operand::IO::Index;
-using IndexSet = neurun::model::operand::IndexSet;
-using GraphNodeInitParam = neurun::model::operation::Node::InitParam;
+using Index = neurun::model::IOIndex;
+using IndexSet = neurun::model::OperandIndexSequence;
TEST(graph_operation_setIO, operation_setIO_conv)
{
- neurun::graph::Graph graph;
+ neurun::model::Model model;
- neurun::model::operand::Shape shape{1u};
- neurun::model::operand::TypeInfo type{ANEURALNETWORKS_TENSOR_INT32, 0, 0};
- shape.dim(0) = 3;
+ neurun::model::Shape shape{3};
+ neurun::model::TypeInfo type{neurun::model::DataType::INT32};
// Add Conv
- std::vector<uint32_t> params;
- for (int i = 0; i < 7; ++i)
- {
- params.emplace_back(graph.addOperand(shape, type).asInt());
- }
- uint32_t outoperand = graph.addOperand(shape, type).asInt();
-
using GraphNode = neurun::model::operation::Conv2DNode;
- auto conv =
- nnfw::cpp14::make_unique<GraphNode>(GraphNodeInitParam{7, params.data(), 1, &outoperand});
- ASSERT_EQ(conv->getInputs().at(Index{0}).asInt(), params[0]);
+ auto input_operand = model.operands.emplace(shape, type);
+ auto kernel_operand = model.operands.emplace(shape, type);
+ auto bias_operand = model.operands.emplace(shape, type);
+ IndexSet inputs{input_operand, kernel_operand, bias_operand};
+
+ GraphNode::Param conv_params;
+ conv_params.padding.type = neurun::model::PaddingType::SAME;
+ conv_params.stride.horizontal = 1;
+ conv_params.stride.vertical = 1;
+ conv_params.activation = neurun::model::Activation::NONE;
+
+ auto output_operand = model.operands.emplace(shape, type).value();
+ IndexSet outputs{output_operand};
+
+ auto conv = nnfw::cpp14::make_unique<GraphNode>(inputs, outputs, conv_params);
+
+ ASSERT_NE(conv, nullptr);
+ ASSERT_EQ(conv->getInputs().at(Index{0}).value(), inputs.at(0).value());
conv->setInputs({8, 9, 10});
- ASSERT_NE(conv->getInputs().at(Index{0}).asInt(), params[0]);
- ASSERT_EQ(conv->getInputs().at(Index{0}).asInt(), 8);
+ ASSERT_NE(conv->getInputs().at(Index{0}).value(), inputs.at(0).value());
+ ASSERT_EQ(conv->getInputs().at(Index{0}).value(), 8);
}
TEST(graph_operation_setIO, operation_setIO_concat)
{
- neurun::graph::Graph graph;
+ neurun::model::Model model;
+
+ neurun::model::Shape shape{3};
+
+ neurun::model::TypeInfo type{neurun::model::DataType::INT32};
- neurun::model::operand::Shape shape{1u};
- neurun::model::operand::TypeInfo type{ANEURALNETWORKS_TENSOR_INT32, 0, 0};
- shape.dim(0) = 3;
+ using GraphNode = neurun::model::operation::ConcatNode;
// Add Concat
- std::vector<uint32_t> params;
- for (int i = 0; i < 7; ++i)
+ IndexSet inputs;
+ for (int i = 0; i < 6; ++i)
{
- params.emplace_back(graph.addOperand(shape, type).asInt());
+ inputs.append(model.operands.emplace(shape, type));
}
- uint32_t outoperand = graph.addOperand(shape, type).asInt();
- using GraphNode = neurun::model::operation::ConcatNode;
+ GraphNode::Param concat_params{0};
+
+ auto output_operand = model.operands.emplace(shape, type).value();
+ IndexSet outputs{output_operand};
- auto concat =
- nnfw::cpp14::make_unique<GraphNode>(GraphNodeInitParam{7, params.data(), 1, &outoperand});
+ auto concat = nnfw::cpp14::make_unique<GraphNode>(inputs, outputs, concat_params);
+ ASSERT_NE(concat, nullptr);
ASSERT_EQ(concat->getInputs().size(), 6);
- ASSERT_EQ(concat->getInputs().at(Index{0}).asInt(), params[0]);
+ ASSERT_EQ(concat->getInputs().at(Index{0}).value(), inputs.at(0).value());
concat->setInputs({80, 6, 9, 11});
ASSERT_EQ(concat->getInputs().size(), 4);
- ASSERT_NE(concat->getInputs().at(Index{0}).asInt(), params[0]);
- ASSERT_EQ(concat->getInputs().at(Index{0}).asInt(), 80);
- ASSERT_EQ(concat->getInputs().at(Index{2}).asInt(), 9);
+ ASSERT_NE(concat->getInputs().at(Index{0}).value(), inputs.at(0).value());
+ ASSERT_EQ(concat->getInputs().at(Index{0}).value(), 80);
+ ASSERT_EQ(concat->getInputs().at(Index{2}).value(), 9);
ASSERT_THROW(concat->getInputs().at(Index{5}), std::out_of_range);
}