From 3fec1ea7e35420ef87de8a98aed0437570251969 Mon Sep 17 00:00:00 2001 From: janeil01 Date: Thu, 7 Nov 2019 09:47:20 +0000 Subject: IVGCVSW-4067 Change LayerGuid to use ProfilingGuid * Refactoring to enable ProfilingGuid * Add profiling includes to Android.mk Signed-off-by: Jan Eilers Change-Id: Ieb25e15e3dc302eb42817d824ad8411ac76dcfe8 --- include/armnn/Types.hpp | 6 ++++-- src/armnn/Layer.cpp | 12 ++---------- src/armnn/QuantizerVisitor.cpp | 4 ++-- src/armnnSerializer/Serializer.cpp | 15 +++++++-------- src/armnnSerializer/Serializer.hpp | 18 ++++++++++-------- src/armnnUtils/DotSerializer.cpp | 4 ++-- src/armnnUtils/DotSerializer.hpp | 6 ++++-- src/backends/backendsCommon/WorkloadData.hpp | 2 ++ .../backendsCommon/test/OptimizationViewsTests.cpp | 4 ++-- 9 files changed, 35 insertions(+), 36 deletions(-) diff --git a/include/armnn/Types.hpp b/include/armnn/Types.hpp index b2aa52edb2..3d3ab65c4a 100644 --- a/include/armnn/Types.hpp +++ b/include/armnn/Types.hpp @@ -209,8 +209,10 @@ private: SizeType m_NumDimMappings; }; +namespace profiling { class ProfilingGuid; } + /// Define LayerGuid type. -using LayerGuid = unsigned int; +using LayerGuid = profiling::ProfilingGuid; class ITensorHandle; @@ -312,4 +314,4 @@ struct hash return hash()(uint64_t(guid)); } }; -} +} // namespace std diff --git a/src/armnn/Layer.cpp b/src/armnn/Layer.cpp index dbeda22ca0..1efe7e412f 100644 --- a/src/armnn/Layer.cpp +++ b/src/armnn/Layer.cpp @@ -5,6 +5,7 @@ #include "Layer.hpp" #include "Graph.hpp" +#include #include #include @@ -184,15 +185,6 @@ EdgeStrategy OutputSlot::GetEdgeStrategyForConnection(unsigned int connectionIdx return m_EdgeStrategies[connectionIdx]; } -namespace { -LayerGuid GenerateLayerGuid() -{ - // Note: Not thread safe. - static LayerGuid newGuid=0; - return newGuid++; -} -} // namespace - Layer::Layer(unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, @@ -202,7 +194,7 @@ Layer::Layer(unsigned int numInputSlots, , m_LayerName(name ? name : "") , m_Type(type) , m_BackendId() -, m_Guid(GenerateLayerGuid()) +, m_Guid(profiling::ProfilingService::Instance().NextGuid()) { m_InputSlots.reserve(numInputSlots); for (unsigned int i = 0; i < numInputSlots; ++i) diff --git a/src/armnn/QuantizerVisitor.cpp b/src/armnn/QuantizerVisitor.cpp index 8a3d4f2990..4b80b02e34 100644 --- a/src/armnn/QuantizerVisitor.cpp +++ b/src/armnn/QuantizerVisitor.cpp @@ -109,8 +109,8 @@ ConstTensor QuantizerVisitor::CreateQuantizedBias(const IConnectableLayer* srcLa void QuantizerVisitor::RecordLayer(const IConnectableLayer* srcLayer, IConnectableLayer* quantizedLayer) { - m_OriginalToQuantizedGuidMap[srcLayer->GetGuid()] = quantizedLayer->GetGuid(); - m_QuantizedGuidToLayerMap[quantizedLayer->GetGuid()] = quantizedLayer; + m_OriginalToQuantizedGuidMap.insert(std::make_pair(srcLayer->GetGuid(), quantizedLayer->GetGuid())); + m_QuantizedGuidToLayerMap.insert(std::make_pair(quantizedLayer->GetGuid(), quantizedLayer)); } void QuantizerVisitor::VisitAbsLayer(const IConnectableLayer* layer, const char* name) diff --git a/src/armnnSerializer/Serializer.cpp b/src/armnnSerializer/Serializer.cpp index 81091bca85..5d06958054 100644 --- a/src/armnnSerializer/Serializer.cpp +++ b/src/armnnSerializer/Serializer.cpp @@ -61,18 +61,17 @@ serializer::ArgMinMaxFunction GetFlatBufferArgMinMaxFunction(armnn::ArgMinMaxFun } } -uint32_t SerializerVisitor::GetSerializedId(unsigned int guid) +uint32_t SerializerVisitor::GetSerializedId(armnn::LayerGuid guid) { - std::pair guidPair(guid, m_layerId); - if (m_guidMap.empty()) { - m_guidMap.insert(guidPair); + m_guidMap.insert(std::make_pair(guid, m_layerId)); } else if (m_guidMap.find(guid) == m_guidMap.end()) { - guidPair.second = ++m_layerId; - m_guidMap.insert(guidPair); + ++m_layerId; + m_guidMap.insert(std::make_pair(guid, m_layerId)); + return m_layerId; } return m_guidMap[guid]; @@ -88,7 +87,7 @@ void SerializerVisitor::VisitInputLayer(const armnn::IConnectableLayer* layer, L auto flatBufferInputBindableBaseLayer = serializer::CreateBindableLayerBase(m_flatBufferBuilder, flatBufferInputBaseLayer, id); - // Push layer Guid to outputIds. + // Push layer index to outputIds. m_inputIds.push_back(GetSerializedId(layer->GetGuid())); // Create the FlatBuffer InputLayer @@ -108,7 +107,7 @@ void SerializerVisitor::VisitOutputLayer(const armnn::IConnectableLayer* layer, auto flatBufferOutputBindableBaseLayer = serializer::CreateBindableLayerBase(m_flatBufferBuilder, flatBufferOutputBaseLayer, id); - // Push layer Guid to outputIds. + // Push layer index to outputIds. m_outputIds.push_back(GetSerializedId(layer->GetGuid())); // Create the FlatBuffer OutputLayer diff --git a/src/armnnSerializer/Serializer.hpp b/src/armnnSerializer/Serializer.hpp index 1fd507af80..7dfd534081 100644 --- a/src/armnnSerializer/Serializer.hpp +++ b/src/armnnSerializer/Serializer.hpp @@ -13,6 +13,8 @@ #include +#include + namespace armnnSerializer { @@ -27,12 +29,12 @@ public: return m_flatBufferBuilder; } - std::vector& GetInputIds() + std::vector& GetInputIds() { return m_inputIds; } - std::vector& GetOutputIds() + std::vector& GetOutputIds() { return m_outputIds; } @@ -277,7 +279,7 @@ private: flatbuffers::Offset> CreateDataVector(const void* memory, unsigned int size); ///Function which maps Guid to an index - uint32_t GetSerializedId(unsigned int guid); + uint32_t GetSerializedId(armnn::LayerGuid guid); /// Creates the serializer InputSlots for the layer. std::vector> CreateInputSlots( @@ -293,14 +295,14 @@ private: /// AnyLayers required by the SerializedGraph. std::vector> m_serializedLayers; - /// Guids of all Input Layers required by the SerializedGraph. - std::vector m_inputIds; + /// Vector of indexes of all Input Layers required by the SerializedGraph. + std::vector m_inputIds; - /// Guids of all Output Layers required by the SerializedGraph. - std::vector m_outputIds; + /// Vector of indexes of all Output Layers required by the SerializedGraph. + std::vector m_outputIds; /// Mapped Guids of all Layers to match our index. - std::unordered_map m_guidMap; + std::unordered_map m_guidMap; /// layer within our FlatBuffer index. uint32_t m_layerId; diff --git a/src/armnnUtils/DotSerializer.cpp b/src/armnnUtils/DotSerializer.cpp index 1f36cf73ae..7416ff6bdf 100644 --- a/src/armnnUtils/DotSerializer.cpp +++ b/src/armnnUtils/DotSerializer.cpp @@ -116,7 +116,7 @@ DotAttributeSet & DotAttributeSet::AddAttribute(const std::string& name, const s return *this; } -DotEdge::DotEdge(std::ostream& stream, unsigned int fromNodeId, unsigned int toNodeId) +DotEdge::DotEdge(std::ostream& stream, LayerGuid fromNodeId, LayerGuid toNodeId) : DotBase(stream) { std::stringstream ss; @@ -176,7 +176,7 @@ NodeContent::~NodeContent() GetStream() << s; } -DotNode::DotNode(std::ostream& stream, unsigned int nodeId, const char* label) +DotNode::DotNode(std::ostream& stream, LayerGuid nodeId, const char* label) : DotBase(stream) { std::stringstream ss; diff --git a/src/armnnUtils/DotSerializer.hpp b/src/armnnUtils/DotSerializer.hpp index dfb8c7f22e..253fb768ec 100644 --- a/src/armnnUtils/DotSerializer.hpp +++ b/src/armnnUtils/DotSerializer.hpp @@ -5,6 +5,8 @@ #pragma once +#include + #include #include #include @@ -75,7 +77,7 @@ private: class DotEdge : public DotBase { public: - explicit DotEdge(std::ostream& stream, unsigned int fromNodeId, unsigned int toNodeId); + explicit DotEdge(std::ostream& stream, LayerGuid fromNodeId, LayerGuid toNodeId); ~DotEdge(); DotAttributeSet& GetAttributeSet() { return *m_Attributes.get(); } @@ -99,7 +101,7 @@ private: class DotNode : public DotBase { public: - explicit DotNode(std::ostream& stream, unsigned int nodeId, const char* label); + explicit DotNode(std::ostream& stream, LayerGuid nodeId, const char* label); ~DotNode(); NodeContent& GetContents() { return *m_Contents.get(); } diff --git a/src/backends/backendsCommon/WorkloadData.hpp b/src/backends/backendsCommon/WorkloadData.hpp index b45a1718f6..6a96a4ad7f 100644 --- a/src/backends/backendsCommon/WorkloadData.hpp +++ b/src/backends/backendsCommon/WorkloadData.hpp @@ -439,6 +439,8 @@ struct GreaterQueueDescriptor : QueueDescriptor struct DebugQueueDescriptor : QueueDescriptor { + DebugQueueDescriptor() : m_Guid(0) {} + void Validate(const WorkloadInfo& workloadInfo) const; LayerGuid m_Guid; diff --git a/src/backends/backendsCommon/test/OptimizationViewsTests.cpp b/src/backends/backendsCommon/test/OptimizationViewsTests.cpp index 594fd450c8..67c3e2c94d 100644 --- a/src/backends/backendsCommon/test/OptimizationViewsTests.cpp +++ b/src/backends/backendsCommon/test/OptimizationViewsTests.cpp @@ -25,11 +25,11 @@ void CheckLayers(Graph& graph) { case LayerType::Input: ++m_inputLayerCount; - if (layer->GetGuid() == 0) + if (layer->GetGuid() == profiling::ProfilingGuid(0)) { BOOST_TEST(layer->GetName() == "inLayer0"); } - else if (layer->GetGuid() == 1) + else if (layer->GetGuid() == profiling::ProfilingGuid(1)) { BOOST_TEST(layer->GetName() == "inLayer1"); } -- cgit v1.2.1