Add gtest for mul op to test 4D tensors (#3452)
authorShubham Gupta/System SW /SRI-Bangalore/Engineer/삼성전자 <shub98.gupta@samsung.com>
Wed, 14 Nov 2018 04:47:09 +0000 (10:17 +0530)
committer오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Wed, 14 Nov 2018 04:47:09 +0000 (13:47 +0900)
This patch will add gtest to test mul op for 4D tensors

Signed-off-by: shubham <shub98.gupta@samsung.com>
runtimes/tests/neural_networks_test/generated/all_generated_tests.cpp
runtimes/tests/neural_networks_test/generated/examples/mul_4D_nnfw.example.cpp [new file with mode: 0644]
runtimes/tests/neural_networks_test/generated/models/mul_4D_nnfw.model.cpp [new file with mode: 0644]
runtimes/tests/neural_networks_test/specs/V1_0/mul_4D_nnfw.mod.py [new file with mode: 0644]

index c0a2780..b6d5c82 100644 (file)
@@ -1625,6 +1625,20 @@ TEST_F(GeneratedTests, mobilenet_quantized) {
             mobilenet_quantized::examples);
 }
 
+namespace mul_4D_nnfw {
+std::vector<MixedTypedExample> examples = {
+// Generated mul_4D_nnfw test
+#include "generated/examples/mul_4D_nnfw.example.cpp"
+};
+// Generated model constructor
+#include "generated/models/mul_4D_nnfw.model.cpp"
+} // namespace mul_4D_nnfw
+TEST_F(GeneratedTests, mul_4D_nnfw) {
+    execute(mul_4D_nnfw::CreateModel,
+            mul_4D_nnfw::is_ignored,
+            mul_4D_nnfw::examples);
+}
+
 namespace mul_broadcast_3D_1D_1_nnfw {
 std::vector<MixedTypedExample> examples = {
 // Generated mul_broadcast_3D_1D_1_nnfw test
diff --git a/runtimes/tests/neural_networks_test/generated/examples/mul_4D_nnfw.example.cpp b/runtimes/tests/neural_networks_test/generated/examples/mul_4D_nnfw.example.cpp
new file mode 100644 (file)
index 0000000..9cc4ad7
--- /dev/null
@@ -0,0 +1,22 @@
+// Generated file (from: mul_4D_nnfw.mod.py). Do not edit
+// Begin of an example
+{
+//Input(s)
+{ // See tools/test_generator/include/TestHarness.h:MixedTyped
+  // int -> FLOAT32 map
+  {{0, {1, 2, -3, -4, -15, 6, 23, 8, -1, -2, 3, 4, 10, -6, 7, -2}}, {1, {-1, -2, 3, 4, -5, -6, 7, -8, 1, -2, -3, -4, -5, 6, 7, 8}}},
+  // int -> INT32 map
+  {},
+  // int -> QUANT8_ASYMM map
+  {}
+},
+//Output(s)
+{ // See tools/test_generator/include/TestHarness.h:MixedTyped
+  // int -> FLOAT32 map
+  {{0, {-1, -4, -9, -16, 75, -36, 161, -64, -1, 4, -9, -16, -50, -36, 49, -16}}},
+  // int -> INT32 map
+  {},
+  // int -> QUANT8_ASYMM map
+  {}
+}
+}, // End of an example
diff --git a/runtimes/tests/neural_networks_test/generated/models/mul_4D_nnfw.model.cpp b/runtimes/tests/neural_networks_test/generated/models/mul_4D_nnfw.model.cpp
new file mode 100644 (file)
index 0000000..c131693
--- /dev/null
@@ -0,0 +1,24 @@
+// Generated file (from: mul_4D_nnfw.mod.py). Do not edit
+void CreateModel(Model *model) {
+  OperandType type1(Type::INT32, {});
+  OperandType type0(Type::TENSOR_FLOAT32, {2, 2, 2, 2});
+  // Phase 1, operands
+  auto op1 = model->addOperand(&type0);
+  auto op2 = model->addOperand(&type0);
+  auto act = model->addOperand(&type1);
+  auto op3 = model->addOperand(&type0);
+  // Phase 2, operations
+  static int32_t act_init[] = {0};
+  model->setOperandValue(act, act_init, sizeof(int32_t) * 1);
+  model->addOperation(ANEURALNETWORKS_MUL, {op1, op2, act}, {op3});
+  // Phase 3, inputs and outputs
+  model->identifyInputsAndOutputs(
+    {op1, op2},
+    {op3});
+  assert(model->isValid());
+}
+
+bool is_ignored(int i) {
+  static std::set<int> ignore = {};
+  return ignore.find(i) != ignore.end();
+}
diff --git a/runtimes/tests/neural_networks_test/specs/V1_0/mul_4D_nnfw.mod.py b/runtimes/tests/neural_networks_test/specs/V1_0/mul_4D_nnfw.mod.py
new file mode 100644 (file)
index 0000000..ae01d98
--- /dev/null
@@ -0,0 +1,19 @@
+# model
+model = Model()
+i1 = Input("op1", "TENSOR_FLOAT32", "{2, 2, 2, 2}")
+i2 = Input("op2", "TENSOR_FLOAT32", "{2, 2, 2, 2}")
+act = Int32Scalar("act", 0) # an int32_t scalar fuse_activation
+i3 = Output("op3", "TENSOR_FLOAT32", "{2, 2, 2, 2}")
+model = model.Operation("MUL", i1, i2, act).To(i3)
+
+# Example 1. Input in operand 0,
+input0 = {i1: # input 0
+          [1, 2, -3, -4, -15, 6, 23, 8, -1, -2, 3, 4, 10, -6, 7, -2],
+          i2: # input 1
+          [-1, -2, 3, 4, -5, -6, 7, -8, 1, -2, -3, -4, -5, 6, 7, 8]}
+
+output0 = {i3: # output 0
+           [-1, -4, -9, -16, 75, -36, 161, -64, -1, 4, -9, -16, -50, -36, 49, -16]}
+
+# Instantiate an example
+Example((input0, output0))