IVGCVSW-7501 Allow constant tensors as inputs for input data in the delegate
In the TLCT tests we were failing many tests because they used
constant tensors as data input for the layers. We had the functionality
in place but we didnt have it spread across the visit functions.
* Check if inputs are constant tensors and attempt to assign them
to input slot of layers.
* Add missing checks to some functions that return a kTfLiteStatus
so we can see if they fail
* Clean up CreateConstTensor function
Signed-off-by: Ryan OShea <ryan.oshea3@arm.com>
Change-Id: I8610b770aea56932a98f91c961d59b3de47c2ab5
diff --git a/delegate/src/DelegateUtils.hpp b/delegate/src/DelegateUtils.hpp
index c0bef4f..3e74225 100644
--- a/delegate/src/DelegateUtils.hpp
+++ b/delegate/src/DelegateUtils.hpp
@@ -545,10 +545,7 @@
}
armnn::ConstTensor CreateConstTensor(const TfLiteTensor* tfLiteTensor,
- armnn::TensorInfo& tensorInfo,
- armnn::Optional<armnn::PermutationVector&>
- permutationVector = armnn::EmptyOptional(),
- void* permutationData = nullptr)
+ const armnn::TensorInfo& tensorInfo)
{
if (tfLiteTensor->allocation_type != kTfLiteMmapRo)
{
@@ -556,28 +553,7 @@
"TfLiteArmnnDelegate: Not constant allocation type: " + std::to_string(tfLiteTensor->allocation_type));
}
- if(tflite::IsConstantTensor(tfLiteTensor))
- {
- tensorInfo.SetConstant();
- }
-
- if (permutationVector.has_value() && permutationVector.value().GetSize() > 0 && permutationData != nullptr)
- {
- // Permute tensor info
- tensorInfo = armnnUtils::Permuted(tensorInfo, permutationVector.value());
- // then permute data using the shape from permuted tensor info
- armnnUtils::Permute(tensorInfo.GetShape(),
- permutationVector.value(),
- tfLiteTensor->data.data,
- permutationData,
- armnn::GetDataTypeSize(tensorInfo.GetDataType()));
-
- return armnn::ConstTensor(tensorInfo, permutationData);
- }
- else
- {
- return armnn::ConstTensor(tensorInfo, tfLiteTensor->data.data);
- }
+ return armnn::ConstTensor(tensorInfo, tfLiteTensor->data.data);
}
armnn::ConstTensor* GetConstTensorForTfLiteTensor(const TfLiteTensor* tfLiteTensors, TfLiteNode* tfLiteNode, int index)
@@ -611,7 +587,7 @@
}
TfLiteStatus ConnectConstant(armnn::IConnectableLayer* layer,
- armnn::TensorInfo& constTensorInfo,
+ const armnn::TensorInfo& constTensorInfo,
TfLiteContext* tfLiteContext,
const TfLiteTensor& tfLiteTensor,
armnnDelegate::DelegateData& data,
@@ -633,8 +609,7 @@
}
auto constantInput = CreateConstTensor(&tfLiteTensor,
- constTensorInfo,
- armnn::Optional<armnn::PermutationVector&>());
+ constTensorInfo);
armnn::IConnectableLayer* constantLayer = data.m_Network->AddConstantLayer(constantInput);
constantLayer->SetBackendId(setBackend);
armnn::IOutputSlot& outputSlot = constantLayer->GetOutputSlot(0);
@@ -684,8 +659,7 @@
return kTfLiteError;
}
auto constantInput = CreateConstTensor(&tfLiteInputTensor,
- inputTensorInfo,
- armnn::Optional<armnn::PermutationVector&>());
+ inputTensorInfo);
armnn::IConnectableLayer* constantLayer = delegateData.m_Network->AddConstantLayer(constantInput);
constantLayer->SetBackendId(setBackend);
armnn::IOutputSlot& outputSlot = constantLayer->GetOutputSlot(0);