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 --- src/backends/reference/workloads/Debug.cpp | 110 +++++++++++++-------- src/backends/reference/workloads/Debug.hpp | 4 +- .../reference/workloads/RefDebugWorkload.cpp | 2 +- 3 files changed, 74 insertions(+), 42 deletions(-) (limited to 'src/backends/reference/workloads') diff --git a/src/backends/reference/workloads/Debug.cpp b/src/backends/reference/workloads/Debug.cpp index 24000d45e6..fdadfef590 100644 --- a/src/backends/reference/workloads/Debug.cpp +++ b/src/backends/reference/workloads/Debug.cpp @@ -5,22 +5,27 @@ #include "Debug.hpp" #include +#include #include #include #include #include +#include +#include +#include namespace armnn { -template -void Debug(const TensorInfo& inputInfo, - const T* inputData, - LayerGuid guid, - const std::string& layerName, - unsigned int slotIndex) +template +void PrintOutput(const TensorInfo& inputInfo, + const T* inputData, + LayerGuid guid, + const std::string& layerName, + unsigned int slotIndex, + std::ostream& os) { const unsigned int numDims = inputInfo.GetNumDimensions(); const unsigned int numElements = inputInfo.GetNumElements(); @@ -34,30 +39,30 @@ void Debug(const TensorInfo& inputInfo, strides[numDims - i] = strides[numDims - i + 1] * inputShape[numDims - i]; } - std::cout << "{ "; - std::cout << "\"layerGuid\": " << guid << ", "; - std::cout << "\"layerName\": \"" << layerName << "\", "; - std::cout << "\"outputSlot\": " << slotIndex << ", "; - std::cout << "\"shape\": "; + os << "{ "; + os << "\"layerGuid\": " << guid << ", "; + os << "\"layerName\": \"" << layerName << "\", "; + os << "\"outputSlot\": " << slotIndex << ", "; + os << "\"shape\": "; - std::cout << "["; + os << "["; for (unsigned int i = 0; i < numDims; i++) { - std::cout << inputShape[i]; + os << inputShape[i]; if (i != numDims - 1) { - std::cout << ", "; + os << ", "; } } - std::cout << "], "; + os << "], "; - std::cout << "\"min\": " - << static_cast(*std::min_element(inputData, inputData + numElements)) << ", "; + os << "\"min\": " + << static_cast(*std::min_element(inputData, inputData + numElements)) << ", "; - std::cout << "\"max\": " - << static_cast(*std::max_element(inputData, inputData + numElements)) << ", "; + os << "\"max\": " + << static_cast(*std::max_element(inputData, inputData + numElements)) << ", "; - std::cout << "\"data\": "; + os << "\"data\": "; for (unsigned int i = 0; i < numElements; i++) { @@ -65,69 +70,96 @@ void Debug(const TensorInfo& inputInfo, { if (i % strides[j] == 0) { - std::cout << "[" ; + os << "["; } } - std::cout << static_cast(inputData[i]); + os << static_cast(inputData[i]); for (unsigned int j = 0; j < numDims; j++) { - if ((i+1) % strides[j] == 0) + if ((i + 1) % strides[j] == 0) { - std::cout << "]" ; + os << "]"; } } if (i != numElements - 1) { - std::cout << ", "; + os << ", "; } } - std::cout << " }" << std::endl; + os << " }" << std::endl; +} + +template +void Debug(const TensorInfo& inputInfo, + const T* inputData, + LayerGuid guid, + const std::string& layerName, + unsigned int slotIndex, + bool outputsToFile) +{ + if (outputsToFile) + { + auto rootPathToFile = armnnUtils::Filesystem::CreateDirectory("/ArmNNIntermediateLayerOutputs"); + std::ofstream out(rootPathToFile + layerName + ".numpy"); + PrintOutput(inputInfo, inputData, guid, layerName, slotIndex, out); + } + else + { + PrintOutput(inputInfo, inputData, guid, layerName, slotIndex, std::cout); + } } template void Debug(const TensorInfo& inputInfo, - const BFloat16* inputData, - LayerGuid guid, - const std::string& layerName, - unsigned int slotIndex); + const BFloat16* inputData, + LayerGuid guid, + const std::string& layerName, + unsigned int slotIndex, + bool outputsToFile); template void Debug(const TensorInfo& inputInfo, const Half* inputData, LayerGuid guid, const std::string& layerName, - unsigned int slotIndex); + unsigned int slotIndex, + bool outputsToFile); template void Debug(const TensorInfo& inputInfo, const float* inputData, LayerGuid guid, const std::string& layerName, - unsigned int slotIndex); + unsigned int slotIndex, + bool outputsToFile); template void Debug(const TensorInfo& inputInfo, const uint8_t* inputData, LayerGuid guid, const std::string& layerName, - unsigned int slotIndex); + unsigned int slotIndex, + bool outputsToFile); template void Debug(const TensorInfo& inputInfo, - const int8_t* inputData, - LayerGuid guid, - const std::string& layerName, - unsigned int slotIndex); + const int8_t* inputData, + LayerGuid guid, + const std::string& layerName, + unsigned int slotIndex, + bool outputsToFile); template void Debug(const TensorInfo& inputInfo, const int16_t* inputData, LayerGuid guid, const std::string& layerName, - unsigned int slotIndex); + unsigned int slotIndex, + bool outputsToFile); template void Debug(const TensorInfo& inputInfo, const int32_t* inputData, LayerGuid guid, const std::string& layerName, - unsigned int slotIndex); + unsigned int slotIndex, + bool outputsToFile); } // namespace armnn diff --git a/src/backends/reference/workloads/Debug.hpp b/src/backends/reference/workloads/Debug.hpp index 3f9920c543..a8802d1524 100644 --- a/src/backends/reference/workloads/Debug.hpp +++ b/src/backends/reference/workloads/Debug.hpp @@ -8,12 +8,12 @@ namespace armnn { - template void Debug(const TensorInfo& inputInfo, const T* inputData, LayerGuid guid, const std::string& layerName, - unsigned int slotIndex); + unsigned int slotIndex, + bool outputsToFile); } //namespace armnn diff --git a/src/backends/reference/workloads/RefDebugWorkload.cpp b/src/backends/reference/workloads/RefDebugWorkload.cpp index 48b519f809..db67b3a782 100644 --- a/src/backends/reference/workloads/RefDebugWorkload.cpp +++ b/src/backends/reference/workloads/RefDebugWorkload.cpp @@ -45,7 +45,7 @@ void RefDebugWorkload::Execute(std::vector inputs) con } else { - Debug(inputInfo, inputData, m_Data.m_Guid, m_Data.m_LayerName, m_Data.m_SlotIndex); + Debug(inputInfo, inputData, m_Data.m_Guid, m_Data.m_LayerName, m_Data.m_SlotIndex, m_Data.m_LayerOutputToFile); } std::memcpy(outputData, inputData, inputInfo.GetNumElements()*sizeof(T)); -- cgit v1.2.1