aboutsummaryrefslogtreecommitdiff
path: root/delegate/test/TestUtils.hpp
diff options
context:
space:
mode:
authorMatthew Sloyan <matthew.sloyan@arm.com>2023-03-30 10:12:08 +0100
committerryan.oshea3 <ryan.oshea3@arm.com>2023-04-05 20:36:32 +0000
commitebe392df1635790bf21714549adb97f2f75559e1 (patch)
tree6fb8e56cc755d7c47a62bbe72c54b6ca5445377d /delegate/test/TestUtils.hpp
parentac9607f401dc30003aa97bd179a06d6b8a32139f (diff)
downloadarmnn-ebe392df1635790bf21714549adb97f2f75559e1.tar.gz
IVGCVSW-7562 Implement DelegateTestInterpreter for classic delegate
* Updated all tests to use new DelegateTestInterpreter. * Fixed some unit tests where the shape was incorrect. * Add file identifier to FlatBuffersBuilder, as it is required for validation when creating the model using new API. Signed-off-by: Matthew Sloyan <matthew.sloyan@arm.com> Change-Id: I1c4f5464367b35d4528571fa94d14bfaef18fb4d
Diffstat (limited to 'delegate/test/TestUtils.hpp')
-rw-r--r--delegate/test/TestUtils.hpp58
1 files changed, 15 insertions, 43 deletions
diff --git a/delegate/test/TestUtils.hpp b/delegate/test/TestUtils.hpp
index 95dd257c92..ba81cd8d56 100644
--- a/delegate/test/TestUtils.hpp
+++ b/delegate/test/TestUtils.hpp
@@ -17,26 +17,12 @@ using Half = half_float::half;
namespace armnnDelegate
{
-/// Can be used to assign input data from a vector to a model input.
-/// Example usage can be found in ResizeTesthelper.hpp
-template <typename T>
-void FillInput(std::unique_ptr<tflite::Interpreter>& interpreter, int inputIndex, std::vector<T>& inputValues)
-{
- auto tfLiteDelegateInputId = interpreter->inputs()[inputIndex];
- auto tfLiteDelageInputData = interpreter->typed_tensor<T>(tfLiteDelegateInputId);
- for (unsigned int i = 0; i < inputValues.size(); ++i)
- {
- tfLiteDelageInputData[i] = inputValues[i];
- }
-}
-
-template <>
-void FillInput(std::unique_ptr<tflite::Interpreter>& interpreter, int inputIndex, std::vector<Half>& inputValues);
+constexpr const char* FILE_IDENTIFIER = "TFL3";
/// Can be used to compare bool data coming from a tflite interpreter
/// Boolean types get converted to a bit representation in a vector. vector.data() returns a void pointer
/// instead of a pointer to bool. Therefore a special function to compare to vector of bool is required
-void CompareData(std::vector<bool>& tensor1, bool tensor2[], size_t tensorSize);
+void CompareData(std::vector<bool>& tensor1, std::vector<bool>& tensor2, size_t tensorSize);
void CompareData(bool tensor1[], bool tensor2[], size_t tensorSize);
/// Can be used to compare float data coming from a tflite interpreter with a tolerance of limit_of_float*100
@@ -66,36 +52,22 @@ void CompareData(TfLiteFloat16 tensor1[], TfLiteFloat16 tensor2[], size_t tensor
/// Can be used to compare Half (Float16) data and TfLiteFloat16 data coming from a tflite interpreter
void CompareData(TfLiteFloat16 tensor1[], Half tensor2[], size_t tensorSize);
-/// Can be used to compare the output tensor shape and values
-/// from armnnDelegateInterpreter and tfLiteInterpreter.
+/// Can be used to compare the output tensor shape
+/// Example usage can be found in ControlTestHelper.hpp
+void CompareOutputShape(const std::vector<int32_t>& tfLiteDelegateShape,
+ const std::vector<int32_t>& armnnDelegateShape,
+ const std::vector<int32_t>& expectedOutputShape);
+
+/// Can be used to compare the output tensor values
/// Example usage can be found in ControlTestHelper.hpp
template <typename T>
-void CompareOutputData(std::unique_ptr<tflite::Interpreter>& tfLiteInterpreter,
- std::unique_ptr<tflite::Interpreter>& armnnDelegateInterpreter,
- std::vector<int32_t>& expectedOutputShape,
- std::vector<T>& expectedOutputValues,
- unsigned int outputIndex = 0)
+void CompareOutputData(std::vector<T>& tfLiteDelegateOutputs,
+ std::vector<T>& armnnDelegateOutputs,
+ std::vector<T>& expectedOutputValues)
{
- auto tfLiteDelegateOutputId = tfLiteInterpreter->outputs()[outputIndex];
- auto tfLiteDelegateOutputTensor = tfLiteInterpreter->tensor(tfLiteDelegateOutputId);
- auto tfLiteDelegateOutputData = tfLiteInterpreter->typed_tensor<T>(tfLiteDelegateOutputId);
- auto armnnDelegateOutputId = armnnDelegateInterpreter->outputs()[outputIndex];
- auto armnnDelegateOutputTensor = armnnDelegateInterpreter->tensor(armnnDelegateOutputId);
- auto armnnDelegateOutputData = armnnDelegateInterpreter->typed_tensor<T>(armnnDelegateOutputId);
-
- CHECK(expectedOutputShape.size() == tfLiteDelegateOutputTensor->dims->size);
- CHECK(expectedOutputShape.size() == armnnDelegateOutputTensor->dims->size);
-
- for (size_t i = 0; i < expectedOutputShape.size(); i++)
- {
- CHECK(expectedOutputShape[i] == armnnDelegateOutputTensor->dims->data[i]);
- CHECK(tfLiteDelegateOutputTensor->dims->data[i] == expectedOutputShape[i]);
- CHECK(tfLiteDelegateOutputTensor->dims->data[i] == armnnDelegateOutputTensor->dims->data[i]);
- }
-
- armnnDelegate::CompareData(expectedOutputValues.data(), armnnDelegateOutputData , expectedOutputValues.size());
- armnnDelegate::CompareData(tfLiteDelegateOutputData , expectedOutputValues.data(), expectedOutputValues.size());
- armnnDelegate::CompareData(tfLiteDelegateOutputData , armnnDelegateOutputData , expectedOutputValues.size());
+ armnnDelegate::CompareData(expectedOutputValues.data(), armnnDelegateOutputs.data(), expectedOutputValues.size());
+ armnnDelegate::CompareData(tfLiteDelegateOutputs.data(), expectedOutputValues.data(), expectedOutputValues.size());
+ armnnDelegate::CompareData(tfLiteDelegateOutputs.data(), armnnDelegateOutputs.data(), expectedOutputValues.size());
}
} // namespace armnnDelegate