aboutsummaryrefslogtreecommitdiff
path: root/delegate/opaque
diff options
context:
space:
mode:
authorMatthew Sloyan <matthew.sloyan@arm.com>2023-04-04 12:06:14 +0100
committerMatthew Sloyan <matthew.sloyan@arm.com>2023-04-07 18:23:12 +0100
commit65c21a1eeff32f3abf91c3a638252ceb1ae5c51e (patch)
tree9dfdf5727687c09a932f8d8dd2f2047e3b5690cd /delegate/opaque
parent40847fc1f8ae7b7f56ca16eec92d1b46929f53e3 (diff)
downloadarmnn-65c21a1eeff32f3abf91c3a638252ceb1ae5c51e.tar.gz
IVGCVSW-7563 Implement DelegateTestInterpreter for opaque delegate
* Added opaque delegate DelegateTestInterpreter implementation * Moved classic specific tests to ArmnnClassicDelegateTest.cpp * Moved opaque specific tests to ArmnnOpaqueDelegateTest.cpp * Removed ArmnnDelegateTest.cpp * Moved TfLiteStableDelegate implementation to armnn_delegate.cpp Signed-off-by: Matthew Sloyan <matthew.sloyan@arm.com> Change-Id: Ifc92b6fb38dc370f3fb88a4daca56d457e74bc2e
Diffstat (limited to 'delegate/opaque')
-rw-r--r--delegate/opaque/include/armnn_delegate.hpp11
-rw-r--r--delegate/opaque/src/armnn_delegate.cpp8
-rw-r--r--delegate/opaque/src/test/ArmnnOpaqueDelegateTest.cpp42
-rw-r--r--delegate/opaque/src/test/DelegateTestInterpreter.cpp79
4 files changed, 131 insertions, 9 deletions
diff --git a/delegate/opaque/include/armnn_delegate.hpp b/delegate/opaque/include/armnn_delegate.hpp
index 5522699e26..3dda7c8631 100644
--- a/delegate/opaque/include/armnn_delegate.hpp
+++ b/delegate/opaque/include/armnn_delegate.hpp
@@ -77,17 +77,10 @@ private:
static int TfLiteArmnnOpaqueDelegateErrno(TfLiteOpaqueDelegate* delegate) { return 0; }
-
- /// In order for the delegate to be loaded by TfLite
+/// In order for the delegate to be loaded by TfLite
const TfLiteOpaqueDelegatePlugin* GetArmnnDelegatePluginApi();
-extern const TfLiteStableDelegate TFL_TheStableDelegate =
-{
- /*delegate_abi_version=*/ TFL_STABLE_DELEGATE_ABI_VERSION,
- /*delegate_name=*/ "ArmnnDelegatePlugin",
- /*delegate_version=*/ "1.0.0",
- /*delegate_plugin=*/ GetArmnnDelegatePluginApi()
-};
+extern const TfLiteStableDelegate TFL_TheStableDelegate;
/// ArmnnSubgraph class where parsing the nodes to ArmNN format and creating the ArmNN Graph
class ArmnnSubgraph
diff --git a/delegate/opaque/src/armnn_delegate.cpp b/delegate/opaque/src/armnn_delegate.cpp
index 2fbfda3628..cfaea01bbc 100644
--- a/delegate/opaque/src/armnn_delegate.cpp
+++ b/delegate/opaque/src/armnn_delegate.cpp
@@ -59,6 +59,14 @@
namespace armnnOpaqueDelegate
{
+const TfLiteStableDelegate TFL_TheStableDelegate =
+{
+ /*delegate_abi_version=*/ TFL_STABLE_DELEGATE_ABI_VERSION,
+ /*delegate_name=*/ "ArmnnDelegatePlugin",
+ /*delegate_version=*/ "1.0.0",
+ /*delegate_plugin=*/ GetArmnnDelegatePluginApi()
+};
+
ArmnnOpaqueDelegate::ArmnnOpaqueDelegate(armnnDelegate::DelegateOptions options)
: m_Options(std::move(options))
{
diff --git a/delegate/opaque/src/test/ArmnnOpaqueDelegateTest.cpp b/delegate/opaque/src/test/ArmnnOpaqueDelegateTest.cpp
new file mode 100644
index 0000000000..1635b65809
--- /dev/null
+++ b/delegate/opaque/src/test/ArmnnOpaqueDelegateTest.cpp
@@ -0,0 +1,42 @@
+//
+// Copyright © 2023 Arm Ltd and Contributors. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
+#include <doctest/doctest.h>
+
+#include <opaque/include/armnn_delegate.hpp>
+#include <opaque/include/Version.hpp>
+
+namespace armnnOpaqueDelegate
+{
+
+TEST_SUITE("ArmnnOpaqueDelegate")
+{
+
+TEST_CASE ("DelegateOptions_OpaqueDelegateDefault")
+{
+ // Check default options can be created
+ auto options = armnnOpaqueDelegate::TfLiteArmnnDelegateOptionsDefault();
+ armnnOpaqueDelegate::ArmnnOpaqueDelegate delegate(options);
+
+ // Check version returns correctly
+ auto version = delegate.GetVersion();
+ CHECK_EQ(version, OPAQUE_DELEGATE_VERSION);
+
+ auto* builder = delegate.GetDelegateBuilder();
+ CHECK(builder);
+
+ // Check Opaque delegate created
+ auto opaqueDelegate = armnnOpaqueDelegate::TfLiteArmnnOpaqueDelegateCreate(&options);
+ CHECK(opaqueDelegate);
+
+ // Check Opaque Delegate can be deleted
+ CHECK(opaqueDelegate->opaque_delegate_builder->data);
+ armnnOpaqueDelegate::TfLiteArmnnOpaqueDelegateDelete(opaqueDelegate);
+}
+
+}
+
+} // namespace armnnDelegate
diff --git a/delegate/opaque/src/test/DelegateTestInterpreter.cpp b/delegate/opaque/src/test/DelegateTestInterpreter.cpp
new file mode 100644
index 0000000000..04e6ad6208
--- /dev/null
+++ b/delegate/opaque/src/test/DelegateTestInterpreter.cpp
@@ -0,0 +1,79 @@
+//
+// Copyright © 2023 Arm Ltd and Contributors. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include <DelegateTestInterpreter.hpp>
+
+#include <armnn_delegate.hpp>
+
+#include <armnn/utility/IgnoreUnused.hpp>
+
+namespace delegateTestInterpreter
+{
+
+DelegateTestInterpreter::DelegateTestInterpreter(std::vector<char>& modelBuffer,
+ const std::vector<armnn::BackendId>& backends,
+ const std::string& customOp,
+ bool disableFallback)
+{
+ armnn::IgnoreUnused(backends);
+ armnn::IgnoreUnused(disableFallback);
+
+ TfLiteModel* tfLiteModel = delegateTestInterpreter::CreateTfLiteModel(modelBuffer);
+
+ TfLiteInterpreterOptions* options = delegateTestInterpreter::CreateTfLiteInterpreterOptions();
+ if (!customOp.empty())
+ {
+ options->mutable_op_resolver = delegateTestInterpreter::GenerateCustomOpResolver(customOp);
+ }
+
+ // Use default settings until options have been enabled.
+ auto armnnDelegate = armnnOpaqueDelegate::TfLiteArmnnOpaqueDelegateCreate(nullptr);
+ TfLiteInterpreterOptionsAddDelegate(options, armnnDelegate);
+
+ m_TfLiteDelegate = armnnDelegate;
+ m_TfLiteInterpreter = TfLiteInterpreterCreate(tfLiteModel, options);
+
+ // The options and model can be deleted after the interpreter is created.
+ TfLiteInterpreterOptionsDelete(options);
+ TfLiteModelDelete(tfLiteModel);
+}
+
+DelegateTestInterpreter::DelegateTestInterpreter(std::vector<char>& modelBuffer,
+ const armnnDelegate::DelegateOptions& delegateOptions,
+ const std::string& customOp)
+{
+ armnn::IgnoreUnused(delegateOptions);
+
+ TfLiteModel* tfLiteModel = delegateTestInterpreter::CreateTfLiteModel(modelBuffer);
+
+ TfLiteInterpreterOptions* options = delegateTestInterpreter::CreateTfLiteInterpreterOptions();
+ if (!customOp.empty())
+ {
+ options->mutable_op_resolver = delegateTestInterpreter::GenerateCustomOpResolver(customOp);
+ }
+
+ // Use default settings until options have been enabled.
+ auto armnnDelegate = armnnOpaqueDelegate::TfLiteArmnnOpaqueDelegateCreate(nullptr);
+ TfLiteInterpreterOptionsAddDelegate(options, armnnDelegate);
+
+ m_TfLiteDelegate = armnnDelegate;
+ m_TfLiteInterpreter = TfLiteInterpreterCreate(tfLiteModel, options);
+
+ // The options and model can be deleted after the interpreter is created.
+ TfLiteInterpreterOptionsDelete(options);
+ TfLiteModelDelete(tfLiteModel);
+}
+
+void DelegateTestInterpreter::Cleanup()
+{
+ TfLiteInterpreterDelete(m_TfLiteInterpreter);
+
+ if (m_TfLiteDelegate)
+ {
+ armnnOpaqueDelegate::TfLiteArmnnOpaqueDelegateDelete(static_cast<TfLiteOpaqueDelegate*>(m_TfLiteDelegate));
+ }
+}
+
+} // anonymous namespace \ No newline at end of file