diff options
author | Keith Davis <keith.davis@arm.com> | 2022-10-14 15:50:33 +0100 |
---|---|---|
committer | KeithARM <keith.davis@arm.com> | 2022-10-19 10:33:40 +0000 |
commit | 15f9c68adef324cd0158cea3d021c0f6bef5eecf (patch) | |
tree | 1cd48b345d182fd19efdc40a32e2540befd8f925 /src/armnn | |
parent | 7bbf56598010041ea46c3fa9d32604db777ee26e (diff) | |
download | armnn-15f9c68adef324cd0158cea3d021c0f6bef5eecf.tar.gz |
MLCE-545 INT8 TFLite model execution abnormal
* Add functionality to print output tensors to file in tempdir
* UnitTests
Signed-off-by: Keith Davis <keith.davis@arm.com>
Change-Id: Idfb4c186544187db1fecdfca11c662540f645439
Diffstat (limited to 'src/armnn')
-rw-r--r-- | src/armnn/Network.cpp | 6 | ||||
-rw-r--r-- | src/armnn/NetworkUtils.cpp | 4 | ||||
-rw-r--r-- | src/armnn/NetworkUtils.hpp | 2 | ||||
-rw-r--r-- | src/armnn/layers/DebugLayer.cpp | 9 | ||||
-rw-r--r-- | src/armnn/layers/DebugLayer.hpp | 4 | ||||
-rw-r--r-- | src/armnn/optimizations/AddDebug.hpp | 22 |
6 files changed, 41 insertions, 6 deletions
diff --git a/src/armnn/Network.cpp b/src/armnn/Network.cpp index 1b1815f73d..bb6eb19fa3 100644 --- a/src/armnn/Network.cpp +++ b/src/armnn/Network.cpp @@ -1810,10 +1810,14 @@ IOptimizedNetworkPtr Optimize(const Graph& inGraph, // This must occur after all topological changes to the graph and any redirection of variables // If the debug flag is set, then insert a DebugLayer after each layer // Doing this after applying the backend optimizations as they might have changed some layers - if (options.m_Debug) + if (options.m_Debug && !options.m_DebugToFile) { Optimizer::Pass(optGraph, MakeOptimizations(InsertDebugLayer())); } + else if (options.m_DebugToFile) + { + Optimizer::Pass(optGraph, MakeOptimizations(InsertDebugToFileLayer())); + } // Calculate the compatibility strategies for tensor handles OptimizationResult strategyResult = SelectTensorHandleStrategy(optGraph, diff --git a/src/armnn/NetworkUtils.cpp b/src/armnn/NetworkUtils.cpp index 5ff0e6c4e1..aaee4eba1a 100644 --- a/src/armnn/NetworkUtils.cpp +++ b/src/armnn/NetworkUtils.cpp @@ -242,7 +242,7 @@ std::vector<ConvertFp32ToFp16Layer*> InsertConvertFp32ToFp16LayersAfter(Graph& g return convertLayers; } -std::vector<DebugLayer*> InsertDebugLayerAfter(Graph& graph, Layer& layer) +std::vector<DebugLayer*> InsertDebugLayerAfter(Graph& graph, Layer& layer, bool toFile) { std::vector<DebugLayer*> debugLayers; debugLayers.reserve(layer.GetNumOutputSlots()); @@ -255,7 +255,7 @@ std::vector<DebugLayer*> InsertDebugLayerAfter(Graph& graph, Layer& layer) std::to_string(outputSlotIdx); DebugLayer* debugLayer = - graph.InsertNewLayer<DebugLayer>(*outputSlot, debugName.c_str()); + graph.InsertNewLayer<DebugLayer>(*outputSlot, debugName.c_str(), toFile); // Sets output tensor info for the debug layer. ARMNN_ASSERT(debugLayer->GetInputSlot(0).GetConnectedOutputSlot() == &(*outputSlot)); diff --git a/src/armnn/NetworkUtils.hpp b/src/armnn/NetworkUtils.hpp index 77dd068cb3..38e0aabaf9 100644 --- a/src/armnn/NetworkUtils.hpp +++ b/src/armnn/NetworkUtils.hpp @@ -27,7 +27,7 @@ std::vector<ConvertFp16ToFp32Layer*> InsertConvertFp16ToFp32LayersBefore(Graph& std::vector<ConvertFp32ToFp16Layer*> InsertConvertFp32ToFp16LayersAfter(Graph& graph, Layer& layer); -std::vector<DebugLayer*> InsertDebugLayerAfter(Graph& graph, Layer& layer); +std::vector<DebugLayer*> InsertDebugLayerAfter(Graph& graph, Layer& layer, bool toFile); bool RevertConstantWeightsToFP32(Layer* layer); diff --git a/src/armnn/layers/DebugLayer.cpp b/src/armnn/layers/DebugLayer.cpp index 8342c530b2..e1c8572c95 100644 --- a/src/armnn/layers/DebugLayer.cpp +++ b/src/armnn/layers/DebugLayer.cpp @@ -13,7 +13,13 @@ namespace armnn { DebugLayer::DebugLayer(const char* name) - : Layer(1, 1, LayerType::Debug, name) + : Layer(1, 1, LayerType::Debug, name), + m_ToFile(false) +{} + +DebugLayer::DebugLayer(const char* name, bool toFile) + : Layer(1, 1, LayerType::Debug, name), + m_ToFile(toFile) {} std::unique_ptr<IWorkload> DebugLayer::CreateWorkload(const IWorkloadFactory& factory) const @@ -24,6 +30,7 @@ std::unique_ptr<IWorkload> DebugLayer::CreateWorkload(const IWorkloadFactory& fa descriptor.m_Guid = prevLayer.GetGuid(); descriptor.m_LayerName = prevLayer.GetNameStr(); descriptor.m_SlotIndex = GetInputSlot(0).GetConnectedOutputSlot()->CalculateIndexOnOwner(); + descriptor.m_LayerOutputToFile = m_ToFile; SetAdditionalInfo(descriptor); diff --git a/src/armnn/layers/DebugLayer.hpp b/src/armnn/layers/DebugLayer.hpp index fe7ad5c9e5..662195d7bc 100644 --- a/src/armnn/layers/DebugLayer.hpp +++ b/src/armnn/layers/DebugLayer.hpp @@ -34,9 +34,13 @@ protected: /// Constructor to create a DebugLayer. /// @param [in] name Optional name for the layer. DebugLayer(const char* name); + DebugLayer(const char* name, bool toFile); /// Default destructor ~DebugLayer() = default; + +private: + bool m_ToFile; }; } // namespace armnn diff --git a/src/armnn/optimizations/AddDebug.hpp b/src/armnn/optimizations/AddDebug.hpp index 60271b0d77..e0c79ae53f 100644 --- a/src/armnn/optimizations/AddDebug.hpp +++ b/src/armnn/optimizations/AddDebug.hpp @@ -22,7 +22,7 @@ public: { // if the inputs/outputs of this layer do not have a debug layer // insert the debug layer after them - InsertDebugLayerAfter(graph, layer); + InsertDebugLayerAfter(graph, layer, false); } } @@ -31,7 +31,27 @@ protected: ~AddDebugImpl() = default; }; +class AddDebugToFileImpl +{ +public: + + void Run(Graph& graph, Layer& layer) const + { + if (layer.GetType() != LayerType::Debug && layer.GetType() != LayerType::Output) + { + // if the inputs/outputs of this layer do not have a debug layer + // insert the debug layer after them + InsertDebugLayerAfter(graph, layer, true); + } + } + +protected: + AddDebugToFileImpl() = default; + ~AddDebugToFileImpl() = default; +}; + using InsertDebugLayer = OptimizeForType<Layer, AddDebugImpl>; +using InsertDebugToFileLayer = OptimizeForType<Layer, AddDebugToFileImpl>; } // namespace optimizations } // namespace armnn |