From 49ed0df12338b1e99674edeee4200acf8c05750e Mon Sep 17 00:00:00 2001 From: Ryan OShea Date: Wed, 21 Sep 2022 16:09:41 +0100 Subject: IVGCVSW-6498 Add Support for Batch MatMul to TfLite Delegate * Creates delegate/src/BatchMatMul.hpp * Add VisitBatchMatMul function * Add BatchMatMul to switch in armnn_delegate * Creates delegate/src/test/BatchMatMulTest.cpp * Creates delegate/src/test/BatchMatMulTestHelper.hpp * Add Int8 and Fp32 unit tests on ref backend * Add BatchMatMul to delegate supported ops Signed-off-by: Ryan OShea Change-Id: I50e61314cf063f986c8a0f7d508847a96953735e --- delegate/src/test/BatchMatMulTest.cpp | 657 ++++++++++++++++++++++++++++ delegate/src/test/BatchMatMulTestHelper.hpp | 206 +++++++++ 2 files changed, 863 insertions(+) create mode 100644 delegate/src/test/BatchMatMulTest.cpp create mode 100644 delegate/src/test/BatchMatMulTestHelper.hpp (limited to 'delegate/src/test') diff --git a/delegate/src/test/BatchMatMulTest.cpp b/delegate/src/test/BatchMatMulTest.cpp new file mode 100644 index 0000000000..5469bc845c --- /dev/null +++ b/delegate/src/test/BatchMatMulTest.cpp @@ -0,0 +1,657 @@ +// +// Copyright © 2022 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "BatchMatMulTestHelper.hpp" + +#include + +#include +#include + +#include + +namespace armnnDelegate +{ + + void BatchMatMul2DFp32SimpleTest(std::vector& backends) + { + // Set input data + std::vector LHSInputShape { 2, 2 }; + std::vector RHSInputShape { 2, 2 }; + std::vector outputShape { 2, 2 }; + + std::vector LHSInputValues = { 1, 2, + 3, 4 }; + + std::vector RHSInputValues = { 5, 6, + 7, 8 }; + + std::vector expectedOutputValues = { 19, 22, + 43, 50 }; + + BatchMatMulTest(tflite::BuiltinOperator_BATCH_MATMUL, + ::tflite::TensorType_FLOAT32, + backends, + LHSInputShape, + RHSInputShape, + outputShape, + LHSInputValues, + RHSInputValues, + expectedOutputValues, + false, + false); + } + void BatchMatMul2DInt8SimpleTest(std::vector& backends) + { + // Set input data + std::vector LHSInputShape { 2, 2 }; + std::vector RHSInputShape { 2, 2 }; + std::vector outputShape { 2, 2 }; + + std::vector LHSInputValues = { 1, 2, + 3, 4 }; + + std::vector RHSInputValues = { 5, 6, + 7, 8 }; + + std::vector expectedOutputValues = { 19, 22, + 43, 50 }; + + BatchMatMulTest(tflite::BuiltinOperator_BATCH_MATMUL, + ::tflite::TensorType_INT8, + backends, + LHSInputShape, + RHSInputShape, + outputShape, + LHSInputValues, + RHSInputValues, + expectedOutputValues, + false, + false); + } + + void BatchMatMul3DFp32SimpleTest(std::vector& backends) + { + // Set input data + std::vector LHSInputShape { 1,2,2 }; + std::vector RHSInputShape { 1,2,2 }; + std::vector outputShape { 1,2,2 }; + + std::vector LHSInputValues = { 1, 2, + 3, 4 }; + + std::vector RHSInputValues = { 5, 6, + 7, 8 }; + + std::vector expectedOutputValues = { 19, 22, + 43, 50 }; + + BatchMatMulTest(tflite::BuiltinOperator_BATCH_MATMUL, + ::tflite::TensorType_FLOAT32, + backends, + LHSInputShape, + RHSInputShape, + outputShape, + LHSInputValues, + RHSInputValues, + expectedOutputValues, + false, + false); + } + + void BatchMatMul3DInt8SimpleTest(std::vector& backends) + { + // Set input data + std::vector LHSInputShape { 1,2,2 }; + std::vector RHSInputShape { 1,2,2 }; + std::vector outputShape { 1,2,2 }; + + std::vector LHSInputValues = { 1, 2, + 3, 4 }; + + std::vector RHSInputValues = { 5, 6, + 7, 8 }; + + std::vector expectedOutputValues = { 19, 22, + 43, 50 }; + + BatchMatMulTest(tflite::BuiltinOperator_BATCH_MATMUL, + ::tflite::TensorType_INT8, + backends, + LHSInputShape, + RHSInputShape, + outputShape, + LHSInputValues, + RHSInputValues, + expectedOutputValues, + false, + false); + } + + void BatchMatMul4DFp32SimpleTest(std::vector& backends) + { + // Set input data + std::vector LHSInputShape { 1,1,2,2 }; + std::vector RHSInputShape { 1,1,2,2 }; + std::vector outputShape { 1,1,2,2 }; + + std::vector LHSInputValues = { 1, 2, + 3, 4 }; + + std::vector RHSInputValues = { 5, 6, + 7, 8 }; + + std::vector expectedOutputValues = { 19, 22, + 43, 50 }; + + BatchMatMulTest(tflite::BuiltinOperator_BATCH_MATMUL, + ::tflite::TensorType_FLOAT32, + backends, + LHSInputShape, + RHSInputShape, + outputShape, + LHSInputValues, + RHSInputValues, + expectedOutputValues, + false, + false); + } + + void BatchMatMul4DInt8SimpleTest(std::vector& backends) + { + // Set input data + std::vector LHSInputShape { 1,1,2,2}; + std::vector RHSInputShape { 1,1,2,2 }; + std::vector outputShape { 1,1,2,2 }; + + std::vector LHSInputValues = { 1, 2, + 3, 4 }; + + std::vector RHSInputValues = { 5, 6, + 7, 8 }; + + std::vector expectedOutputValues = { 19, 22, + 43, 50 }; + + BatchMatMulTest(tflite::BuiltinOperator_BATCH_MATMUL, + ::tflite::TensorType_INT8, + backends, + LHSInputShape, + RHSInputShape, + outputShape, + LHSInputValues, + RHSInputValues, + expectedOutputValues, + false, + false); + } + + void BatchMatMul3DFp32BatchTest(std::vector& backends) + { + // Set input data + std::vector LHSInputShape { 2,2,2 }; + std::vector RHSInputShape { 2,2,2 }; + std::vector outputShape { 2,2,2 }; + + std::vector LHSInputValues = { 1, 2, + 3, 4, + + 9, 10, + 11, 12 }; + + std::vector RHSInputValues = { 5, 6, + 7, 8, + + 13, 14, + 15, 16 }; + + std::vector expectedOutputValues = { 19, 22, + 43, 50, + + 267, 286, + 323, 346 }; + + BatchMatMulTest(tflite::BuiltinOperator_BATCH_MATMUL, + ::tflite::TensorType_FLOAT32, + backends, + LHSInputShape, + RHSInputShape, + outputShape, + LHSInputValues, + RHSInputValues, + expectedOutputValues, + false, + false); + } + + void BatchMatMul3DInt8BatchTest(std::vector& backends) + { + // Set input data + std::vector LHSInputShape { 2,2,2 }; + std::vector RHSInputShape { 2,2,2 }; + std::vector outputShape { 2,2,2 }; + + std::vector LHSInputValues = { 1, 2, + 3, 4, + + 9, 10, + 11, 12 }; + + std::vector RHSInputValues = { 5, 6, + 7, 8, + + 1, 2, + 3, 4 }; + + std::vector expectedOutputValues = { 19, 22, + 43, 50, + + 39, 58, + 47, 70 }; + + BatchMatMulTest(tflite::BuiltinOperator_BATCH_MATMUL, + ::tflite::TensorType_INT8, + backends, + LHSInputShape, + RHSInputShape, + outputShape, + LHSInputValues, + RHSInputValues, + expectedOutputValues, + false, + false); + } + + void BatchMatMul3DFp32BroadcastTest(std::vector& backends) + { + // Set input data + std::vector LHSInputShape { 2,2,2 }; + std::vector RHSInputShape { 1,2,2 }; + std::vector outputShape { 2,2,2 }; + + std::vector LHSInputValues = { 1, 2, + 3, 4, + + 9, 10, + 11, 12 }; + + std::vector RHSInputValues = { 13, 14, + 15, 16 }; + + std::vector expectedOutputValues = { 43, 46, + 99, 106, + + 267, 286, + 323, 346 }; + + BatchMatMulTest(tflite::BuiltinOperator_BATCH_MATMUL, + ::tflite::TensorType_FLOAT32, + backends, + LHSInputShape, + RHSInputShape, + outputShape, + LHSInputValues, + RHSInputValues, + expectedOutputValues, + false, + false); + } + + void BatchMatMul3DInt8BroadcastTest(std::vector& backends) + { + // Set input data + std::vector LHSInputShape { 2,2,2 }; + std::vector RHSInputShape { 1,2,2 }; + std::vector outputShape { 2,2,2 }; + + std::vector LHSInputValues = { 1, 2, + 3, 4, + + 9, 10, + 11, 12 }; + + std::vector RHSInputValues = { 1, 2, + 3, 4 }; + + std::vector expectedOutputValues = { 7, 10, + 15, 22, + + 39, 58, + 47, 70 }; + + BatchMatMulTest(tflite::BuiltinOperator_BATCH_MATMUL, + ::tflite::TensorType_INT8, + backends, + LHSInputShape, + RHSInputShape, + outputShape, + LHSInputValues, + RHSInputValues, + expectedOutputValues, + false, + false); + } + + void BatchMatMul3D2DFp32BroadcastTest(std::vector& backends) + { + // Set input data + std::vector LHSInputShape { 2,2,2 }; + std::vector RHSInputShape { 2,2 }; + std::vector outputShape { 2,2,2 }; + + std::vector LHSInputValues = { 1, 2, + 3, 4, + + 9, 10, + 11, 12 }; + + std::vector RHSInputValues = { 13, 14, + 15, 16 }; + + std::vector expectedOutputValues = { 43, 46, + 99, 106, + + 267, 286, + 323, 346 }; + + BatchMatMulTest(tflite::BuiltinOperator_BATCH_MATMUL, + ::tflite::TensorType_FLOAT32, + backends, + LHSInputShape, + RHSInputShape, + outputShape, + LHSInputValues, + RHSInputValues, + expectedOutputValues, + false, + false); + } + + void BatchMatMul3D2DInt8BroadcastTest(std::vector& backends) + { + // Set input data + std::vector LHSInputShape { 2,2,2 }; + std::vector RHSInputShape { 2,2 }; + std::vector outputShape { 2,2,2 }; + + std::vector LHSInputValues = { 1, 2, + 3, 4, + + 9, 10, + 11, 12 }; + + std::vector RHSInputValues = { 1, 2, + 3, 4 }; + + std::vector expectedOutputValues = { 7, 10, + 15, 22, + + 39, 58, + 47, 70 }; + + BatchMatMulTest(tflite::BuiltinOperator_BATCH_MATMUL, + ::tflite::TensorType_INT8, + backends, + LHSInputShape, + RHSInputShape, + outputShape, + LHSInputValues, + RHSInputValues, + expectedOutputValues, + false, + false); + } + + void BatchMatMul2DFp32TinyTest(std::vector& backends) + { + // Set input data + std::vector LHSInputShape { 1,1 }; + std::vector RHSInputShape { 1,1 }; + std::vector outputShape { 1,1 }; + + std::vector LHSInputValues = { 3 }; + + std::vector RHSInputValues = { 5 }; + + std::vector expectedOutputValues = { 15 }; + + BatchMatMulTest(tflite::BuiltinOperator_BATCH_MATMUL, + ::tflite::TensorType_FLOAT32, + backends, + LHSInputShape, + RHSInputShape, + outputShape, + LHSInputValues, + RHSInputValues, + expectedOutputValues, + false, + false); + } + void BatchMatMul2DInt8TinyTest(std::vector& backends) + { + // Set input data + std::vector LHSInputShape { 1,1 }; + std::vector RHSInputShape { 1,1 }; + std::vector outputShape { 1,1 }; + + std::vector LHSInputValues = { 3 }; + + std::vector RHSInputValues = { 5 }; + + std::vector expectedOutputValues = { 15 }; + + BatchMatMulTest(tflite::BuiltinOperator_BATCH_MATMUL, + ::tflite::TensorType_INT8, + backends, + LHSInputShape, + RHSInputShape, + outputShape, + LHSInputValues, + RHSInputValues, + expectedOutputValues, + false, + false); + } + + void BatchMatMulNonSquareFp32Test(std::vector& backends) + { + // Set input data + std::vector LHSInputShape { 2,5,3 }; + std::vector RHSInputShape { 2,3,4 }; + std::vector outputShape { 2,5,4 }; + + std::vector LHSInputValues = { 8, 8, 4, + 6, 1, 3, + 8, 8, 3, + 8, 9, 8, + 5, 4, 4, + + 1, 8, 5, + 7, 1, 1, + 8, 7, 9, + 3, 2, 7, + 8, 5, 3 }; + + std::vector RHSInputValues = { 6, 2, 3, 2, + 6, 2, 2, 8, + 3, 7, 8, 1, + + 7, 2, 9, 5, + 2, 3, 1, 3, + 2, 7, 7, 5 }; + + std::vector expectedOutputValues = { 108, 60, 72, 84, + 51, 35, 44, 23, + 105, 53, 64, 83, + 126, 90, 106, 96, + 66, 46, 55, 46, + + 33, 61, 52, 54, + 53, 24, 71, 43, + 88, 100, 142, 106, + 39, 61, 78, 56, + 72, 52, 98, 70 }; + + BatchMatMulTest(tflite::BuiltinOperator_BATCH_MATMUL, + ::tflite::TensorType_FLOAT32, + backends, + LHSInputShape, + RHSInputShape, + outputShape, + LHSInputValues, + RHSInputValues, + expectedOutputValues, + false, + false); + } + + void BatchMatMulNonSquareInt8Test(std::vector& backends) + { + // Set input data + std::vector LHSInputShape { 2,5,3 }; + std::vector RHSInputShape { 2,3,4 }; + std::vector outputShape { 2,5,4 }; + + std::vector LHSInputValues = { 8, 8, 4, + 6, 1, 3, + 8, 8, 3, + 8, 9, 8, + 5, 4, 4, + + 1, 8, 5, + 7, 1, 1, + 8, 7, 9, + 3, 2, 7, + 8, 5, 3 }; + + std::vector RHSInputValues = { 6, 2, 3, 2, + 6, 2, 2, 8, + 3, 7, 8, 1, + + 7, 2, 3, 5, + 2, 3, 1, 3, + 2, 7, 7, 5 }; + + std::vector expectedOutputValues = { 108, 60, 72, 84, + 51, 35, 44, 23, + 105, 53, 64, 83, + 126, 90, 106, 96, + 66, 46, 55, 46, + + 33, 61, 46, 54, + 53, 24, 29, 43, + 88, 100, 94, 106, + 39, 61, 60, 56, + 72, 52, 50, 70 }; + + BatchMatMulTest(tflite::BuiltinOperator_BATCH_MATMUL, + ::tflite::TensorType_INT8, + backends, + LHSInputShape, + RHSInputShape, + outputShape, + LHSInputValues, + RHSInputValues, + expectedOutputValues, + false, + false); + } + + void BatchMatMul2DFp32SimpleAdjointTest(std::vector& backends) + { + // Set input data + std::vector LHSInputShape { 3,3 }; + std::vector RHSInputShape { 3,3 }; + std::vector outputShape { 3,3 }; + + std::vector LHSInputValues = { 3, 1, 1, + 1, 3, -1, + 2, 4, 1 }; + + std::vector RHSInputValues = { 1, 0, 0, + 0, 1, 0, + 0, 0, 1 }; + + std::vector expectedOutputValues = { 3, 1, 2, + 1, 3, 4, + 1, -1, 1 }; + + BatchMatMulTest(tflite::BuiltinOperator_BATCH_MATMUL, + ::tflite::TensorType_FLOAT32, + backends, + LHSInputShape, + RHSInputShape, + outputShape, + LHSInputValues, + RHSInputValues, + expectedOutputValues, + true, + false); + } + + void BatchMatMul2DInt8SimpleAdjointTest(std::vector& backends) + { + // Set input data + std::vector LHSInputShape { 3,3 }; + std::vector RHSInputShape { 3,3 }; + std::vector outputShape { 3,3 }; + + std::vector LHSInputValues = { 3, 1, 1, + 1, 3, -1, + 2, 4, 1 }; + + std::vector RHSInputValues = { 1, 0, 0, + 0, 1, 0, + 0, 0, 1 }; + + std::vector expectedOutputValues = { 3, 1, 2, + 1, 3, 4, + 1, -1, 1 }; + + BatchMatMulTest(tflite::BuiltinOperator_BATCH_MATMUL, + ::tflite::TensorType_INT8, + backends, + LHSInputShape, + RHSInputShape, + outputShape, + LHSInputValues, + RHSInputValues, + expectedOutputValues, + true, + false); + } + + TEST_SUITE("BATCH_MATMUL_CpuRefTests") + { + TEST_CASE("BATCH_MATMUL_Fp32_CpuRefTests") + { + std::vector backends = {armnn::Compute::CpuRef}; + BatchMatMul2DFp32SimpleTest (backends); + BatchMatMul3DFp32SimpleTest (backends); + BatchMatMul4DFp32SimpleTest (backends); + BatchMatMul3DFp32BatchTest (backends); + BatchMatMul3DFp32BroadcastTest (backends); + BatchMatMul3D2DFp32BroadcastTest (backends); + BatchMatMul2DFp32TinyTest (backends); + BatchMatMulNonSquareFp32Test (backends); + BatchMatMul2DFp32SimpleAdjointTest(backends); + } + + TEST_CASE("BATCH_MATMUL_Int8_CpuRefTests") + { + std::vector backends = {armnn::Compute::CpuRef}; + BatchMatMul2DInt8SimpleTest (backends); + BatchMatMul3DInt8SimpleTest (backends); + BatchMatMul4DInt8SimpleTest (backends); + BatchMatMul3DInt8BatchTest (backends); + BatchMatMul3DInt8BroadcastTest (backends); + BatchMatMul3D2DInt8BroadcastTest (backends); + BatchMatMul2DInt8TinyTest (backends); + BatchMatMulNonSquareInt8Test (backends); + BatchMatMul2DInt8SimpleAdjointTest(backends); + } + } + +} diff --git a/delegate/src/test/BatchMatMulTestHelper.hpp b/delegate/src/test/BatchMatMulTestHelper.hpp new file mode 100644 index 0000000000..42c1ed6a1e --- /dev/null +++ b/delegate/src/test/BatchMatMulTestHelper.hpp @@ -0,0 +1,206 @@ +// +// Copyright © 2022 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#pragma once + +#include "TestUtils.hpp" + +#include + +#include +#include +#include +#include +#include +#include + +#include + +namespace +{ + + std::vector CreateBatchMatMulTfLiteModel( + tflite::BuiltinOperator bmmOperatorCode, + tflite::TensorType tensorType, + const std::vector & LHSInputTensorShape, + const std::vector & RHSInputTensorShape, + const std::vector & outputTensorShape, + bool adjX = false, + bool adjY = false, + float quantScale = 1.0f, + int quantOffset = 0) + { + using namespace tflite; + flatbuffers::FlatBufferBuilder flatBufferBuilder; + + std::vector> buffers; + buffers.push_back(CreateBuffer(flatBufferBuilder, flatBufferBuilder.CreateVector({}))); + + auto quantizationParameters = + CreateQuantizationParameters(flatBufferBuilder, + 0, + 0, + flatBufferBuilder.CreateVector({ quantScale }), + flatBufferBuilder.CreateVector({ quantOffset })); + + std::array, 3> tensors; + tensors[0] = CreateTensor(flatBufferBuilder, + flatBufferBuilder.CreateVector(LHSInputTensorShape.data(), + LHSInputTensorShape.size()), + tensorType, + 0, + flatBufferBuilder.CreateString("LHSInput"), + quantizationParameters); + + tensors[1] = CreateTensor(flatBufferBuilder, + flatBufferBuilder.CreateVector(RHSInputTensorShape.data(), + RHSInputTensorShape.size()), + tensorType, + 0, + flatBufferBuilder.CreateString("RHSInput"), + quantizationParameters); + + tensors[2] = CreateTensor(flatBufferBuilder, + flatBufferBuilder.CreateVector(outputTensorShape.data(), + outputTensorShape.size()), + tensorType, + 0, + flatBufferBuilder.CreateString("output"), + quantizationParameters); + + // create operator + tflite::BuiltinOptions operatorBuiltinOptionsType = BuiltinOptions_BatchMatMulOptions; + flatbuffers::Offset operatorBuiltinOptions = CreateBatchMatMulOptions(flatBufferBuilder, + adjX, + adjY).Union(); + + const std::vector operatorInputs{{0, 1}}; + const std::vector operatorOutputs{2}; + flatbuffers::Offset bmmOperator = + CreateOperator(flatBufferBuilder, + 0, + flatBufferBuilder.CreateVector(operatorInputs.data(), operatorInputs.size()), + flatBufferBuilder.CreateVector(operatorOutputs.data(), + operatorOutputs.size()), + operatorBuiltinOptionsType, + operatorBuiltinOptions); + + const std::vector subgraphInputs{{0, 1}}; + const std::vector subgraphOutputs{2}; + flatbuffers::Offset subgraph = + CreateSubGraph(flatBufferBuilder, + flatBufferBuilder.CreateVector(tensors.data(), tensors.size()), + flatBufferBuilder.CreateVector(subgraphInputs.data(), subgraphInputs.size()), + flatBufferBuilder.CreateVector(subgraphOutputs.data(), + subgraphOutputs.size()), + flatBufferBuilder.CreateVector(&bmmOperator, 1)); + + flatbuffers::Offset modelDescription = + flatBufferBuilder.CreateString("ArmnnDelegate: BatchMatMul Operator Model"); + flatbuffers::Offset operatorCode = CreateOperatorCode(flatBufferBuilder, bmmOperatorCode); + + flatbuffers::Offset flatbufferModel = + CreateModel(flatBufferBuilder, + TFLITE_SCHEMA_VERSION, + flatBufferBuilder.CreateVector(&operatorCode, 1), + flatBufferBuilder.CreateVector(&subgraph, 1), + modelDescription, + flatBufferBuilder.CreateVector(buffers.data(), buffers.size())); + + flatBufferBuilder.Finish(flatbufferModel); + + return std::vector(flatBufferBuilder.GetBufferPointer(), + flatBufferBuilder.GetBufferPointer() + flatBufferBuilder.GetSize()); + } + + template + void BatchMatMulTest(tflite::BuiltinOperator bmmOperatorCode, + tflite::TensorType tensorType, + std::vector& backends, + std::vector& LHSInputShape, + std::vector& RHSInputShape, + std::vector& outputShape, + std::vector& LHSInputValues, + std::vector& RHSInputValues, + std::vector& expectedOutputValues, + bool adjX = false, + bool adjY = false, + float quantScale = 1.0f, + int quantOffset = 0) + { + using namespace tflite; + std::vector modelBuffer = CreateBatchMatMulTfLiteModel(bmmOperatorCode, + tensorType, + LHSInputShape, + RHSInputShape, + outputShape, + adjX, + adjY, + quantScale, + quantOffset); + + const Model* tfLiteModel = GetModel(modelBuffer.data()); + CHECK(tfLiteModel != nullptr); + // Create TfLite Interpreters + std::unique_ptr armnnDelegateInterpreter; + CHECK(InterpreterBuilder(tfLiteModel, ::tflite::ops::builtin::BuiltinOpResolver()) + (&armnnDelegateInterpreter) == kTfLiteOk); + CHECK(armnnDelegateInterpreter != nullptr); + CHECK(armnnDelegateInterpreter->AllocateTensors() == kTfLiteOk); + + std::unique_ptr tfLiteInterpreter; + CHECK(InterpreterBuilder(tfLiteModel, ::tflite::ops::builtin::BuiltinOpResolver()) + (&tfLiteInterpreter) == kTfLiteOk); + CHECK(tfLiteInterpreter != nullptr); + CHECK(tfLiteInterpreter->AllocateTensors() == kTfLiteOk); + + // Create the ArmNN Delegate + armnnDelegate::DelegateOptions delegateOptions(backends); + std::unique_ptr + theArmnnDelegate(armnnDelegate::TfLiteArmnnDelegateCreate(delegateOptions), + armnnDelegate::TfLiteArmnnDelegateDelete); + CHECK(theArmnnDelegate != nullptr); + // Modify armnnDelegateInterpreter to use armnnDelegate + CHECK(armnnDelegateInterpreter->ModifyGraphWithDelegate(theArmnnDelegate.get()) == kTfLiteOk); + + // Set input data + auto tfLiteDelegateLHSInputId = tfLiteInterpreter->inputs()[0]; + auto tfLiteDelegateLHSInputData = tfLiteInterpreter->typed_tensor(tfLiteDelegateLHSInputId); + auto tfLiteDelegateRHSInputId = tfLiteInterpreter->inputs()[1]; + auto tfLiteDelegateRHSInputData = tfLiteInterpreter->typed_tensor(tfLiteDelegateRHSInputId); + for (unsigned int i = 0; i < LHSInputValues.size(); ++i) + { + tfLiteDelegateLHSInputData[i] = LHSInputValues[i]; + } + for (unsigned int i = 0; i < RHSInputValues.size(); ++i) + { + tfLiteDelegateRHSInputData[i] = RHSInputValues[i]; + } + + auto armnnDelegateLHSInputId = armnnDelegateInterpreter->inputs()[0]; + auto armnnDelegateLHSInputData = armnnDelegateInterpreter->typed_tensor(armnnDelegateLHSInputId); + auto armnnDelegateRHSInputId = armnnDelegateInterpreter->inputs()[1]; + auto armnnDelegateRHSInputData = armnnDelegateInterpreter->typed_tensor(armnnDelegateRHSInputId); + for (unsigned int i = 0; i < LHSInputValues.size(); ++i) + { + armnnDelegateLHSInputData[i] = LHSInputValues[i]; + } + for (unsigned int i = 0; i < RHSInputValues.size(); ++i) + { + armnnDelegateRHSInputData[i] = RHSInputValues[i]; + } + // Run EnqueueWorkload + CHECK(tfLiteInterpreter->Invoke() == kTfLiteOk); + CHECK(armnnDelegateInterpreter->Invoke() == kTfLiteOk); + + armnnDelegate::CompareOutputData(tfLiteInterpreter, armnnDelegateInterpreter, + outputShape, expectedOutputValues); + } + +} // anonymous namespace + + + + -- cgit v1.2.1