aboutsummaryrefslogtreecommitdiff
path: root/src/armnn
diff options
context:
space:
mode:
authorJim Flynn <jim.flynn@arm.com>2022-03-25 21:24:56 +0000
committerJim Flynn <jim.flynn@arm.com>2022-04-11 14:24:34 +0100
commit870b96c643388ae88dd4245b9169f526d6a8d49e (patch)
tree44a675f1eecdbf0eff40dc4ee623e0a2f03b2f96 /src/armnn
parentb99799bda8fe0fb0a755eebbe2d02dbb74507c9f (diff)
downloadarmnn-870b96c643388ae88dd4245b9169f526d6a8d49e.tar.gz
IVGCVSW-6707 Enables a bare metal compile
Change-Id: Icc2f83c5f27f413758fee3e5c1445e9fc44f42c8 Signed-off-by: Jim Flynn <jim.flynn@arm.com>
Diffstat (limited to 'src/armnn')
-rw-r--r--src/armnn/AsyncExecutionCallback.cpp16
-rw-r--r--src/armnn/AsyncExecutionCallback.hpp17
-rw-r--r--src/armnn/LoadedNetwork.cpp15
-rw-r--r--src/armnn/LoadedNetwork.hpp8
-rw-r--r--src/armnn/Runtime.cpp6
-rw-r--r--src/armnn/Runtime.hpp4
-rw-r--r--src/armnn/Threadpool.cpp4
-rw-r--r--src/armnn/Utils.cpp10
8 files changed, 64 insertions, 16 deletions
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<std::mutex> 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<AsyncExecutionCallback> AsyncCallbackManager::GetNewCallback()
{
- auto cb = std::make_unique<AsyncExecutionCallback>(m_NotificationQueue, m_Mutex, m_Condition);
+ auto cb = std::make_unique<AsyncExecutionCallback>(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<AsyncExecutionCallback> AsyncCallbackManager::GetNewCallback()
std::shared_ptr<AsyncExecutionCallback> AsyncCallbackManager::GetNotifiedCallback()
{
+#if !defined(ARMNN_DISABLE_THREADS)
std::unique_lock<std::mutex> 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<AsyncExecutionCallback> 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<InferenceId>& notificationQueue,
- std::mutex& mutex,
- std::condition_variable& condition)
+ AsyncExecutionCallback(std::queue<InferenceId>& 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<InferenceId>& 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<AsyncExecutionCallback> GetNotifiedCallback();
private:
+#if !defined(ARMNN_DISABLE_THREADS)
std::mutex m_Mutex;
std::condition_variable m_Condition;
+#endif
std::unordered_map<InferenceId, std::shared_ptr<AsyncExecutionCallback>> m_Callbacks;
std::queue<InferenceId> 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<std::mutex>& lock)
+void LoadedNetwork::AllocateWorkingMemory(
+#if !defined(ARMNN_DISABLE_THREADS)
+ std::lock_guard<std::mutex>& 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<std::mutex>& lock)
void LoadedNetwork::FreeWorkingMemory()
{
+#if !defined(ARMNN_DISABLE_THREADS)
std::lock_guard<std::mutex> lockGuard(m_WorkingMemMutex);
+#endif
if (!m_IsWorkingMemAllocated)
{
@@ -1159,8 +1166,12 @@ bool LoadedNetwork::Execute(std::unique_ptr<TimelineUtilityMethods>& timelineUti
try
{
+#if !defined(ARMNN_DISABLE_THREADS)
std::lock_guard<std::mutex> 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<std::mutex>& lock);
+ void AllocateWorkingMemory(
+#if !defined(ARMNN_DISABLE_THREADS)
+ std::lock_guard<std::mutex>& 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<std::mutex> 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<arm::pipe::TimelineUtilityMethods> timelineUtils =
arm::pipe::TimelineUtilityMethods::GetTimelineUtils(*m_ProfilingService.get());
{
+#if !defined(ARMNN_DISABLE_THREADS)
std::lock_guard<std::mutex> 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<std::mutex> 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<typename Func>
void LoadedNetworkFuncSafe(NetworkId networkId, Func f)
{
+#if !defined(ARMNN_DISABLE_THREADS)
std::lock_guard<std::mutex> 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 <armnn/Threadpool.hpp>
@@ -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 <sys/auxv.h>
#include <asm/hwcap.h>
@@ -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