aboutsummaryrefslogtreecommitdiff
path: root/delegate/opaque/src
diff options
context:
space:
mode:
authorRyan OShea <ryan.oshea3@arm.com>2023-05-11 20:37:53 +0100
committerMatthew Sloyan <matthew.sloyan@arm.com>2023-05-18 16:06:23 +0000
commit59f8f65f047546e4a73966a988d087eeb6602cea (patch)
treeab72dbc5b4357801cbdd468b2800ccc043e3dfbe /delegate/opaque/src
parent34c1c38944b47b881febdfb9f98103dbdc949ed0 (diff)
downloadarmnn-59f8f65f047546e4a73966a988d087eeb6602cea.tar.gz
IVGCVSW-7735 Opaque Delegate Cleanup
* Move TFL_TheStableDelegate to opaque/armnn_delegate_external.cpp * Change TFL_TheStableDelegate to extern variable * Remove duplicated opaque test sources * Add support for missing Fill operator * Enable support for Mirror Pad * Fix failing Split tests Signed-off-by: Ryan OShea <ryan.oshea3@arm.com> Signed-off-by: Matthew Sloyan <matthew.sloyan@arm.com> Change-Id: I7f8d8b4269bb4fbe27b6f47709cbd828554d37d8
Diffstat (limited to 'delegate/opaque/src')
-rw-r--r--delegate/opaque/src/Fill.hpp130
-rw-r--r--delegate/opaque/src/Split.hpp49
-rw-r--r--delegate/opaque/src/armnn_delegate.cpp34
-rw-r--r--delegate/opaque/src/armnn_external_delegate.cpp39
4 files changed, 219 insertions, 33 deletions
diff --git a/delegate/opaque/src/Fill.hpp b/delegate/opaque/src/Fill.hpp
index e16969768e..a8cdf3a56f 100644
--- a/delegate/opaque/src/Fill.hpp
+++ b/delegate/opaque/src/Fill.hpp
@@ -2,3 +2,133 @@
// Copyright © 2023 Arm Ltd and Contributors. All rights reserved.
// SPDX-License-Identifier: MIT
//
+
+#pragma once
+
+#include <OpaqueDelegateUtils.hpp>
+
+namespace armnnOpaqueDelegate
+{
+
+ TfLiteStatus VisitFillOperator(DelegateData& delegateData,
+ TfLiteOpaqueContext* tfLiteContext,
+ TfLiteOpaqueNode* tfLiteNode,
+ int nodeIndex,
+ int32_t tfLiteFillOperatorCode)
+ {
+ TF_LITE_ENSURE_STATUS(ValidateNumOutputs(tfLiteContext, tfLiteNode, 1, nodeIndex));
+
+ switch(tfLiteFillOperatorCode)
+ {
+ case kTfLiteBuiltinFill:
+ TF_LITE_ENSURE_STATUS(ValidateNumInputs(tfLiteContext, tfLiteNode, 2, nodeIndex));
+ break;
+ default:
+ return kTfLiteError;
+ }
+
+ // Inputs
+ int numInputs = 0;
+ const int* inputTensors;
+ if (TfLiteOpaqueNodeInputs(tfLiteNode, &inputTensors, &numInputs) != kTfLiteOk)
+ {
+ TF_LITE_OPAQUE_MAYBE_KERNEL_LOG(
+ tfLiteContext,
+ "TfLiteArmnnOpaqueDelegate: Unable to gather input tensor indices from node #%d: ",
+ nodeIndex);
+ return kTfLiteError;
+ }
+
+ const TfLiteOpaqueTensor* tfLiteInputTensor = TfLiteOpaqueContextGetOpaqueTensor(tfLiteContext,
+ inputTensors[0]);
+ if (!IsValid(tfLiteContext, tfLiteInputTensor, tfLiteFillOperatorCode, nodeIndex))
+ {
+ return kTfLiteError;
+ }
+
+ const TfLiteOpaqueTensor* tfLiteFillTensor = TfLiteOpaqueContextGetOpaqueTensor(tfLiteContext,
+ inputTensors[1]);
+ if (!IsValid(tfLiteContext, tfLiteFillTensor, tfLiteFillOperatorCode, nodeIndex))
+ {
+ return kTfLiteError;
+ }
+
+ int numOutputs = 0;
+ const int* outputTensors;
+ if (TfLiteOpaqueNodeOutputs(tfLiteNode, &outputTensors, &numOutputs) != kTfLiteOk)
+ {
+ TF_LITE_OPAQUE_MAYBE_KERNEL_LOG(
+ tfLiteContext,
+ "TfLiteArmnnOpaqueDelegate: Unable to gather output tensor indices from node #%d: ",
+ nodeIndex);
+ return kTfLiteError;
+ }
+
+ const TfLiteOpaqueTensor* tfLiteOutputTensor = TfLiteOpaqueContextGetOpaqueTensor(tfLiteContext,
+ outputTensors[0]);
+ if (!IsValid(tfLiteContext, tfLiteOutputTensor, tfLiteFillOperatorCode, nodeIndex))
+ {
+ return kTfLiteError;
+ }
+
+ armnn::TensorInfo inputTensorInfo = GetTensorInfoForTfLiteOpaqueTensor(tfLiteInputTensor);
+ const armnn::TensorInfo& outputTensorInfo = GetTensorInfoForTfLiteOpaqueTensor(tfLiteOutputTensor, true);
+
+ armnn::FillDescriptor descriptor;
+ switch (TfLiteOpaqueTensorType(tfLiteFillTensor))
+ {
+ case kTfLiteFloat32:
+ descriptor.m_Value = *static_cast<float*>(TfLiteOpaqueTensorData(tfLiteFillTensor));
+ break;
+ case kTfLiteInt32:
+ descriptor.m_Value = *static_cast<int32_t*>(TfLiteOpaqueTensorData(tfLiteFillTensor));
+ break;
+ default:
+ TF_LITE_OPAQUE_MAYBE_KERNEL_LOG(
+ tfLiteContext,
+ "TfLiteArmnnOpaqueDelegate: FILL value data type is not supported in operator #%d node #%d: ",
+ tfLiteFillOperatorCode, nodeIndex);
+ return kTfLiteError;
+ }
+
+ bool isSupported = false;
+ armnn::BackendId setBackend;
+ auto validateFunc = [&](const armnn::TensorInfo& outInfo, bool& isSupported)
+ {
+ FORWARD_LAYER_OPAQUE_SUPPORT_FUNC("FILL",
+ tfLiteContext,
+ IsFillSupported,
+ delegateData.m_Backends,
+ isSupported,
+ setBackend,
+ inputTensorInfo,
+ outInfo,
+ descriptor);
+ };
+
+ if (!delegateData.m_Network)
+ {
+ validateFunc(outputTensorInfo, isSupported);
+ return isSupported ? kTfLiteOk : kTfLiteError;
+ }
+
+ armnn::IConnectableLayer* layer = delegateData.m_Network->AddFillLayer(descriptor);
+ layer->SetBackendId(setBackend);
+ ARMNN_ASSERT(layer != nullptr);
+
+ armnn::IOutputSlot& outputSlot = layer->GetOutputSlot(0);
+ outputSlot.SetTensorInfo(outputTensorInfo);
+
+ auto inputsTensorsProcess = ProcessInputs(layer,
+ delegateData,
+ tfLiteContext,
+ tfLiteNode);
+ if (inputsTensorsProcess == kTfLiteError)
+ {
+ return inputsTensorsProcess;
+ }
+
+ return Connect(layer, tfLiteContext, tfLiteNode, delegateData);
+ }
+
+} // namespace armnnDelegate
diff --git a/delegate/opaque/src/Split.hpp b/delegate/opaque/src/Split.hpp
index 3840ed9620..d3d00e4d63 100644
--- a/delegate/opaque/src/Split.hpp
+++ b/delegate/opaque/src/Split.hpp
@@ -81,7 +81,8 @@ TfLiteStatus VisitSplitOperator(DelegateData& delegateData,
// -1 == 3, -2 == 2, -3 == 1, -4 == 0
TF_LITE_OPAQUE_MAYBE_KERNEL_LOG(
tfLiteContext,
- "TfLiteArmnnDelegate: Operation has invalid axis: #%d. Axis must be in range [-n, n) in node #%d:",
+ "TfLiteOpaqueArmnnDelegate: Operation has invalid axis: #%d. "
+ "Axis must be in range [-n, n) in node #%d:",
axis, nodeIndex);
}
const unsigned int splitDim = ComputeWrappedIndex(axis, inputTensorInfo.GetNumDimensions());
@@ -104,8 +105,9 @@ TfLiteStatus VisitSplitOperator(DelegateData& delegateData,
{
TF_LITE_OPAQUE_MAYBE_KERNEL_LOG(
tfLiteContext,
- "TfLiteArmnnDelegate: The number of dimensions: #%d for input tensors of the split op cannot be "
- "greater than #%d in node #%d: ", inputDimSize, MaxNumOfTensorDimensions, nodeIndex);
+ "TfLiteOpaqueArmnnDelegate: The number of dimensions: #%d for input tensors of the split op cannot be "
+ "greater than #%d in node #%d: ",
+ inputDimSize, MaxNumOfTensorDimensions, nodeIndex);
return kTfLiteError;
}
@@ -121,7 +123,7 @@ TfLiteStatus VisitSplitOperator(DelegateData& delegateData,
{
TF_LITE_OPAQUE_MAYBE_KERNEL_LOG(
tfLiteContext,
- "TfLiteArmnnDelegate: Number of splits #%d must evenly divide the dimension #%d in node #%d: ",
+ "TfLiteOpaqueArmnnDelegate: Number of splits #%d must evenly divide the dimension #%d in node #%d: ",
numSplits, splitterDimSizes[splitDim], nodeIndex);
return kTfLiteError;
}
@@ -165,10 +167,25 @@ TfLiteStatus VisitSplitOperator(DelegateData& delegateData,
}
// Connect the input slots
- if(Connect(layer, tfLiteContext, tfLiteNode, delegateData) != kTfLiteOk)
+ delegateData.m_OutputSlotForNode[inputTensors[1]]->Connect(layer->GetInputSlot(0));
+
+ if(numSplits != static_cast<int>(layer->GetNumOutputSlots()))
{
+ TF_LITE_OPAQUE_MAYBE_KERNEL_LOG(
+ tfLiteContext,
+ "TfLiteOpaqueArmnnDelegate: Expected number of splits #%d does not "
+ "match the number of output slots #%d in node #%d: ",
+ numSplits, layer->GetNumOutputSlots(), nodeIndex);
return kTfLiteError;
}
+
+ // Prepare output slots
+ for (unsigned int outputIndex = 0; outputIndex < layer->GetNumOutputSlots(); ++outputIndex)
+ {
+ armnn::IOutputSlot& outputSlot = layer->GetOutputSlot(outputIndex);
+ delegateData.m_OutputSlotForNode[
+ static_cast<unsigned long>(outputTensors[outputIndex])] = &outputSlot;
+ }
return kTfLiteOk;
}
@@ -224,7 +241,8 @@ TfLiteStatus VisitSplitVOperator(DelegateData& delegateData,
{
TF_LITE_OPAQUE_MAYBE_KERNEL_LOG(
tfLiteContext,
- "TfLiteArmnnDelegate: Operation has invalid axis: #%d. Axis must be in range [-n, n) in node #%d:",
+ "TfLiteOpaqueArmnnDelegate: Operation has invalid axis: #%d. "
+ "Axis must be in range [-n, n) in node #%d:",
axis, nodeIndex);
}
const unsigned int splitDim = ComputeWrappedIndex(axisTensorData[0], inputTensorInfo.GetNumDimensions());
@@ -243,7 +261,8 @@ TfLiteStatus VisitSplitVOperator(DelegateData& delegateData,
if (numSplits <= 0)
{
TF_LITE_OPAQUE_MAYBE_KERNEL_LOG(
- tfLiteContext, "TfLiteArmnnDelegate: Invalid number of splits %d in node #%d",
+ tfLiteContext,
+ "TfLiteOpaqueArmnnDelegate: Invalid number of splits %d in node #%d",
numSplits, nodeIndex);
return kTfLiteError;
}
@@ -278,8 +297,9 @@ TfLiteStatus VisitSplitVOperator(DelegateData& delegateData,
{
TF_LITE_OPAQUE_MAYBE_KERNEL_LOG(
tfLiteContext,
- "TfLiteArmnnDelegate: The number of dimensions: #%d for input tensors of the split op cannot be "
- "greater than #%d in node #%d: ", inputDimSize, MaxNumOfTensorDimensions, nodeIndex);
+ "TfLiteOpaqueArmnnDelegate: The number of dimensions: #%d for input tensors of the split op cannot be "
+ "greater than #%d in node #%d: ",
+ inputDimSize, MaxNumOfTensorDimensions, nodeIndex);
return kTfLiteError;
}
@@ -312,8 +332,10 @@ TfLiteStatus VisitSplitVOperator(DelegateData& delegateData,
if (splitSum != armnn::numeric_cast<int>(inputTensorInfo.GetShape()[splitDim]))
{
TF_LITE_OPAQUE_MAYBE_KERNEL_LOG(
- tfLiteContext, "TfLiteArmnnDelegate: SplitV split_sizes does not sum to the dimension of value "
- "along split_dim in node #%d", nodeIndex);
+ tfLiteContext,
+ "TfLiteOpaqueArmnnDelegate: SplitV split_sizes does not sum to the dimension "
+ "of value along split_dim in node #%d",
+ nodeIndex);
return kTfLiteError;
}
}
@@ -324,8 +346,9 @@ TfLiteStatus VisitSplitVOperator(DelegateData& delegateData,
else
{
TF_LITE_OPAQUE_MAYBE_KERNEL_LOG(
- tfLiteContext, "TfLiteArmnnDelegate: SplitV cannot infer split size for "
- "more than one split in node #%d",
+ tfLiteContext,
+ "TfLiteOpaqueArmnnDelegate: SplitV cannot infer split size for "
+ "more than one split in node #%d",
nodeIndex);
return kTfLiteError;
}
diff --git a/delegate/opaque/src/armnn_delegate.cpp b/delegate/opaque/src/armnn_delegate.cpp
index 45aff85346..f32a6f43b8 100644
--- a/delegate/opaque/src/armnn_delegate.cpp
+++ b/delegate/opaque/src/armnn_delegate.cpp
@@ -6,8 +6,6 @@
#include <armnn_delegate.hpp>
#include <OpaqueDelegateUtils.hpp>
-#include <Version.hpp>
-
#include "Activation.hpp"
#include "ArgMinMax.hpp"
#include "BatchMatMul.hpp"
@@ -50,7 +48,6 @@
#include <tensorflow/lite/context_util.h>
#include <tensorflow/lite/schema/schema_generated.h>
#include <tensorflow/lite/minimal_logging.h>
-#include <tensorflow/lite/logger.h>
#include <algorithm>
#include <iostream>
@@ -59,16 +56,8 @@
namespace armnnOpaqueDelegate
{
-const TfLiteStableDelegate TFL_TheStableDelegate =
-{
- /*delegate_abi_version=*/ TFL_STABLE_DELEGATE_ABI_VERSION,
- /*delegate_name=*/ "armnn_delegate",
- /*delegate_version=*/ OPAQUE_DELEGATE_VERSION,
- /*delegate_plugin=*/ GetArmnnDelegatePluginApi()
-};
-
static auto* g_delegate_plugin_ArmnnDelegatePlugin_ =
- new tflite::delegates::DelegatePluginRegistry::Register(TFL_TheStableDelegate.delegate_name,
+ new tflite::delegates::DelegatePluginRegistry::Register("armnn_delegate",
ArmnnDelegatePlugin::New);
ArmnnOpaqueDelegate::ArmnnOpaqueDelegate(armnnDelegate::DelegateOptions options)
@@ -126,7 +115,7 @@ TfLiteStatus DoPrepare(TfLiteOpaqueContext* tfLiteContext, TfLiteOpaqueDelegate*
// ArmNN Opaque Delegate Registration
TfLiteRegistrationExternal* kernelRegistration =
TfLiteRegistrationExternalCreate(kTfLiteBuiltinDelegate,
- TFL_TheStableDelegate.delegate_name,
+ "armnn_delegate",
/*version=*/OPAQUE_DELEGATE_MAJOR_VERSION);
if(kernelRegistration == nullptr)
{
@@ -227,13 +216,6 @@ void TfLiteArmnnOpaqueDelegateDelete(TfLiteOpaqueDelegate* tfLiteDelegate)
}
}
-const TfLiteOpaqueDelegatePlugin* GetArmnnDelegatePluginApi()
-{
- static constexpr TfLiteOpaqueDelegatePlugin armnnPlugin{
- TfLiteArmnnOpaqueDelegateCreate, TfLiteArmnnOpaqueDelegateDelete, TfLiteArmnnOpaqueDelegateErrno};
- return &armnnPlugin;
-}
-
const std::string ArmnnOpaqueDelegate::GetVersion() {
return OPAQUE_DELEGATE_VERSION;
}
@@ -776,6 +758,12 @@ TfLiteStatus ArmnnSubgraph::VisitNode(DelegateData& delegateData,
tfLiteNode,
nodeIndex,
kTfLiteBuiltinExpandDims);
+ case kTfLiteBuiltinFill:
+ return VisitFillOperator(delegateData,
+ tfLiteContext,
+ tfLiteNode,
+ nodeIndex,
+ kTfLiteBuiltinFill);
case kTfLiteBuiltinFloor:
return VisitFloorOperator(delegateData,
tfLiteContext,
@@ -928,6 +916,12 @@ TfLiteStatus ArmnnSubgraph::VisitNode(DelegateData& delegateData,
tfLiteNode,
nodeIndex,
kTfLiteBuiltinMinimum);
+ case kTfLiteBuiltinMirrorPad:
+ return VisitPadOperator(delegateData,
+ tfLiteContext,
+ tfLiteNode,
+ nodeIndex,
+ kTfLiteBuiltinMirrorPad);
case kTfLiteBuiltinMul:
return VisitElementwiseBinaryOperator(delegateData,
tfLiteContext,
diff --git a/delegate/opaque/src/armnn_external_delegate.cpp b/delegate/opaque/src/armnn_external_delegate.cpp
index e16969768e..6cc29f3fe1 100644
--- a/delegate/opaque/src/armnn_external_delegate.cpp
+++ b/delegate/opaque/src/armnn_external_delegate.cpp
@@ -2,3 +2,42 @@
// Copyright © 2023 Arm Ltd and Contributors. All rights reserved.
// SPDX-License-Identifier: MIT
//
+
+#include <armnn_delegate.hpp>
+
+namespace {
+
+ TfLiteOpaqueDelegate* ArmNNDelegateCreateFunc(const void* tflite_settings)
+ {
+ auto delegate = armnnOpaqueDelegate::TfLiteArmnnOpaqueDelegateCreate(tflite_settings);
+ return delegate;
+ }
+
+ void ArmNNDelegateDestroyFunc(TfLiteOpaqueDelegate* armnnDelegate)
+ {
+ armnnOpaqueDelegate::TfLiteArmnnOpaqueDelegateDelete(
+ armnnDelegate);
+ }
+
+ int ArmNNDelegateErrnoFunc(TfLiteOpaqueDelegate* sample_stable_delegate)
+ {
+ return 0;
+ }
+
+ const TfLiteOpaqueDelegatePlugin armnn_delegate_plugin = {
+ ArmNNDelegateCreateFunc, ArmNNDelegateDestroyFunc,
+ ArmNNDelegateErrnoFunc};
+
+ const TfLiteStableDelegate armnn_delegate = {
+ /*delegate_abi_version=*/ TFL_STABLE_DELEGATE_ABI_VERSION,
+ /*delegate_name=*/ "armnn_delegate",
+ /*delegate_version=*/ OPAQUE_DELEGATE_VERSION,
+ /*delegate_plugin=*/ &armnn_delegate_plugin
+ };
+
+} // namespace
+
+/**
+ * The ArmNN delegate to be loaded dynamically
+ */
+extern "C" const TfLiteStableDelegate TFL_TheStableDelegate = armnn_delegate; \ No newline at end of file