From ebe392df1635790bf21714549adb97f2f75559e1 Mon Sep 17 00:00:00 2001 From: Matthew Sloyan Date: Thu, 30 Mar 2023 10:12:08 +0100 Subject: 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 Change-Id: I1c4f5464367b35d4528571fa94d14bfaef18fb4d --- delegate/test/ShapeTestHelper.hpp | 75 +++++++++++++-------------------------- 1 file changed, 24 insertions(+), 51 deletions(-) (limited to 'delegate/test/ShapeTestHelper.hpp') diff --git a/delegate/test/ShapeTestHelper.hpp b/delegate/test/ShapeTestHelper.hpp index 54e27ac8fd..42f258b00b 100644 --- a/delegate/test/ShapeTestHelper.hpp +++ b/delegate/test/ShapeTestHelper.hpp @@ -8,14 +8,14 @@ #include "TestUtils.hpp" #include +#include #include -#include #include -#include -#include #include +#include + #include namespace @@ -97,7 +97,7 @@ std::vector CreateShapeTfLiteModel(tflite::TensorType inputTensorType, modelDescription, flatBufferBuilder.CreateVector(buffers.data(), buffers.size())); - flatBufferBuilder.Finish(flatbufferModel); + flatBufferBuilder.Finish(flatbufferModel, armnnDelegate::FILE_IDENTIFIER); return std::vector(flatBufferBuilder.GetBufferPointer(), flatBufferBuilder.GetBufferPointer() + flatBufferBuilder.GetSize()); @@ -114,7 +114,7 @@ void ShapeTest(tflite::TensorType inputTensorType, float quantScale = 1.0f, int quantOffset = 0) { - using namespace tflite; + using namespace delegateTestInterpreter; std::vector modelBuffer = CreateShapeTfLiteModel(inputTensorType, outputTensorType, inputShape, @@ -122,52 +122,25 @@ void ShapeTest(tflite::TensorType inputTensorType, quantScale, quantOffset); - const Model* tfLiteModel = GetModel(modelBuffer.data()); - - // Create TfLite Interpreters - std::unique_ptr armnnDelegate; - - CHECK(InterpreterBuilder(tfLiteModel, ::tflite::ops::builtin::BuiltinOpResolver()) - (&armnnDelegate) == kTfLiteOk); - CHECK(armnnDelegate != nullptr); - CHECK(armnnDelegate->AllocateTensors() == kTfLiteOk); - - std::unique_ptr 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(tfLiteDelegate, 0, inputValues); - armnnDelegate::FillInput(armnnDelegate, 0, inputValues); - - // Run EnqueWorkload - CHECK(tfLiteDelegate->Invoke() == kTfLiteOk); - CHECK(armnnDelegate->Invoke() == kTfLiteOk); - - // Compare output data - armnnDelegate::CompareOutputData(tfLiteDelegate, - armnnDelegate, - expectedOutputShape, - expectedOutputValues, - 0); - - tfLiteDelegate.reset(nullptr); - armnnDelegate.reset(nullptr); + // Setup interpreter with just TFLite Runtime. + auto tfLiteInterpreter = DelegateTestInterpreter(modelBuffer); + CHECK(tfLiteInterpreter.AllocateTensors() == kTfLiteOk); + CHECK(tfLiteInterpreter.Invoke() == kTfLiteOk); + std::vector tfLiteOutputValues = tfLiteInterpreter.GetOutputResult(0); + std::vector tfLiteOutputShape = tfLiteInterpreter.GetOutputShape(0); + + // Setup interpreter with Arm NN Delegate applied. + auto armnnInterpreter = DelegateTestInterpreter(modelBuffer, backends); + CHECK(armnnInterpreter.AllocateTensors() == kTfLiteOk); + CHECK(armnnInterpreter.Invoke() == kTfLiteOk); + std::vector armnnOutputValues = armnnInterpreter.GetOutputResult(0); + std::vector armnnOutputShape = armnnInterpreter.GetOutputShape(0); + + armnnDelegate::CompareOutputData(tfLiteOutputValues, armnnOutputValues, expectedOutputValues); + armnnDelegate::CompareOutputShape(tfLiteOutputShape, armnnOutputShape, expectedOutputShape); + + tfLiteInterpreter.Cleanup(); + armnnInterpreter.Cleanup(); } } // anonymous namespace -- cgit v1.2.1