diff options
author | Matthew Sloyan <matthew.sloyan@arm.com> | 2023-03-30 10:12:08 +0100 |
---|---|---|
committer | ryan.oshea3 <ryan.oshea3@arm.com> | 2023-04-05 20:36:32 +0000 |
commit | ebe392df1635790bf21714549adb97f2f75559e1 (patch) | |
tree | 6fb8e56cc755d7c47a62bbe72c54b6ca5445377d /delegate/test/StridedSliceTestHelper.hpp | |
parent | ac9607f401dc30003aa97bd179a06d6b8a32139f (diff) | |
download | armnn-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/StridedSliceTestHelper.hpp')
-rw-r--r-- | delegate/test/StridedSliceTestHelper.hpp | 75 |
1 files changed, 26 insertions, 49 deletions
diff --git a/delegate/test/StridedSliceTestHelper.hpp b/delegate/test/StridedSliceTestHelper.hpp index fde7e16c72..d3d160158b 100644 --- a/delegate/test/StridedSliceTestHelper.hpp +++ b/delegate/test/StridedSliceTestHelper.hpp @@ -8,18 +8,15 @@ #include "TestUtils.hpp" #include <armnn_delegate.hpp> -#include <armnn/DescriptorsFwd.hpp> +#include <DelegateTestInterpreter.hpp> #include <flatbuffers/flatbuffers.h> -#include <tensorflow/lite/interpreter.h> #include <tensorflow/lite/kernels/register.h> -#include <tensorflow/lite/model.h> -#include <schema_generated.h> #include <tensorflow/lite/version.h> -#include <doctest/doctest.h> +#include <schema_generated.h> -#include <string> +#include <doctest/doctest.h> namespace { @@ -132,7 +129,7 @@ std::vector<char> CreateStridedSliceTfLiteModel(tflite::TensorType tensorType, modelDescription, flatBufferBuilder.CreateVector(buffers, 6)); - flatBufferBuilder.Finish(flatbufferModel); + flatBufferBuilder.Finish(flatbufferModel, armnnDelegate::FILE_IDENTIFIER); return std::vector<char>(flatBufferBuilder.GetBufferPointer(), flatBufferBuilder.GetBufferPointer() + flatBufferBuilder.GetSize()); @@ -157,7 +154,7 @@ void StridedSliceTestImpl(std::vector<armnn::BackendId>& backends, const int32_t ShrinkAxisMask = 0, const armnn::DataLayout& dataLayout = armnn::DataLayout::NHWC) { - using namespace tflite; + using namespace delegateTestInterpreter; std::vector<char> modelBuffer = CreateStridedSliceTfLiteModel( ::tflite::TensorType_FLOAT32, inputTensorShape, @@ -175,47 +172,27 @@ void StridedSliceTestImpl(std::vector<armnn::BackendId>& backends, ShrinkAxisMask, dataLayout); - auto tfLiteModel = GetModel(modelBuffer.data()); - - // Create TfLite Interpreters - std::unique_ptr<Interpreter> armnnDelegate; - CHECK(InterpreterBuilder(tfLiteModel, ::tflite::ops::builtin::BuiltinOpResolver()) - (&armnnDelegate) == kTfLiteOk); - CHECK(armnnDelegate != nullptr); - CHECK(armnnDelegate->AllocateTensors() == kTfLiteOk); - - std::unique_ptr<Interpreter> tfLiteDelegate; - CHECK(InterpreterBuilder(tfLiteModel, ::tflite::ops::builtin::BuiltinOpResolver()) - (&tfLiteDelegate) == kTfLiteOk); - CHECK(tfLiteDelegate != nullptr); - CHECK(tfLiteDelegate->AllocateTensors() == kTfLiteOk); - - // Create the ArmNN Delegate - armnnDelegate::DelegateOptions delegateOptions(backends); - std::unique_ptr<TfLiteDelegate, decltype(&armnnDelegate::TfLiteArmnnDelegateDelete)> - theArmnnDelegate(armnnDelegate::TfLiteArmnnDelegateCreate(delegateOptions), - armnnDelegate::TfLiteArmnnDelegateDelete); - CHECK(theArmnnDelegate != nullptr); - - // Modify armnnDelegateInterpreter to use armnnDelegate - CHECK(armnnDelegate->ModifyGraphWithDelegate(theArmnnDelegate.get()) == kTfLiteOk); - - // Set input data - armnnDelegate::FillInput<T>(tfLiteDelegate, 0, inputValues); - armnnDelegate::FillInput<T>(armnnDelegate, 0, inputValues); - - // Run EnqueWorkload - CHECK(tfLiteDelegate->Invoke() == kTfLiteOk); - CHECK(armnnDelegate->Invoke() == kTfLiteOk); - - // Compare output data - armnnDelegate::CompareOutputData<T>(tfLiteDelegate, - armnnDelegate, - outputTensorShape, - expectedOutputValues); - - tfLiteDelegate.reset(nullptr); - armnnDelegate.reset(nullptr); + // Setup interpreter with just TFLite Runtime. + auto tfLiteInterpreter = DelegateTestInterpreter(modelBuffer); + CHECK(tfLiteInterpreter.AllocateTensors() == kTfLiteOk); + CHECK(tfLiteInterpreter.FillInputTensor<T>(inputValues, 0) == kTfLiteOk); + CHECK(tfLiteInterpreter.Invoke() == kTfLiteOk); + std::vector<T> tfLiteOutputValues = tfLiteInterpreter.GetOutputResult<T>(0); + std::vector<int32_t> tfLiteOutputShape = tfLiteInterpreter.GetOutputShape(0); + + // Setup interpreter with Arm NN Delegate applied. + auto armnnInterpreter = DelegateTestInterpreter(modelBuffer, backends); + CHECK(armnnInterpreter.AllocateTensors() == kTfLiteOk); + CHECK(armnnInterpreter.FillInputTensor<T>(inputValues, 0) == kTfLiteOk); + CHECK(armnnInterpreter.Invoke() == kTfLiteOk); + std::vector<T> armnnOutputValues = armnnInterpreter.GetOutputResult<T>(0); + std::vector<int32_t> armnnOutputShape = armnnInterpreter.GetOutputShape(0); + + armnnDelegate::CompareOutputData<T>(tfLiteOutputValues, armnnOutputValues, expectedOutputValues); + armnnDelegate::CompareOutputShape(tfLiteOutputShape, armnnOutputShape, outputTensorShape); + + tfLiteInterpreter.Cleanup(); + armnnInterpreter.Cleanup(); } // End of StridedSlice Test } // anonymous namespace
\ No newline at end of file |