aboutsummaryrefslogtreecommitdiff
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
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
-rw-r--r--delegate/CMakeLists.txt98
-rw-r--r--delegate/classic/src/test/ArmnnClassicDelegateTest.cpp (renamed from delegate/test/ArmnnDelegateTest.cpp)2
-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
6 files changed, 194 insertions, 46 deletions
diff --git a/delegate/CMakeLists.txt b/delegate/CMakeLists.txt
index 73df68fc4c..f071c0e8fe 100644
--- a/delegate/CMakeLists.txt
+++ b/delegate/CMakeLists.txt
@@ -120,14 +120,15 @@ if (BUILD_OPAQUE_DELEGATE)
set_target_properties(armnnOpaqueDelegate PROPERTIES VERSION ${OPAQUE_DELEGATE_LIB_VERSION} SOVERSION ${OPAQUE_DELEGATE_LIB_SOVERSION})
endif()
-if(BUILD_UNIT_TESTS AND BUILD_CLASSIC_DELEGATE)
- set(armnnDelegate_unittest_sources)
- list(APPEND armnnDelegate_unittest_sources
+if(BUILD_UNIT_TESTS)
+ set(commonDelegate_unittest_sources)
+ list(APPEND commonDelegate_unittest_sources
+ common/src/test/DelegateTestInterpreter.hpp
+ common/src/test/DelegateTestInterpreterUtils.hpp
test/ActivationTest.cpp
test/ActivationTestHelper.hpp
test/ArgMinMaxTest.cpp
test/ArgMinMaxTestHelper.hpp
- test/ArmnnDelegateTest.cpp
test/BatchMatMulTest.cpp
test/BatchMatMulTestHelper.hpp
test/BatchSpaceTest.cpp
@@ -143,9 +144,6 @@ if(BUILD_UNIT_TESTS AND BUILD_CLASSIC_DELEGATE)
test/ConvolutionTestHelper.hpp
test/DelegateOptionsTest.cpp
test/DelegateOptionsTestHelper.hpp
- classic/src/test/DelegateTestInterpreter.cpp
- common/src/test/DelegateTestInterpreter.hpp
- common/src/test/DelegateTestInterpreterUtils.hpp
test/DepthwiseConvolution2dTest.cpp
test/ElementwiseBinaryTest.cpp
test/ElementwiseBinaryTestHelper.hpp
@@ -207,48 +205,76 @@ if(BUILD_UNIT_TESTS AND BUILD_CLASSIC_DELEGATE)
test/UnpackTest.cpp
test/UnpackTestHelper.hpp)
- # There's a known Android NDK bug which causes a subset of NeonLayerTests to
- # fail. We'll exclude these tests in NeonLayerTests_NDK_Bug.cpp if we're doing
- # a debug build and NDK is less than r21.
- # https://github.com/android/ndk/issues/1135
-
- # Default to always including these tests.
- set(INCLUDE_NDK_BUG_TESTS "ON")
- # Reconsider if we in a debug build.
- string( TOLOWER ${CMAKE_BUILD_TYPE} BUILD_TYPE_LOWERCASE )
- if ( NOT BUILD_TYPE_LOWERCASE STREQUAL "release" )
- message("CMAKE:: BUILD TYPE IS ${CMAKE_BUILD_TYPE}")
- # And NDK_VERSION has been set.
- if ( DEFINED NDK_VERSION )
- message("CMAKE:: NDK DEFINED")
- # And the version is less than r21.
- if ( ${NDK_VERSION} STRLESS "r21" )
- message("CMAKE:: BUG TESTS OFF")
- set(INCLUDE_NDK_BUG_TESTS "OFF")
- endif()
+ # There's a known Android NDK bug which causes a subset of NeonLayerTests to
+ # fail. We'll exclude these tests in NeonLayerTests_NDK_Bug.cpp if we're doing
+ # a debug build and NDK is less than r21.
+ # https://github.com/android/ndk/issues/1135
+
+ # Default to always including these tests.
+ set(INCLUDE_NDK_BUG_TESTS "ON")
+ # Reconsider if we in a debug build.
+ string( TOLOWER ${CMAKE_BUILD_TYPE} BUILD_TYPE_LOWERCASE )
+ if ( NOT BUILD_TYPE_LOWERCASE STREQUAL "release" )
+ message("CMAKE:: BUILD TYPE IS ${CMAKE_BUILD_TYPE}")
+ # And NDK_VERSION has been set.
+ if ( DEFINED NDK_VERSION )
+ message("CMAKE:: NDK DEFINED")
+ # And the version is less than r21.
+ if ( ${NDK_VERSION} STRLESS "r21" )
+ message("CMAKE:: BUG TESTS OFF")
+ set(INCLUDE_NDK_BUG_TESTS "OFF")
endif()
endif()
+ endif()
- if ( INCLUDE_NDK_BUG_TESTS STREQUAL "ON" )
- list(APPEND armnnDelegate_unittest_sources
- test/NeonDelegateTests_NDK_Issue.cpp
- )
- else()
+ if ( INCLUDE_NDK_BUG_TESTS STREQUAL "ON" )
+ list(APPEND commonDelegate_unittest_sources
+ test/NeonDelegateTests_NDK_Issue.cpp)
+ endif()
- endif()
- add_executable(DelegateUnitTests ${armnnDelegate_unittest_sources})
+ if (BUILD_CLASSIC_DELEGATE)
+ set(classicDelegate_unittest_sources)
+ list(APPEND classicDelegate_unittest_sources
+ classic/src/test/ArmnnClassicDelegateTest.cpp
+ classic/src/test/DelegateTestInterpreter.cpp)
+
+ add_executable(DelegateUnitTests ${commonDelegate_unittest_sources} ${classicDelegate_unittest_sources})
target_include_directories(DelegateUnitTests SYSTEM PRIVATE "${TF_LITE_SCHEMA_INCLUDE_PATH}")
target_include_directories(DelegateUnitTests SYSTEM PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/common/src/test")
+ target_include_directories(DelegateUnitTests PUBLIC ${PROJECT_SOURCE_DIR})
# Add half library from armnn third-party libraries
target_link_libraries(DelegateUnitTests PRIVATE thirdparty_headers)
-
target_link_libraries(DelegateUnitTests PRIVATE armnnDelegate)
- target_include_directories(DelegateUnitTests PUBLIC ${PROJECT_SOURCE_DIR})
target_link_libraries(DelegateUnitTests PRIVATE Armnn::armnnUtils)
-
target_link_libraries(DelegateUnitTests PRIVATE profiling_library_headers)
+ endif()
+
+ if (BUILD_OPAQUE_DELEGATE)
+ set(opaqueDelegate_unittest_sources)
+ list(APPEND opaqueDelegate_unittest_sources
+ common/src/test/DelegateTestInterpreter.hpp
+ common/src/test/DelegateTestInterpreterUtils.hpp
+ opaque/src/test/ArmnnOpaqueDelegateTest.cpp
+ opaque/src/test/DelegateTestInterpreter.cpp
+ test/TestUtils.hpp
+ test/TestUtils.cpp)
+
+ # Until all operators are supported, we have to add tests one by one above to opaqueDelegate_unittest_sources.
+ # After we add can add commonDelegate_unittest_sources to the add_executable below.
+ add_executable(OpaqueDelegateUnitTests ${opaqueDelegate_unittest_sources})
+
+ target_include_directories(OpaqueDelegateUnitTests SYSTEM PRIVATE "${TF_LITE_SCHEMA_INCLUDE_PATH}")
+ target_include_directories(OpaqueDelegateUnitTests SYSTEM PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/common/src/test")
+ target_include_directories(OpaqueDelegateUnitTests PUBLIC ${PROJECT_SOURCE_DIR})
+
+ # Add half library from armnn third-party libraries
+ target_link_libraries(OpaqueDelegateUnitTests PRIVATE thirdparty_headers)
+ target_link_libraries(OpaqueDelegateUnitTests PRIVATE armnnOpaqueDelegate)
+ target_link_libraries(OpaqueDelegateUnitTests PRIVATE Armnn::armnnUtils)
+ target_link_libraries(OpaqueDelegateUnitTests PRIVATE profiling_library_headers)
+ endif()
endif()
if(BUILD_DELEGATE_JNI_INTERFACE)
diff --git a/delegate/test/ArmnnDelegateTest.cpp b/delegate/classic/src/test/ArmnnClassicDelegateTest.cpp
index bd5ed6059c..26acfe91f1 100644
--- a/delegate/test/ArmnnDelegateTest.cpp
+++ b/delegate/classic/src/test/ArmnnClassicDelegateTest.cpp
@@ -1,5 +1,5 @@
//
-// Copyright © 2020, 2023 Arm Ltd and Contributors. All rights reserved.
+// Copyright © 2023 Arm Ltd and Contributors. All rights reserved.
// SPDX-License-Identifier: MIT
//
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