From: janeil01 Date: Thu, 7 Nov 2019 09:47:20 +0000 (+0000) Subject: IVGCVSW-4067 Change LayerGuid to use ProfilingGuid X-Git-Tag: submit/tizen/20200316.035456~63 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3fec1ea7e35420ef87de8a98aed0437570251969;p=platform%2Fupstream%2Farmnn.git 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 --- diff --git a/include/armnn/Types.hpp b/include/armnn/Types.hpp index b2aa52e..3d3ab65 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 dbeda22..1efe7e4 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 8a3d4f2..4b80b02 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 81091bc..5d06958 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 1fd507a..7dfd534 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 1f36cf7..7416ff6 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 dfb8c7f..253fb76 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 b45a171..6a96a4a 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 594fd45..67c3e2c 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"); }