From 500c5f8e9786e2cde2d0dc4ac7994662de6e94a0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Shubham=20Gupta/System=20SW=20/SRI-Bangalore/Engineer/?= =?utf8?q?=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Wed, 14 Nov 2018 10:17:09 +0530 Subject: [PATCH] Add gtest for mul op to test 4D tensors (#3452) This patch will add gtest to test mul op for 4D tensors Signed-off-by: shubham --- .../generated/all_generated_tests.cpp | 14 +++++++++++++ .../generated/examples/mul_4D_nnfw.example.cpp | 22 ++++++++++++++++++++ .../generated/models/mul_4D_nnfw.model.cpp | 24 ++++++++++++++++++++++ .../specs/V1_0/mul_4D_nnfw.mod.py | 19 +++++++++++++++++ 4 files changed, 79 insertions(+) create mode 100644 runtimes/tests/neural_networks_test/generated/examples/mul_4D_nnfw.example.cpp create mode 100644 runtimes/tests/neural_networks_test/generated/models/mul_4D_nnfw.model.cpp create mode 100644 runtimes/tests/neural_networks_test/specs/V1_0/mul_4D_nnfw.mod.py diff --git a/runtimes/tests/neural_networks_test/generated/all_generated_tests.cpp b/runtimes/tests/neural_networks_test/generated/all_generated_tests.cpp index c0a2780..b6d5c82 100644 --- a/runtimes/tests/neural_networks_test/generated/all_generated_tests.cpp +++ b/runtimes/tests/neural_networks_test/generated/all_generated_tests.cpp @@ -1625,6 +1625,20 @@ TEST_F(GeneratedTests, mobilenet_quantized) { mobilenet_quantized::examples); } +namespace mul_4D_nnfw { +std::vector 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 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 index 0000000..9cc4ad7 --- /dev/null +++ b/runtimes/tests/neural_networks_test/generated/examples/mul_4D_nnfw.example.cpp @@ -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 index 0000000..c131693 --- /dev/null +++ b/runtimes/tests/neural_networks_test/generated/models/mul_4D_nnfw.model.cpp @@ -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 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 index 0000000..ae01d98 --- /dev/null +++ b/runtimes/tests/neural_networks_test/specs/V1_0/mul_4D_nnfw.mod.py @@ -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)) -- 2.7.4