From 5446a4d6d02002515fc58fafe33d74ae6dca5787 Mon Sep 17 00:00:00 2001 From: Mike Kelly Date: Fri, 20 Jan 2023 15:51:05 +0000 Subject: IVGCVSW-7297 When creating multiple Executors only the last one works fine * All ArmNNExecutors now share a single IRuntime. * All armnn_delegates now share a single IRuntime. * Increased delegate major version. Signed-off-by: Mike Kelly Change-Id: I95cbdc32655ec0beb476dbb2d60f1a0209df8f04 --- delegate/include/Version.hpp | 2 +- delegate/include/armnn_delegate.hpp | 14 ++++++++++++-- delegate/src/armnn_delegate.cpp | 13 ++++++------- tests/ExecuteNetwork/ArmNNExecutor.cpp | 7 +++++-- tests/ExecuteNetwork/ArmNNExecutor.hpp | 14 ++++++++++++-- tests/ExecuteNetwork/TfliteExecutor.cpp | 2 +- 6 files changed, 37 insertions(+), 15 deletions(-) diff --git a/delegate/include/Version.hpp b/delegate/include/Version.hpp index 36d8fb54af..5550278414 100644 --- a/delegate/include/Version.hpp +++ b/delegate/include/Version.hpp @@ -13,7 +13,7 @@ namespace armnnDelegate #define STRINGIFY_MACRO(s) #s // ArmNN Delegate version components -#define DELEGATE_MAJOR_VERSION 27 +#define DELEGATE_MAJOR_VERSION 28 #define DELEGATE_MINOR_VERSION 0 #define DELEGATE_PATCH_VERSION 0 diff --git a/delegate/include/armnn_delegate.hpp b/delegate/include/armnn_delegate.hpp index 79ab4bf79c..159d590423 100644 --- a/delegate/include/armnn_delegate.hpp +++ b/delegate/include/armnn_delegate.hpp @@ -1,5 +1,5 @@ // -// Copyright © 2020 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2020-2023 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -64,6 +64,16 @@ public: static const std::string GetVersion(); private: + /** + * Returns a pointer to the armnn::IRuntime* this will be shared by all armnn_delegates. + */ + armnn::IRuntime* GetRuntime(const armnn::IRuntime::CreationOptions& options) + { + static armnn::IRuntimePtr instance = armnn::IRuntime::Create(options); + // Instantiated on first use. + return instance.get(); + } + TfLiteDelegate m_Delegate = { reinterpret_cast(this), // .data_ DoPrepare, // .Prepare @@ -74,7 +84,7 @@ private: }; /// ArmNN Runtime pointer - armnn::IRuntimePtr m_Runtime; + armnn::IRuntime* m_Runtime; /// ArmNN Delegate Options armnnDelegate::DelegateOptions m_Options; }; diff --git a/delegate/src/armnn_delegate.cpp b/delegate/src/armnn_delegate.cpp index 1557ec92b6..b2d9c67c7b 100644 --- a/delegate/src/armnn_delegate.cpp +++ b/delegate/src/armnn_delegate.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2022-2023 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2020-2023 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -133,17 +133,16 @@ TfLiteStatus DoPrepare(TfLiteContext* tfLiteContext, TfLiteDelegate* tfLiteDeleg } Delegate::Delegate(armnnDelegate::DelegateOptions options) - : m_Runtime(nullptr, nullptr), - m_Options(std::move(options)) + : m_Options(std::move(options)) { // Configures logging for ARMNN if (m_Options.IsLoggingEnabled()) { armnn::ConfigureLogging(true, true, m_Options.GetLoggingSeverity()); } - // Create ArmNN Runtime - m_Runtime = armnn::IRuntime::Create(m_Options.GetRuntimeOptions()); - + // Create/Get the static ArmNN Runtime. Note that the m_Runtime will be shared by all armnn_delegate + // instances so the RuntimeOptions cannot be altered for different armnn_delegate instances. + m_Runtime = GetRuntime(m_Options.GetRuntimeOptions()); std::vector backends; if (m_Runtime) { @@ -463,7 +462,7 @@ ArmnnSubgraph* ArmnnSubgraph::Create(TfLiteContext* tfLiteContext, << std::fixed << armnn::GetTimeDuration(startTime).count() << " ms\n"; // Create a new SubGraph with networkId and runtime - return new ArmnnSubgraph(networkId, delegate->m_Runtime.get(), inputBindings, outputBindings); + return new ArmnnSubgraph(networkId, delegate->m_Runtime, inputBindings, outputBindings); } TfLiteStatus ArmnnSubgraph::Prepare(TfLiteContext* tfLiteContext) diff --git a/tests/ExecuteNetwork/ArmNNExecutor.cpp b/tests/ExecuteNetwork/ArmNNExecutor.cpp index 139da5f830..730c072836 100644 --- a/tests/ExecuteNetwork/ArmNNExecutor.cpp +++ b/tests/ExecuteNetwork/ArmNNExecutor.cpp @@ -19,7 +19,10 @@ ArmNNExecutor::ArmNNExecutor(const ExecuteNetworkParams& params, armnn::IRuntime { runtimeOptions.m_EnableGpuProfiling = params.m_EnableProfiling; runtimeOptions.m_DynamicBackendsPath = params.m_DynamicBackendsPath; - m_Runtime = armnn::IRuntime::Create(runtimeOptions); + + // Create/Get the static ArmNN Runtime. Note that the m_Runtime will be shared by all ArmNNExecutor + // instances so the RuntimeOptions cannot be altered for different ArmNNExecutor instances. + m_Runtime = GetRuntime(runtimeOptions); auto parser = CreateParser(); auto network = parser->CreateNetwork(m_Params); @@ -100,7 +103,7 @@ void ArmNNExecutor::ExecuteAsync() } threadpool = std::make_unique(m_Params.m_ThreadPoolSize, - m_Runtime.get(), + m_Runtime, memHandles); ARMNN_LOG(info) << "Asynchronous Execution with Arm NN thread pool... \n"; diff --git a/tests/ExecuteNetwork/ArmNNExecutor.hpp b/tests/ExecuteNetwork/ArmNNExecutor.hpp index c4adc9e120..b0b29deffd 100644 --- a/tests/ExecuteNetwork/ArmNNExecutor.hpp +++ b/tests/ExecuteNetwork/ArmNNExecutor.hpp @@ -1,5 +1,5 @@ // -// Copyright © 2022 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2022-2023 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -45,6 +45,16 @@ public: private: + /** + * Returns a pointer to the armnn::IRuntime* this will be shared by all ArmNNExecutors. + */ + armnn::IRuntime* GetRuntime(const armnn::IRuntime::CreationOptions& options) + { + static armnn::IRuntimePtr instance = armnn::IRuntime::Create(options); + // Instantiated on first use. + return instance.get(); + } + struct IParser; struct IOInfo; struct IOStorage; @@ -101,7 +111,7 @@ private: std::vector m_OutputTensorsVec; std::vector> m_ImportedInputIds; std::vector> m_ImportedOutputIds; - std::shared_ptr m_Runtime; + armnn::IRuntime* m_Runtime; armnn::NetworkId m_NetworkId; ExecuteNetworkParams m_Params; diff --git a/tests/ExecuteNetwork/TfliteExecutor.cpp b/tests/ExecuteNetwork/TfliteExecutor.cpp index 41716ffb93..6a799548bf 100644 --- a/tests/ExecuteNetwork/TfliteExecutor.cpp +++ b/tests/ExecuteNetwork/TfliteExecutor.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2022 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2022-2023 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // -- cgit v1.2.1