From 15f9c68adef324cd0158cea3d021c0f6bef5eecf Mon Sep 17 00:00:00 2001 From: Keith Davis Date: Fri, 14 Oct 2022 15:50:33 +0100 Subject: MLCE-545 INT8 TFLite model execution abnormal * Add functionality to print output tensors to file in tempdir * UnitTests Signed-off-by: Keith Davis Change-Id: Idfb4c186544187db1fecdfca11c662540f645439 --- .../test/layerTests/DebugTestImpl.cpp | 141 ++++++++++++++------- .../test/layerTests/DebugTestImpl.hpp | 48 ++++--- 2 files changed, 126 insertions(+), 63 deletions(-) (limited to 'src/backends/backendsCommon/test') diff --git a/src/backends/backendsCommon/test/layerTests/DebugTestImpl.cpp b/src/backends/backendsCommon/test/layerTests/DebugTestImpl.cpp index 9226f215aa..fa9a825313 100644 --- a/src/backends/backendsCommon/test/layerTests/DebugTestImpl.cpp +++ b/src/backends/backendsCommon/test/layerTests/DebugTestImpl.cpp @@ -6,15 +6,16 @@ #include "DebugTestImpl.hpp" #include +#include #include - #include #include #include #include +#include namespace { @@ -29,6 +30,8 @@ LayerTestResult DebugTestImpl( std::vector& outputExpectedData, armnn::DebugQueueDescriptor descriptor, const std::string expectedStringOutput, + const std::string& layerName, + bool toFile, const float qScale = 1.0f, const int32_t qOffset = 0) { @@ -65,15 +68,27 @@ LayerTestResult DebugTestImpl( CopyDataToITensorHandle(inputHandle.get(), input.data()); - std::ostringstream oss; - std::streambuf* coutStreambuf = std::cout.rdbuf(); - std::cout.rdbuf(oss.rdbuf()); + if (toFile) + { + fs::path tmpDir = fs::temp_directory_path(); + std::string full_path = tmpDir.generic_string() + "/ArmNNIntermediateLayerOutputs/" + layerName + ".numpy"; - ExecuteWorkload(*workload, memoryManager); + ExecuteWorkload(*workload, memoryManager); - std::cout.rdbuf(coutStreambuf); + armnnUtils::Filesystem::FileContents output = armnnUtils::Filesystem::ReadFileContentsIntoString(full_path); + CHECK((output == expectedStringOutput)); + } + else + { + std::ostringstream oss; + std::streambuf* coutStreambuf = std::cout.rdbuf(); + std::cout.rdbuf(oss.rdbuf()); - CHECK(oss.str() == expectedStringOutput); + ExecuteWorkload(*workload, memoryManager); + + std::cout.rdbuf(coutStreambuf); + CHECK(oss.str() == expectedStringOutput); + } CopyDataFromITensorHandle(actualOutput.data(), outputHandle.get()); @@ -86,7 +101,8 @@ LayerTestResult DebugTestImpl( template > LayerTestResult Debug4dTest( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + bool toFile = false) { armnn::TensorInfo inputTensorInfo; armnn::TensorInfo outputTensorInfo; @@ -98,6 +114,7 @@ LayerTestResult Debug4dTest( desc.m_Guid = 1; desc.m_LayerName = "TestOutput"; desc.m_SlotIndex = 0; + desc.m_LayerOutputToFile = toFile; inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType); outputTensorInfo = armnn::TensorInfo(4, outputShape, ArmnnType); @@ -133,13 +150,16 @@ LayerTestResult Debug4dTest( input, outputExpected, desc, - expectedStringOutput); + expectedStringOutput, + desc.m_LayerName, + toFile); } template > LayerTestResult Debug3dTest( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + bool toFile = false) { armnn::TensorInfo inputTensorInfo; armnn::TensorInfo outputTensorInfo; @@ -151,6 +171,7 @@ LayerTestResult Debug3dTest( desc.m_Guid = 1; desc.m_LayerName = "TestOutput"; desc.m_SlotIndex = 0; + desc.m_LayerOutputToFile = toFile; inputTensorInfo = armnn::TensorInfo(3, inputShape, ArmnnType); outputTensorInfo = armnn::TensorInfo(3, outputShape, ArmnnType); @@ -184,13 +205,16 @@ LayerTestResult Debug3dTest( input, outputExpected, desc, - expectedStringOutput); + expectedStringOutput, + desc.m_LayerName, + toFile); } template > LayerTestResult Debug2dTest( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + bool toFile = false) { armnn::TensorInfo inputTensorInfo; armnn::TensorInfo outputTensorInfo; @@ -202,6 +226,7 @@ LayerTestResult Debug2dTest( desc.m_Guid = 1; desc.m_LayerName = "TestOutput"; desc.m_SlotIndex = 0; + desc.m_LayerOutputToFile = toFile; inputTensorInfo = armnn::TensorInfo(2, inputShape, ArmnnType); outputTensorInfo = armnn::TensorInfo(2, outputShape, ArmnnType); @@ -233,13 +258,16 @@ LayerTestResult Debug2dTest( input, outputExpected, desc, - expectedStringOutput); + expectedStringOutput, + desc.m_LayerName, + toFile); } template > LayerTestResult Debug1dTest( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + bool toFile = false) { armnn::TensorInfo inputTensorInfo; armnn::TensorInfo outputTensorInfo; @@ -251,6 +279,7 @@ LayerTestResult Debug1dTest( desc.m_Guid = 1; desc.m_LayerName = "TestOutput"; desc.m_SlotIndex = 0; + desc.m_LayerOutputToFile = toFile; inputTensorInfo = armnn::TensorInfo(1, inputShape, ArmnnType); outputTensorInfo = armnn::TensorInfo(1, outputShape, ArmnnType); @@ -280,119 +309,137 @@ LayerTestResult Debug1dTest( input, outputExpected, desc, - expectedStringOutput); + expectedStringOutput, + desc.m_LayerName, + toFile); } } // anonymous namespace LayerTestResult Debug4dFloat32Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + bool toFile = false) { - return Debug4dTest(workloadFactory, memoryManager); + return Debug4dTest(workloadFactory, memoryManager, toFile); } LayerTestResult Debug3dFloat32Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + bool toFile = false) { - return Debug3dTest(workloadFactory, memoryManager); + return Debug3dTest(workloadFactory, memoryManager, toFile); } LayerTestResult Debug2dFloat32Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + bool toFile = false) { - return Debug2dTest(workloadFactory, memoryManager); + return Debug2dTest(workloadFactory, memoryManager, toFile); } LayerTestResult Debug1dFloat32Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + bool toFile = false) { - return Debug1dTest(workloadFactory, memoryManager); + return Debug1dTest(workloadFactory, memoryManager, toFile); } LayerTestResult Debug4dBFloat16Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + bool toFile = false) { - return Debug4dTest(workloadFactory, memoryManager); + return Debug4dTest(workloadFactory, memoryManager, toFile); } LayerTestResult Debug3dBFloat16Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + bool toFile = false) { - return Debug3dTest(workloadFactory, memoryManager); + return Debug3dTest(workloadFactory, memoryManager, toFile); } LayerTestResult Debug2dBFloat16Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + bool toFile = false) { - return Debug2dTest(workloadFactory, memoryManager); + return Debug2dTest(workloadFactory, memoryManager, toFile); } LayerTestResult Debug1dBFloat16Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + bool toFile = false) { - return Debug1dTest(workloadFactory, memoryManager); + return Debug1dTest(workloadFactory, memoryManager, toFile); } LayerTestResult Debug4dUint8Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + bool toFile = false) { - return Debug4dTest(workloadFactory, memoryManager); + return Debug4dTest(workloadFactory, memoryManager, toFile); } LayerTestResult Debug3dUint8Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + bool toFile = false) { - return Debug3dTest(workloadFactory, memoryManager); + return Debug3dTest(workloadFactory, memoryManager, toFile); } LayerTestResult Debug2dUint8Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + bool toFile = false) { - return Debug2dTest(workloadFactory, memoryManager); + return Debug2dTest(workloadFactory, memoryManager, toFile); } LayerTestResult Debug1dUint8Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + bool toFile = false) { - return Debug1dTest(workloadFactory, memoryManager); + return Debug1dTest(workloadFactory, memoryManager, toFile); } LayerTestResult Debug4dInt16Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + bool toFile = false) { - return Debug4dTest(workloadFactory, memoryManager); + return Debug4dTest(workloadFactory, memoryManager, toFile); } LayerTestResult Debug3dInt16Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + bool toFile = false) { - return Debug3dTest(workloadFactory, memoryManager); + return Debug3dTest(workloadFactory, memoryManager, toFile); } LayerTestResult Debug2dInt16Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + bool toFile = false) { - return Debug2dTest(workloadFactory, memoryManager); + return Debug2dTest(workloadFactory, memoryManager, toFile); } LayerTestResult Debug1dInt16Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + bool toFile = false) { - return Debug1dTest(workloadFactory, memoryManager); + return Debug1dTest(workloadFactory, memoryManager, toFile); } diff --git a/src/backends/backendsCommon/test/layerTests/DebugTestImpl.hpp b/src/backends/backendsCommon/test/layerTests/DebugTestImpl.hpp index ac068e8939..250c658cbf 100644 --- a/src/backends/backendsCommon/test/layerTests/DebugTestImpl.hpp +++ b/src/backends/backendsCommon/test/layerTests/DebugTestImpl.hpp @@ -14,64 +14,80 @@ LayerTestResult Debug4dFloat32Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + bool toFile); LayerTestResult Debug3dFloat32Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + bool toFile); LayerTestResult Debug2dFloat32Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + bool toFile); LayerTestResult Debug1dFloat32Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + bool toFile); LayerTestResult Debug4dBFloat16Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + bool toFile); LayerTestResult Debug3dBFloat16Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + bool toFile); LayerTestResult Debug2dBFloat16Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + bool toFile); LayerTestResult Debug1dBFloat16Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + bool toFile); LayerTestResult Debug4dUint8Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + bool toFile); LayerTestResult Debug3dUint8Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + bool toFile); LayerTestResult Debug2dUint8Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + bool toFile); LayerTestResult Debug1dUint8Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + bool toFile); LayerTestResult Debug4dInt16Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + bool toFile); LayerTestResult Debug3dInt16Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + bool toFile); LayerTestResult Debug2dInt16Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + bool toFile); LayerTestResult Debug1dInt16Test( armnn::IWorkloadFactory& workloadFactory, - const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager); + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + bool toFile); -- cgit v1.2.1