IVGCVSW-2850 Fix Circular Dependency Issue
authorSadik Armagan <sadik.armagan@arm.com>
Wed, 20 Mar 2019 12:28:32 +0000 (12:28 +0000)
committerSadik Armagan <sadik.armagan@arm.com>
Wed, 20 Mar 2019 17:54:41 +0000 (17:54 +0000)
 * Create the SerilizationID for fb base layer before creating inputs and connections.

Change-Id: I3dbb18e455c1fe9d7ea0fc11988ea55655ee398f
Signed-off-by: Sadik Armagan <sadik.armagan@arm.com>
src/armnnSerializer/Serializer.cpp
src/armnnSerializer/test/SerializerTests.cpp

index cf67022..a27cbc0 100644 (file)
@@ -787,11 +787,13 @@ void SerializerVisitor::VisitSubtractionLayer(const armnn::IConnectableLayer* la
 fb::Offset<serializer::LayerBase> SerializerVisitor::CreateLayerBase(const IConnectableLayer* layer,
                                                                      const serializer::LayerType layerType)
 {
+    uint32_t fbIndex = GetSerializedId(layer->GetGuid());
+
     std::vector<fb::Offset<serializer::InputSlot>> inputSlots = CreateInputSlots(layer);
     std::vector<fb::Offset<serializer::OutputSlot>> outputSlots = CreateOutputSlots(layer);
 
     return serializer::CreateLayerBase(m_flatBufferBuilder,
-                                       GetSerializedId(layer->GetGuid()),
+                                       fbIndex,
                                        m_flatBufferBuilder.CreateString(layer->GetName()),
                                        layerType,
                                        m_flatBufferBuilder.CreateVector(inputSlots),
index ca15553..f40c02d 100644 (file)
@@ -1993,4 +1993,58 @@ BOOST_AUTO_TEST_CASE(SerializeSubtraction)
     deserializedNetwork->Accept(verifier);
 }
 
+BOOST_AUTO_TEST_CASE(SerializeDeserializeNonLinearNetwork)
+{
+    class ConstantLayerVerifier : public LayerVerifierBase
+    {
+    public:
+        ConstantLayerVerifier(const std::string& layerName,
+                              const std::vector<armnn::TensorInfo>& inputInfos,
+                              const std::vector<armnn::TensorInfo>& outputInfos,
+                              const armnn::ConstTensor& layerInput)
+            : LayerVerifierBase(layerName, inputInfos, outputInfos)
+            , m_LayerInput(layerInput) {}
+
+        void VisitConstantLayer(const armnn::IConnectableLayer* layer,
+                                const armnn::ConstTensor& input,
+                                const char* name) override
+        {
+            VerifyNameAndConnections(layer, name);
+
+            CompareConstTensor(input, m_LayerInput);
+        }
+
+        void VisitAdditionLayer(const armnn::IConnectableLayer* layer, const char* name = nullptr) override {}
+
+    private:
+        armnn::ConstTensor m_LayerInput;
+    };
+
+    const std::string layerName("constant");
+    const armnn::TensorInfo info({ 2, 3 }, armnn::DataType::Float32);
+
+    std::vector<float> constantData = GenerateRandomData<float>(info.GetNumElements());
+    armnn::ConstTensor constTensor(info, constantData);
+
+    armnn::INetworkPtr network(armnn::INetwork::Create());
+    armnn::IConnectableLayer* input = network->AddInputLayer(0);
+    armnn::IConnectableLayer* add = network->AddAdditionLayer();
+    armnn::IConnectableLayer* constant = network->AddConstantLayer(constTensor, layerName.c_str());
+    armnn::IConnectableLayer* output = network->AddOutputLayer(0);
+
+    input->GetOutputSlot(0).Connect(add->GetInputSlot(0));
+    constant->GetOutputSlot(0).Connect(add->GetInputSlot(1));
+    add->GetOutputSlot(0).Connect(output->GetInputSlot(0));
+
+    input->GetOutputSlot(0).SetTensorInfo(info);
+    constant->GetOutputSlot(0).SetTensorInfo(info);
+    add->GetOutputSlot(0).SetTensorInfo(info);
+
+    armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(SerializeNetwork(*network));
+    BOOST_CHECK(deserializedNetwork);
+
+    ConstantLayerVerifier verifier(layerName, {}, {info}, constTensor);
+    deserializedNetwork->Accept(verifier);
+}
+
 BOOST_AUTO_TEST_SUITE_END()