IVGCVSW-2688 Add Serializer and Deserializer for Equal

Change-Id: If613f4394e161483eea4930dab2afba74c5e26fd
Signed-off-by: Nattapat Chaimanowong <nattapat.chaimanowong@arm.com>
diff --git a/src/armnnDeserializer/Deserializer.cpp b/src/armnnDeserializer/Deserializer.cpp
index 28c6c94..317269e 100644
--- a/src/armnnDeserializer/Deserializer.cpp
+++ b/src/armnnDeserializer/Deserializer.cpp
@@ -192,6 +192,7 @@
     m_ParserFunctions[Layer_Convolution2dLayer]          = &Deserializer::ParseConvolution2d;
     m_ParserFunctions[Layer_DepthwiseConvolution2dLayer] = &Deserializer::ParseDepthwiseConvolution2d;
     m_ParserFunctions[Layer_DivisionLayer]               = &Deserializer::ParseDivision;
+    m_ParserFunctions[Layer_EqualLayer]                  = &Deserializer::ParseEqual;
     m_ParserFunctions[Layer_FullyConnectedLayer]         = &Deserializer::ParseFullyConnected;
     m_ParserFunctions[Layer_MinimumLayer]                = &Deserializer::ParseMinimum;
     m_ParserFunctions[Layer_MultiplicationLayer]         = &Deserializer::ParseMultiplication;
@@ -222,6 +223,8 @@
             return graphPtr->layers()->Get(layerIndex)->layer_as_DepthwiseConvolution2dLayer()->base();
         case Layer::Layer_DivisionLayer:
             return graphPtr->layers()->Get(layerIndex)->layer_as_DivisionLayer()->base();
+        case Layer::Layer_EqualLayer:
+            return graphPtr->layers()->Get(layerIndex)->layer_as_EqualLayer()->base();
         case Layer::Layer_FullyConnectedLayer:
             return graphPtr->layers()->Get(layerIndex)->layer_as_FullyConnectedLayer()->base();
         case Layer::Layer_InputLayer:
@@ -958,6 +961,26 @@
     RegisterOutputSlots(graph, layerIndex, layer);
 }
 
+void Deserializer::ParseEqual(GraphPtr graph, unsigned int layerIndex)
+{
+    CHECK_LAYERS(graph, 0, layerIndex);
+    auto inputs = GetInputs(graph, layerIndex);
+    CHECK_LOCATION();
+    CHECK_VALID_SIZE(inputs.size(), 2);
+
+    auto outputs = GetOutputs(graph, layerIndex);
+    CHECK_VALID_SIZE(outputs.size(), 1);
+
+    auto layerName = GetLayerName(graph, layerIndex);
+    IConnectableLayer* layer = m_Network->AddEqualLayer(layerName.c_str());
+
+    armnn::TensorInfo outputTensorInfo = ToTensorInfo(outputs[0]);
+    layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
+
+    RegisterInputSlots(graph, layerIndex, layer);
+    RegisterOutputSlots(graph, layerIndex, layer);
+}
+
 void Deserializer::ParseMinimum(GraphPtr graph, unsigned int layerIndex)
 {
     CHECK_LAYERS(graph, 0, layerIndex);
diff --git a/src/armnnDeserializer/Deserializer.hpp b/src/armnnDeserializer/Deserializer.hpp
index 657c7f5..e75ab1c 100644
--- a/src/armnnDeserializer/Deserializer.hpp
+++ b/src/armnnDeserializer/Deserializer.hpp
@@ -75,6 +75,7 @@
     void ParseConvolution2d(GraphPtr graph, unsigned int layerIndex);
     void ParseDepthwiseConvolution2d(GraphPtr graph, unsigned int layerIndex);
     void ParseDivision(GraphPtr graph, unsigned int layerIndex);
+    void ParseEqual(GraphPtr graph, unsigned int layerIndex);
     void ParseFullyConnected(GraphPtr graph, unsigned int layerIndex);
     void ParseMinimum(GraphPtr graph, unsigned int layerIndex);
     void ParseMultiplication(GraphPtr graph, unsigned int layerIndex);
diff --git a/src/armnnDeserializer/DeserializerSupport.md b/src/armnnDeserializer/DeserializerSupport.md
index 8fd7b42..7910683 100644
--- a/src/armnnDeserializer/DeserializerSupport.md
+++ b/src/armnnDeserializer/DeserializerSupport.md
@@ -13,6 +13,7 @@
 * Convolution2d
 * DepthwiseConvolution2d
 * Division
+* Equal
 * FullyConnected
 * Minimum
 * Multiplication
diff --git a/src/armnnDeserializer/test/DeserializeEqual.cpp b/src/armnnDeserializer/test/DeserializeEqual.cpp
new file mode 100644
index 0000000..7d8213c
--- /dev/null
+++ b/src/armnnDeserializer/test/DeserializeEqual.cpp
@@ -0,0 +1,148 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include <boost/test/unit_test.hpp>
+#include "ParserFlatbuffersSerializeFixture.hpp"
+#include "../Deserializer.hpp"
+
+#include <string>
+#include <iostream>
+
+BOOST_AUTO_TEST_SUITE(Deserializer)
+
+struct EqualFixture : public ParserFlatbuffersSerializeFixture
+{
+    explicit EqualFixture(const std::string & inputShape1,
+                          const std::string & inputShape2,
+                          const std::string & outputShape,
+                          const std::string & dataType)
+    {
+        m_JsonString = R"(
+            {
+                inputIds: [0, 1],
+                outputIds: [3],
+                layers: [
+                    {
+                        layer_type: "InputLayer",
+                        layer: {
+                            base: {
+                                layerBindingId: 0,
+                                base: {
+                                    index: 0,
+                                    layerName: "InputLayer1",
+                                    layerType: "Input",
+                                    inputSlots: [{
+                                        index: 0,
+                                        connection: {sourceLayerIndex:0, outputSlotIndex:0 },
+                                    }],
+                                    outputSlots: [{
+                                        index: 0,
+                                        tensorInfo: {
+                                            dimensions: )" + inputShape1 + R"(,
+                                            dataType: )" + dataType + R"(
+                                        },
+                                    }],
+                                },
+                            }
+                        },
+                    },
+                    {
+                        layer_type: "InputLayer",
+                        layer: {
+                            base: {
+                                layerBindingId: 1,
+                                base: {
+                                      index:1,
+                                      layerName: "InputLayer2",
+                                      layerType: "Input",
+                                      inputSlots: [{
+                                          index: 0,
+                                          connection: {sourceLayerIndex:0, outputSlotIndex:0 },
+                                      }],
+                                      outputSlots: [{
+                                          index: 0,
+                                          tensorInfo: {
+                                              dimensions: )" + inputShape2 + R"(,
+                                              dataType: )" + dataType + R"(
+                                          },
+                                      }],
+                                },
+                            }
+                        },
+                    },
+                    {
+                        layer_type: "EqualLayer",
+                        layer: {
+                            base: {
+                                 index:2,
+                                 layerName: "EqualLayer",
+                                 layerType: "Equal",
+                                 inputSlots: [{
+                                     index: 0,
+                                     connection: {sourceLayerIndex:0, outputSlotIndex:0 },
+                                 },
+                                 {
+                                     index: 1,
+                                     connection: {sourceLayerIndex:1, outputSlotIndex:0 },
+                                 }],
+                                 outputSlots: [{
+                                     index: 0,
+                                     tensorInfo: {
+                                         dimensions: )" + outputShape + R"(,
+                                         dataType: Boolean
+                                     },
+                                 }],
+                            }
+                        },
+                    },
+                    {
+                        layer_type: "OutputLayer",
+                        layer: {
+                            base:{
+                                layerBindingId: 0,
+                                base: {
+                                    index: 3,
+                                    layerName: "OutputLayer",
+                                    layerType: "Output",
+                                    inputSlots: [{
+                                        index: 0,
+                                        connection: {sourceLayerIndex:2, outputSlotIndex:0 },
+                                    }],
+                                    outputSlots: [{
+                                        index: 0,
+                                        tensorInfo: {
+                                            dimensions: )" + outputShape + R"(,
+                                            dataType: Boolean
+                                        },
+                                    }],
+                                }
+                            }
+                        },
+                    }
+                ]
+            }
+        )";
+        Setup();
+    }
+};
+
+struct SimpleEqualFixture : EqualFixture
+{
+    SimpleEqualFixture() : EqualFixture("[ 2, 2, 2, 1 ]",
+                                        "[ 2, 2, 2, 1 ]",
+                                        "[ 2, 2, 2, 1 ]",
+                                        "QuantisedAsymm8") {}
+};
+
+BOOST_FIXTURE_TEST_CASE(EqualQuantisedAsymm8, SimpleEqualFixture)
+{
+  RunTest<4, armnn::DataType::QuantisedAsymm8, armnn::DataType::Boolean>(
+      0,
+      {{"InputLayer1", { 0, 1, 2, 3, 4, 5, 6, 7 }},
+       {"InputLayer2", { 0, 0, 0, 3, 0, 0, 6, 7 }}},
+      {{"OutputLayer", { 1, 0, 0, 1, 0, 0, 1, 1 }}});
+}
+
+BOOST_AUTO_TEST_SUITE_END()