From 870b96c643388ae88dd4245b9169f526d6a8d49e Mon Sep 17 00:00:00 2001 From: Jim Flynn Date: Fri, 25 Mar 2022 21:24:56 +0000 Subject: IVGCVSW-6707 Enables a bare metal compile Change-Id: Icc2f83c5f27f413758fee3e5c1445e9fc44f42c8 Signed-off-by: Jim Flynn --- src/armnn/AsyncExecutionCallback.cpp | 16 +++++++++++++--- src/armnn/AsyncExecutionCallback.hpp | 17 +++++++++++++---- src/armnn/LoadedNetwork.cpp | 15 +++++++++++++-- src/armnn/LoadedNetwork.hpp | 8 +++++++- src/armnn/Runtime.cpp | 6 ++++++ src/armnn/Runtime.hpp | 4 ++++ src/armnn/Threadpool.cpp | 4 +++- src/armnn/Utils.cpp | 10 +++++----- 8 files changed, 64 insertions(+), 16 deletions(-) (limited to 'src/armnn') diff --git a/src/armnn/AsyncExecutionCallback.cpp b/src/armnn/AsyncExecutionCallback.cpp index 2973e2d891..5b87927af2 100644 --- a/src/armnn/AsyncExecutionCallback.cpp +++ b/src/armnn/AsyncExecutionCallback.cpp @@ -14,14 +14,18 @@ namespace experimental void AsyncExecutionCallback::Notify(armnn::Status status, InferenceTimingPair timeTaken) { { +#if !defined(ARMNN_DISABLE_THREADS) std::lock_guard hold(m_Mutex); +#endif // store results and mark as notified m_Status = status; m_StartTime = timeTaken.first; m_EndTime = timeTaken.second; m_NotificationQueue.push(m_InferenceId); } +#if !defined(ARMNN_DISABLE_THREADS) m_Condition.notify_all(); +#endif } armnn::Status AsyncExecutionCallback::GetStatus() const @@ -41,7 +45,12 @@ HighResolutionClock AsyncExecutionCallback::GetEndTime() const std::shared_ptr AsyncCallbackManager::GetNewCallback() { - auto cb = std::make_unique(m_NotificationQueue, m_Mutex, m_Condition); + auto cb = std::make_unique(m_NotificationQueue +#if !defined(ARMNN_DISABLE_THREADS) + , m_Mutex + , m_Condition +#endif + ); InferenceId id = cb->GetInferenceId(); m_Callbacks.insert({id, std::move(cb)}); @@ -50,10 +59,11 @@ std::shared_ptr AsyncCallbackManager::GetNewCallback() std::shared_ptr AsyncCallbackManager::GetNotifiedCallback() { +#if !defined(ARMNN_DISABLE_THREADS) std::unique_lock lock(m_Mutex); m_Condition.wait(lock, [this] { return !m_NotificationQueue.empty(); }); - +#endif InferenceId id = m_NotificationQueue.front(); m_NotificationQueue.pop(); @@ -64,4 +74,4 @@ std::shared_ptr AsyncCallbackManager::GetNotifiedCallbac } // namespace experimental -} // namespace armnn \ No newline at end of file +} // namespace armnn diff --git a/src/armnn/AsyncExecutionCallback.hpp b/src/armnn/AsyncExecutionCallback.hpp index 2ff73b3efb..9eab06b4fa 100644 --- a/src/armnn/AsyncExecutionCallback.hpp +++ b/src/armnn/AsyncExecutionCallback.hpp @@ -28,12 +28,17 @@ private: static InferenceId nextID; public: - AsyncExecutionCallback(std::queue& notificationQueue, - std::mutex& mutex, - std::condition_variable& condition) + AsyncExecutionCallback(std::queue& notificationQueue +#if !defined(ARMNN_DISABLE_THREADS) + , std::mutex& mutex + , std::condition_variable& condition +#endif + ) : m_NotificationQueue(notificationQueue) +#if !defined(ARMNN_DISABLE_THREADS) , m_Mutex(mutex) , m_Condition(condition) +#endif , m_InferenceId(++nextID) {} @@ -53,8 +58,10 @@ public: private: std::queue& m_NotificationQueue; +#if !defined(ARMNN_DISABLE_THREADS) std::mutex& m_Mutex; std::condition_variable& m_Condition; +#endif HighResolutionClock m_StartTime; HighResolutionClock m_EndTime; @@ -73,12 +80,14 @@ public: std::shared_ptr GetNotifiedCallback(); private: +#if !defined(ARMNN_DISABLE_THREADS) std::mutex m_Mutex; std::condition_variable m_Condition; +#endif std::unordered_map> m_Callbacks; std::queue m_NotificationQueue; }; } // namespace experimental -} // namespace armnn \ No newline at end of file +} // namespace armnn diff --git a/src/armnn/LoadedNetwork.cpp b/src/armnn/LoadedNetwork.cpp index 0e577354f0..f10fb89e15 100644 --- a/src/armnn/LoadedNetwork.cpp +++ b/src/armnn/LoadedNetwork.cpp @@ -1087,13 +1087,18 @@ void LoadedNetwork::EnqueueOutput(const BindableLayer& layer, ITensorHandle* ten } } -void LoadedNetwork::AllocateWorkingMemory(std::lock_guard& lock) +void LoadedNetwork::AllocateWorkingMemory( +#if !defined(ARMNN_DISABLE_THREADS) + std::lock_guard& lock +#endif + ) { ARMNN_SCOPED_PROFILING_EVENT(Compute::Undefined, "Working Memory Allocation"); +#if !defined(ARMNN_DISABLE_THREADS) // this unused parameter makes sure we can only call this function with a valid lock IgnoreUnused(lock); - +#endif if (m_IsWorkingMemAllocated) { return; @@ -1122,7 +1127,9 @@ void LoadedNetwork::AllocateWorkingMemory(std::lock_guard& lock) void LoadedNetwork::FreeWorkingMemory() { +#if !defined(ARMNN_DISABLE_THREADS) std::lock_guard lockGuard(m_WorkingMemMutex); +#endif if (!m_IsWorkingMemAllocated) { @@ -1159,8 +1166,12 @@ bool LoadedNetwork::Execute(std::unique_ptr& timelineUti try { +#if !defined(ARMNN_DISABLE_THREADS) std::lock_guard lockGuard(m_WorkingMemMutex); AllocateWorkingMemory(lockGuard); +#else + AllocateWorkingMemory(); +#endif ProfilingDynamicGuid workloadInferenceID(0); auto ExecuteQueue = [&timelineUtils, &workloadInferenceID, &inferenceGuid](WorkloadQueue& queue) diff --git a/src/armnn/LoadedNetwork.hpp b/src/armnn/LoadedNetwork.hpp index 829405516a..45f94cbec7 100644 --- a/src/armnn/LoadedNetwork.hpp +++ b/src/armnn/LoadedNetwork.hpp @@ -102,7 +102,11 @@ public: private: - void AllocateWorkingMemory(std::lock_guard& lock); + void AllocateWorkingMemory( +#if !defined(ARMNN_DISABLE_THREADS) + std::lock_guard& lock +#endif + ); void AllocateAndExecuteConstantWorkloads(); void AllocateAndExecuteConstantWorkloadsAsync(); @@ -151,7 +155,9 @@ private: WorkloadQueue m_WorkloadQueue; WorkloadQueue m_OutputQueue; +#if !defined(ARMNN_DISABLE_THREADS) mutable std::mutex m_WorkingMemMutex; +#endif bool m_IsWorkingMemAllocated = false; diff --git a/src/armnn/Runtime.cpp b/src/armnn/Runtime.cpp index 657c90735c..75b1ee8179 100644 --- a/src/armnn/Runtime.cpp +++ b/src/armnn/Runtime.cpp @@ -205,7 +205,9 @@ Status RuntimeImpl::LoadNetwork(NetworkId& networkIdOut, } { +#if !defined(ARMNN_DISABLE_THREADS) std::lock_guard lockGuard(m_Mutex); +#endif // Stores the network m_LoadedNetworks[networkIdOut] = std::move(loadedNetwork); @@ -242,7 +244,9 @@ Status RuntimeImpl::UnloadNetwork(NetworkId networkId) std::unique_ptr timelineUtils = arm::pipe::TimelineUtilityMethods::GetTimelineUtils(*m_ProfilingService.get()); { +#if !defined(ARMNN_DISABLE_THREADS) std::lock_guard lockGuard(m_Mutex); +#endif // If timeline recording is on mark the Network end of life if (timelineUtils) @@ -586,7 +590,9 @@ RuntimeImpl::~RuntimeImpl() LoadedNetwork* RuntimeImpl::GetLoadedNetworkPtr(NetworkId networkId) const { +#if !defined(ARMNN_DISABLE_THREADS) std::lock_guard lockGuard(m_Mutex); +#endif return m_LoadedNetworks.at(networkId).get(); } diff --git a/src/armnn/Runtime.hpp b/src/armnn/Runtime.hpp index 51a8afff71..376cdbc000 100644 --- a/src/armnn/Runtime.hpp +++ b/src/armnn/Runtime.hpp @@ -126,7 +126,9 @@ private: template void LoadedNetworkFuncSafe(NetworkId networkId, Func f) { +#if !defined(ARMNN_DISABLE_THREADS) std::lock_guard lockGuard(m_Mutex); +#endif auto iter = m_LoadedNetworks.find(networkId); if (iter != m_LoadedNetworks.end()) { @@ -137,7 +139,9 @@ private: /// Loads any available/compatible dynamic backend in the runtime. void LoadDynamicBackends(const std::string& overrideBackendPath); +#if !defined(ARMNN_DISABLE_THREADS) mutable std::mutex m_Mutex; +#endif /// Map of Loaded Networks with associated GUID as key LoadedNetworks m_LoadedNetworks; diff --git a/src/armnn/Threadpool.cpp b/src/armnn/Threadpool.cpp index 4289a4b1b7..df4ff84fb5 100644 --- a/src/armnn/Threadpool.cpp +++ b/src/armnn/Threadpool.cpp @@ -2,7 +2,7 @@ // Copyright © 2021 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // - +#if !defined(ARMNN_DISABLE_THREADS) #include @@ -204,3 +204,5 @@ void Threadpool::ProcessExecPriorities(uint32_t index) } // namespace experimental } // namespace armnn + +#endif diff --git a/src/armnn/Utils.cpp b/src/armnn/Utils.cpp index b9f948aea2..33d654f484 100644 --- a/src/armnn/Utils.cpp +++ b/src/armnn/Utils.cpp @@ -6,7 +6,7 @@ #include "armnn/Utils.hpp" #include "armnn/Version.hpp" -#if !defined(BARE_METAL) && (defined(__arm__) || defined(__aarch64__)) +#if !defined(ARMNN_BUILD_BARE_METAL) && (defined(__arm__) || defined(__aarch64__)) #include #include @@ -36,11 +36,11 @@ static DefaultLoggingConfiguration g_DefaultLoggingConfiguration; // Detect the presence of Neon on Linux bool NeonDetected() { -#if !defined(BARE_METAL) && (defined(__arm__) || defined(__aarch64__)) +#if !defined(ARMNN_BUILD_BARE_METAL) && (defined(__arm__) || defined(__aarch64__)) auto hwcaps= getauxval(AT_HWCAP); #endif -#if !defined(BARE_METAL) && defined(__aarch64__) +#if !defined(ARMNN_BUILD_BARE_METAL) && defined(__aarch64__) if (hwcaps & HWCAP_ASIMD) { @@ -54,7 +54,7 @@ bool NeonDetected() } #endif -#if !defined(BARE_METAL) && defined(__arm__) +#if !defined(ARMNN_BUILD_BARE_METAL) && defined(__arm__) if (hwcaps & HWCAP_NEON) { @@ -79,4 +79,4 @@ const std::string GetVersion() return ARMNN_VERSION; } -} // namespace armnn \ No newline at end of file +} // namespace armnn -- cgit v1.2.1