summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Eilers <jan.eilers@arm.com>2021-02-03 09:14:30 +0000
committerKeithARM <keith.davis@arm.com>2021-02-15 12:32:46 +0000
commit2ffddda9d9f890a041bcdcc80948d2de1e627832 (patch)
tree84f789b1a2536418186e92ccb0661e341dfdfdfd
parent800b281e506e921006c23cd4309781b6508c0fcb (diff)
downloadarmnn-2ffddda9d9f890a041bcdcc80948d2de1e627832.tar.gz
armnn-2ffddda9d9f890a041bcdcc80948d2de1e627832.tar.bz2
armnn-2ffddda9d9f890a041bcdcc80948d2de1e627832.zip
IVGCVSW-5386 TfLiteDelegate: Add Strided Slice operator
Signed-off-by: Jan Eilers <jan.eilers@arm.com> Change-Id: Icd87b1c54e1a5de84893882da30840a9097f6d84
-rw-r--r--delegate/CMakeLists.txt2
-rw-r--r--delegate/src/Slice.hpp125
-rw-r--r--delegate/src/test/SliceTest.cpp243
-rw-r--r--delegate/src/test/SliceTestHelper.hpp241
4 files changed, 605 insertions, 6 deletions
diff --git a/delegate/CMakeLists.txt b/delegate/CMakeLists.txt
index f792821d1..7de168fa9 100644
--- a/delegate/CMakeLists.txt
+++ b/delegate/CMakeLists.txt
@@ -157,6 +157,8 @@ if(BUILD_UNIT_TESTS)
src/test/SoftmaxTestHelper.hpp
src/test/SpaceDepthTest.cpp
src/test/SpaceDepthTestHelper.hpp
+ src/test/SliceTest.cpp
+ src/test/SliceTestHelper.hpp
src/test/SplitTest.cpp
src/test/SplitTestHelper.hpp
src/test/TestUtils.hpp
diff --git a/delegate/src/Slice.hpp b/delegate/src/Slice.hpp
index 0311abf41..a237034bb 100644
--- a/delegate/src/Slice.hpp
+++ b/delegate/src/Slice.hpp
@@ -21,13 +21,126 @@ TfLiteStatus VisitSliceOperator(DelegateData& delegateData,
int nodeIndex,
int32_t sliceOperatorCode)
{
- armnn::IgnoreUnused(delegateData,
- tfLiteContext,
- tfLiteNode,
- nodeIndex,
- sliceOperatorCode);
+ TF_LITE_ENSURE_STATUS(ValidateNumInputs(tfLiteContext, tfLiteNode, 4, nodeIndex));
+ TF_LITE_ENSURE_STATUS(ValidateNumOutputs(tfLiteContext, tfLiteNode, 1, nodeIndex));
- return kTfLiteError;
+ // Read inputs [input, begin, end, strides]
+ int numInputs = tfLiteNode->inputs->size;
+ std::vector<const TfLiteTensor*> tfLiteInputs;
+ tfLiteInputs.reserve(numInputs);
+ const TfLiteTensor* tfLiteTensors = tfLiteContext->tensors;
+ for (int i = 0; i < numInputs; i++)
+ {
+ const TfLiteTensor* inputTensor = &tfLiteTensors[tfLiteNode->inputs->data[i]];
+ tfLiteInputs.push_back(inputTensor);
+ if (!IsValid(tfLiteContext, *inputTensor, sliceOperatorCode, nodeIndex))
+ {
+ return kTfLiteError;
+ }
+ }
+
+ // We save the begin, end and strides tensors in our descriptor. Therefore we have to read those values from inputs
+ int inputRank = tfLiteInputs[0]->dims->size;
+ auto ReadInt32Input = [&](int inputIndex, std::vector<int32_t>& outputData) -> TfLiteStatus
+ {
+ if (tfLiteInputs[inputIndex]->type != kTfLiteInt32)
+ {
+ TF_LITE_MAYBE_KERNEL_LOG(
+ tfLiteContext,
+ "TfLiteArmnnDelegate: The Begin-, End- and Stride-Tensors of the StridedSlice operation need to "
+ "be of type int32. Operator: #%d node #%d: ",
+ sliceOperatorCode, nodeIndex);
+ return kTfLiteError;
+ }
+ int rank = tfLiteInputs[inputIndex]->dims->size;
+ if (rank != 1)
+ {
+ TF_LITE_MAYBE_KERNEL_LOG(
+ tfLiteContext,
+ "TfLiteArmnnDelegate: The Begin-, End- and Stride-Tensors of the StridedSlice operation need to "
+ "be a 1D-Tensor. Operator: #%d node #%d: ",
+ sliceOperatorCode, nodeIndex);
+ return kTfLiteError;
+ }
+ int numValues = tfLiteInputs[inputIndex]->dims->data[0];
+ if (numValues != inputRank)
+ {
+ TF_LITE_MAYBE_KERNEL_LOG(
+ tfLiteContext,
+ "TfLiteArmnnDelegate: The number of values in the Begin-, End- and Stride-Tensors of the "
+ "StridedSlice operation need to be equal to the rank of the Input-Tensor. Operator: #%d node #%d: ",
+ sliceOperatorCode, nodeIndex);
+ return kTfLiteError;
+ }
+ // return tensor data
+ auto* tensorDataPtr = tflite::GetTensorData<int32_t>(tfLiteInputs[inputIndex]);
+ outputData.assign(tensorDataPtr, tensorDataPtr+numValues);
+ return kTfLiteOk;
+ };
+
+ std::vector<int32_t> beginData;
+ if (ReadInt32Input(1, beginData) != kTfLiteOk)
+ return kTfLiteError;
+ std::vector<int32_t> endData;
+ if (ReadInt32Input(2, endData) != kTfLiteOk)
+ return kTfLiteError;
+ std::vector<int32_t> strideData;
+ if (ReadInt32Input(3, strideData) != kTfLiteOk)
+ return kTfLiteError;
+
+ // parse built in options
+ auto* stridedSliceParams = reinterpret_cast<TfLiteStridedSliceParams*>(tfLiteNode->builtin_data);
+
+ // Write all data to the descriptor
+ armnn::StridedSliceDescriptor descriptor;
+ descriptor.m_Begin = std::move(beginData);
+ descriptor.m_End = std::move(endData);
+ descriptor.m_Stride = std::move(strideData);
+ descriptor.m_BeginMask = stridedSliceParams->begin_mask;
+ descriptor.m_EllipsisMask = stridedSliceParams->ellipsis_mask;
+ descriptor.m_EndMask = stridedSliceParams->end_mask;
+ descriptor.m_NewAxisMask = stridedSliceParams->new_axis_mask;
+ descriptor.m_ShrinkAxisMask = stridedSliceParams->shrink_axis_mask;
+ descriptor.m_DataLayout = armnn::DataLayout::NHWC;
+
+ // Validate output
+ const TfLiteTensor& tfLiteOutputTensor = tfLiteTensors[tfLiteNode->outputs->data[0]];
+ if (!IsValid(tfLiteContext, tfLiteOutputTensor, sliceOperatorCode, nodeIndex))
+ {
+ return kTfLiteError;
+ }
+
+ const armnn::TensorInfo& inputTensorInfo = GetTensorInfoForTfLiteTensor(*tfLiteInputs[0]);
+ const armnn::TensorInfo& outputTensorInfo = GetTensorInfoForTfLiteTensor(tfLiteOutputTensor);
+
+ bool isSupported = false;
+ auto validateFunc = [&](const armnn::TensorInfo& outInfo, bool& isSupported)
+ {
+ FORWARD_LAYER_SUPPORT_FUNC(__func__,
+ tfLiteContext,
+ IsStridedSliceSupported,
+ delegateData.m_Backends,
+ isSupported,
+ inputTensorInfo,
+ outInfo,
+ descriptor);
+ };
+
+ if (!delegateData.m_Network)
+ {
+ validateFunc(outputTensorInfo, isSupported);
+ return isSupported ? kTfLiteOk : kTfLiteError;
+ }
+
+ // Add a StridedSlice layer
+ armnn::IConnectableLayer* layer = delegateData.m_Network->AddStridedSliceLayer(descriptor);
+ ARMNN_ASSERT(layer != nullptr);
+
+ armnn::IOutputSlot& outputSlot = layer->GetOutputSlot(0);
+ outputSlot.SetTensorInfo(outputTensorInfo);
+
+ // Connect
+ return Connect(layer, tfLiteNode, delegateData);
}
} // namespace armnnDelegate
diff --git a/delegate/src/test/SliceTest.cpp b/delegate/src/test/SliceTest.cpp
new file mode 100644
index 000000000..bd0584936
--- /dev/null
+++ b/delegate/src/test/SliceTest.cpp
@@ -0,0 +1,243 @@
+//
+// Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "SliceTestHelper.hpp"
+
+#include <armnn_delegate.hpp>
+
+#include <flatbuffers/flatbuffers.h>
+#include <tensorflow/lite/schema/schema_generated.h>
+
+#include <doctest/doctest.h>
+
+namespace armnnDelegate
+{
+
+void StridedSlice4DTest(std::vector<armnn::BackendId>& backends)
+{
+ std::vector<int32_t> inputShape { 3, 2, 3, 1 };
+ std::vector<int32_t> outputShape { 1, 2, 3, 1 };
+ std::vector<int32_t> beginShape { 4 };
+ std::vector<int32_t> endShape { 4 };
+ std::vector<int32_t> strideShape { 4 };
+
+ std::vector<int32_t> beginData { 1, 0, 0, 0 };
+ std::vector<int32_t> endData { 2, 2, 3, 1 };
+ std::vector<int32_t> strideData { 1, 1, 1, 1 };
+ std::vector<float> inputData { 1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f,
+ 3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f,
+ 5.0f, 5.0f, 5.0f, 6.0f, 6.0f, 6.0f };
+ std::vector<float> outputData { 3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f };
+
+ StridedSliceTestImpl<float>(
+ backends,
+ inputData,
+ outputData,
+ beginData,
+ endData,
+ strideData,
+ inputShape,
+ beginShape,
+ endShape,
+ strideShape,
+ outputShape
+ );
+}
+
+void StridedSlice4DReverseTest(std::vector<armnn::BackendId>& backends)
+{
+ std::vector<int32_t> inputShape { 3, 2, 3, 1 };
+ std::vector<int32_t> outputShape { 1, 2, 3, 1 };
+ std::vector<int32_t> beginShape { 4 };
+ std::vector<int32_t> endShape { 4 };
+ std::vector<int32_t> strideShape { 4 };
+
+ std::vector<int32_t> beginData { 1, -1, 0, 0 };
+ std::vector<int32_t> endData { 2, -3, 3, 1 };
+ std::vector<int32_t> strideData { 1, -1, 1, 1 };
+ std::vector<float> inputData { 1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f,
+ 3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f,
+ 5.0f, 5.0f, 5.0f, 6.0f, 6.0f, 6.0f };
+ std::vector<float> outputData { 4.0f, 4.0f, 4.0f, 3.0f, 3.0f, 3.0f };
+
+ StridedSliceTestImpl<float>(
+ backends,
+ inputData,
+ outputData,
+ beginData,
+ endData,
+ strideData,
+ inputShape,
+ beginShape,
+ endShape,
+ strideShape,
+ outputShape
+ );
+}
+
+void StridedSliceSimpleStrideTest(std::vector<armnn::BackendId>& backends)
+{
+ std::vector<int32_t> inputShape { 3, 2, 3, 1 };
+ std::vector<int32_t> outputShape { 2, 1, 2, 1 };
+ std::vector<int32_t> beginShape { 4 };
+ std::vector<int32_t> endShape { 4 };
+ std::vector<int32_t> strideShape { 4 };
+
+ std::vector<int32_t> beginData { 0, 0, 0, 0 };
+ std::vector<int32_t> endData { 3, 2, 3, 1 };
+ std::vector<int32_t> strideData { 2, 2, 2, 1 };
+ std::vector<float> inputData { 1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f,
+ 3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f,
+ 5.0f, 5.0f, 5.0f, 6.0f, 6.0f, 6.0f };
+ std::vector<float> outputData { 1.0f, 1.0f,
+ 5.0f, 5.0f };
+
+ StridedSliceTestImpl<float>(
+ backends,
+ inputData,
+ outputData,
+ beginData,
+ endData,
+ strideData,
+ inputShape,
+ beginShape,
+ endShape,
+ strideShape,
+ outputShape
+ );
+}
+
+void StridedSliceSimpleRangeMaskTest(std::vector<armnn::BackendId>& backends)
+{
+ std::vector<int32_t> inputShape { 3, 2, 3, 1 };
+ std::vector<int32_t> outputShape { 3, 2, 3, 1 };
+ std::vector<int32_t> beginShape { 4 };
+ std::vector<int32_t> endShape { 4 };
+ std::vector<int32_t> strideShape { 4 };
+
+ std::vector<int32_t> beginData { 1, 1, 1, 1 };
+ std::vector<int32_t> endData { 1, 1, 1, 1 };
+ std::vector<int32_t> strideData { 1, 1, 1, 1 };
+
+ int beginMask = -1;
+ int endMask = -1;
+
+ std::vector<float> inputData { 1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f,
+ 3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f,
+ 5.0f, 5.0f, 5.0f, 6.0f, 6.0f, 6.0f };
+ std::vector<float> outputData { 1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f,
+ 3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f,
+ 5.0f, 5.0f, 5.0f, 6.0f, 6.0f, 6.0f };
+
+ StridedSliceTestImpl<float>(
+ backends,
+ inputData,
+ outputData,
+ beginData,
+ endData,
+ strideData,
+ inputShape,
+ beginShape,
+ endShape,
+ strideShape,
+ outputShape,
+ beginMask,
+ endMask
+ );
+}
+
+
+TEST_SUITE("StridedSlice_CpuRefTests")
+{
+
+TEST_CASE ("StridedSlice_4D_CpuRef_Test")
+{
+ std::vector<armnn::BackendId> backends = {armnn::Compute::CpuRef};
+ StridedSlice4DTest(backends);
+}
+
+TEST_CASE ("StridedSlice_4D_Reverse_CpuRef_Test")
+{
+ std::vector<armnn::BackendId> backends = {armnn::Compute::CpuRef};
+ StridedSlice4DReverseTest(backends);
+}
+
+TEST_CASE ("StridedSlice_SimpleStride_CpuRef_Test")
+{
+ std::vector<armnn::BackendId> backends = {armnn::Compute::CpuRef};
+ StridedSliceSimpleStrideTest(backends);
+}
+
+TEST_CASE ("StridedSlice_SimpleRange_CpuRef_Test")
+{
+ std::vector<armnn::BackendId> backends = {armnn::Compute::CpuRef};
+ StridedSliceSimpleRangeMaskTest(backends);
+}
+
+} // StridedSlice_CpuRefTests TestSuite
+
+
+
+TEST_SUITE("StridedSlice_CpuAccTests")
+{
+
+TEST_CASE ("StridedSlice_4D_CpuAcc_Test")
+{
+ std::vector<armnn::BackendId> backends = {armnn::Compute::CpuAcc};
+ StridedSlice4DTest(backends);
+}
+
+TEST_CASE ("StridedSlice_4D_Reverse_CpuAcc_Test")
+{
+ std::vector<armnn::BackendId> backends = {armnn::Compute::CpuAcc};
+ StridedSlice4DReverseTest(backends);
+}
+
+TEST_CASE ("StridedSlice_SimpleStride_CpuAcc_Test")
+{
+ std::vector<armnn::BackendId> backends = {armnn::Compute::CpuAcc};
+ StridedSliceSimpleStrideTest(backends);
+}
+
+TEST_CASE ("StridedSlice_SimpleRange_CpuAcc_Test")
+{
+ std::vector<armnn::BackendId> backends = {armnn::Compute::CpuAcc};
+ StridedSliceSimpleRangeMaskTest(backends);
+}
+
+} // StridedSlice_CpuAccTests TestSuite
+
+
+
+TEST_SUITE("StridedSlice_GpuAccTests")
+{
+
+TEST_CASE ("StridedSlice_4D_GpuAcc_Test")
+{
+ std::vector<armnn::BackendId> backends = {armnn::Compute::GpuAcc};
+ StridedSlice4DTest(backends);
+}
+
+TEST_CASE ("StridedSlice_4D_Reverse_GpuAcc_Test")
+{
+ std::vector<armnn::BackendId> backends = {armnn::Compute::GpuAcc};
+ StridedSlice4DReverseTest(backends);
+}
+
+TEST_CASE ("StridedSlice_SimpleStride_GpuAcc_Test")
+{
+ std::vector<armnn::BackendId> backends = {armnn::Compute::GpuAcc};
+ StridedSliceSimpleStrideTest(backends);
+}
+
+TEST_CASE ("StridedSlice_SimpleRange_GpuAcc_Test")
+{
+ std::vector<armnn::BackendId> backends = {armnn::Compute::GpuAcc};
+ StridedSliceSimpleRangeMaskTest(backends);
+}
+
+} // StridedSlice_GpuAccTests TestSuite
+
+} // namespace armnnDelegate \ No newline at end of file
diff --git a/delegate/src/test/SliceTestHelper.hpp b/delegate/src/test/SliceTestHelper.hpp
new file mode 100644
index 000000000..abaa807ae
--- /dev/null
+++ b/delegate/src/test/SliceTestHelper.hpp
@@ -0,0 +1,241 @@
+//
+// Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#pragma once
+
+#include "TestUtils.hpp"
+
+#include <armnn_delegate.hpp>
+#include <armnn/DescriptorsFwd.hpp>
+
+#include <flatbuffers/flatbuffers.h>
+#include <tensorflow/lite/interpreter.h>
+#include <tensorflow/lite/kernels/register.h>
+#include <tensorflow/lite/model.h>
+#include <tensorflow/lite/schema/schema_generated.h>
+#include <tensorflow/lite/version.h>
+
+#include <doctest/doctest.h>
+
+#include <string>
+
+namespace
+{
+
+struct StridedSliceParams
+{
+ StridedSliceParams(std::vector<int32_t>& inputTensorShape,
+ std::vector<int32_t>& beginTensorData,
+ std::vector<int32_t>& endTensorData,
+ std::vector<int32_t>& strideTensorData,
+ std::vector<int32_t>& outputTensorShape,
+ armnn::StridedSliceDescriptor& descriptor)
+ : m_InputTensorShape(inputTensorShape),
+ m_BeginTensorData(beginTensorData),
+ m_EndTensorData(endTensorData),
+ m_StrideTensorData(strideTensorData),
+ m_OutputTensorShape(outputTensorShape),
+ m_Descriptor (descriptor) {}
+
+ std::vector<int32_t> m_InputTensorShape;
+ std::vector<int32_t> m_BeginTensorData;
+ std::vector<int32_t> m_EndTensorData;
+ std::vector<int32_t> m_StrideTensorData;
+ std::vector<int32_t> m_OutputTensorShape;
+ armnn::StridedSliceDescriptor m_Descriptor;
+};
+
+std::vector<char> CreateSliceTfLiteModel(tflite::TensorType tensorType,
+ const std::vector<int32_t>& inputTensorShape,
+ const std::vector<int32_t>& beginTensorData,
+ const std::vector<int32_t>& endTensorData,
+ const std::vector<int32_t>& strideTensorData,
+ const std::vector<int32_t>& beginTensorShape,
+ const std::vector<int32_t>& endTensorShape,
+ const std::vector<int32_t>& strideTensorShape,
+ const std::vector<int32_t>& outputTensorShape,
+ const int32_t beginMask,
+ const int32_t endMask,
+ const int32_t ellipsisMask,
+ const int32_t newAxisMask,
+ const int32_t ShrinkAxisMask,
+ const armnn::DataLayout& dataLayout)
+{
+ using namespace tflite;
+ flatbuffers::FlatBufferBuilder flatBufferBuilder;
+
+ std::array<flatbuffers::Offset<tflite::Buffer>, 4> buffers;
+ buffers[0] = CreateBuffer(flatBufferBuilder, flatBufferBuilder.CreateVector({}));
+ buffers[1] = CreateBuffer(flatBufferBuilder,
+ flatBufferBuilder.CreateVector(reinterpret_cast<const uint8_t*>(beginTensorData.data()),
+ sizeof(int32_t) * beginTensorData.size()));
+ buffers[2] = CreateBuffer(flatBufferBuilder,
+ flatBufferBuilder.CreateVector(reinterpret_cast<const uint8_t*>(endTensorData.data()),
+ sizeof(int32_t) * endTensorData.size()));
+ buffers[3] = CreateBuffer(flatBufferBuilder,
+ flatBufferBuilder.CreateVector(reinterpret_cast<const uint8_t*>(strideTensorData.data()),
+ sizeof(int32_t) * strideTensorData.size()));
+
+ std::array<flatbuffers::Offset<Tensor>, 5> tensors;
+ tensors[0] = CreateTensor(flatBufferBuilder,
+ flatBufferBuilder.CreateVector<int32_t>(inputTensorShape.data(),
+ inputTensorShape.size()),
+ tensorType,
+ 0,
+ flatBufferBuilder.CreateString("input"));
+ tensors[1] = CreateTensor(flatBufferBuilder,
+ flatBufferBuilder.CreateVector<int32_t>(beginTensorShape.data(),
+ beginTensorShape.size()),
+ ::tflite::TensorType_INT32,
+ 1,
+ flatBufferBuilder.CreateString("begin_tensor"));
+ tensors[2] = CreateTensor(flatBufferBuilder,
+ flatBufferBuilder.CreateVector<int32_t>(endTensorShape.data(),
+ endTensorShape.size()),
+ ::tflite::TensorType_INT32,
+ 2,
+ flatBufferBuilder.CreateString("end_tensor"));
+ tensors[3] = CreateTensor(flatBufferBuilder,
+ flatBufferBuilder.CreateVector<int32_t>(strideTensorShape.data(),
+ strideTensorShape.size()),
+ ::tflite::TensorType_INT32,
+ 3,
+ flatBufferBuilder.CreateString("stride_tensor"));
+ tensors[4] = CreateTensor(flatBufferBuilder,
+ flatBufferBuilder.CreateVector<int32_t>(outputTensorShape.data(),
+ outputTensorShape.size()),
+ tensorType,
+ 0,
+ flatBufferBuilder.CreateString("output"));
+
+
+ // create operator
+ tflite::BuiltinOptions operatorBuiltinOptionsType = tflite::BuiltinOptions_StridedSliceOptions;
+ flatbuffers::Offset<void> operatorBuiltinOptions = CreateStridedSliceOptions(flatBufferBuilder,
+ beginMask,
+ endMask,
+ ellipsisMask,
+ newAxisMask,
+ ShrinkAxisMask).Union();
+
+ const std::vector<int> operatorInputs{ 0, 1, 2, 3 };
+ const std::vector<int> operatorOutputs{ 4 };
+ flatbuffers::Offset <Operator> sliceOperator =
+ CreateOperator(flatBufferBuilder,
+ 0,
+ flatBufferBuilder.CreateVector<int32_t>(operatorInputs.data(), operatorInputs.size()),
+ flatBufferBuilder.CreateVector<int32_t>(operatorOutputs.data(), operatorOutputs.size()),
+ operatorBuiltinOptionsType,
+ operatorBuiltinOptions);
+
+ const std::vector<int> subgraphInputs{ 0, 1, 2, 3 };
+ const std::vector<int> subgraphOutputs{ 4 };
+ flatbuffers::Offset <SubGraph> subgraph =
+ CreateSubGraph(flatBufferBuilder,
+ flatBufferBuilder.CreateVector(tensors.data(), tensors.size()),
+ flatBufferBuilder.CreateVector<int32_t>(subgraphInputs.data(), subgraphInputs.size()),
+ flatBufferBuilder.CreateVector<int32_t>(subgraphOutputs.data(), subgraphOutputs.size()),
+ flatBufferBuilder.CreateVector(&sliceOperator, 1));
+
+ flatbuffers::Offset <flatbuffers::String> modelDescription =
+ flatBufferBuilder.CreateString("ArmnnDelegate: StridedSlice Operator Model");
+ flatbuffers::Offset <OperatorCode> operatorCode = CreateOperatorCode(flatBufferBuilder,
+ BuiltinOperator_STRIDED_SLICE);
+
+ flatbuffers::Offset <Model> 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<char>(flatBufferBuilder.GetBufferPointer(),
+ flatBufferBuilder.GetBufferPointer() + flatBufferBuilder.GetSize());
+}
+
+template <typename T>
+void StridedSliceTestImpl(std::vector<armnn::BackendId>& backends,
+ std::vector<T>& inputValues,
+ std::vector<T>& expectedOutputValues,
+ std::vector<int32_t>& beginTensorData,
+ std::vector<int32_t>& endTensorData,
+ std::vector<int32_t>& strideTensorData,
+ std::vector<int32_t>& inputTensorShape,
+ std::vector<int32_t>& beginTensorShape,
+ std::vector<int32_t>& endTensorShape,
+ std::vector<int32_t>& strideTensorShape,
+ std::vector<int32_t>& outputTensorShape,
+ const int32_t beginMask = 0,
+ const int32_t endMask = 0,
+ const int32_t ellipsisMask = 0,
+ const int32_t newAxisMask = 0,
+ const int32_t ShrinkAxisMask = 0,
+ const armnn::DataLayout& dataLayout = armnn::DataLayout::NHWC)
+{
+ using namespace tflite;
+ std::vector<char> modelBuffer = CreateSliceTfLiteModel(
+ ::tflite::TensorType_FLOAT32,
+ inputTensorShape,
+ beginTensorData,
+ endTensorData,
+ strideTensorData,
+ beginTensorShape,
+ endTensorShape,
+ strideTensorShape,
+ outputTensorShape,
+ beginMask,
+ endMask,
+ ellipsisMask,
+ newAxisMask,
+ 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);
+} // End of StridedSlice Test
+
+} // anonymous namespace \ No newline at end of file