aboutsummaryrefslogtreecommitdiff
path: root/src
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
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')
-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
-rwxr-xr-xsrc/armnnSerializer/CMakeLists.txt6
-rwxr-xr-xsrc/armnnTestUtils/CMakeLists.txt14
-rw-r--r--src/armnnUtils/Filesystem.cpp7
-rw-r--r--src/backends/backendsCommon/DynamicBackendUtils.cpp8
-rw-r--r--src/backends/backendsCommon/DynamicBackendUtils.hpp2
-rw-r--r--src/backends/dynamic/reference/CMakeLists.txt5
-rw-r--r--src/backends/reference/workloads/ConvImpl.cpp2
15 files changed, 102 insertions, 22 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
diff --git a/src/armnnSerializer/CMakeLists.txt b/src/armnnSerializer/CMakeLists.txt
index 9c90af2e11..582013178d 100755
--- a/src/armnnSerializer/CMakeLists.txt
+++ b/src/armnnSerializer/CMakeLists.txt
@@ -29,7 +29,11 @@ if(BUILD_ARMNN_SERIALIZER)
../armnnDeserializer/Deserializer.cpp
)
- add_library_ex(armnnSerializer SHARED ${armnn_serializer_sources})
+ if(BUILD_BARE_METAL)
+ add_library_ex(armnnSerializer STATIC ${armnn_serializer_sources})
+ else()
+ add_library_ex(armnnSerializer SHARED ${armnn_serializer_sources})
+ endif()
include_directories(SYSTEM "${FLATBUFFERS_INCLUDE_PATH}")
set_target_properties(armnnSerializer PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
diff --git a/src/armnnTestUtils/CMakeLists.txt b/src/armnnTestUtils/CMakeLists.txt
index b90a71e66e..3f6fb415a2 100755
--- a/src/armnnTestUtils/CMakeLists.txt
+++ b/src/armnnTestUtils/CMakeLists.txt
@@ -29,11 +29,21 @@ list(APPEND armnnTestUtils_sources
TensorCopyUtils.cpp
TestUtils.cpp
TestUtils.hpp
+ )
+
+if(NOT BUILD_BARE_METAL)
+list(APPEND armnnTestUtils_sources
UnitTests.cpp
UnitTests.hpp
)
+endif()
+
-add_library_ex(armnnTestUtils SHARED ${armnnTestUtils_sources})
+if(BUILD_BARE_METAL)
+ add_library_ex(armnnTestUtils STATIC ${armnnTestUtils_sources})
+else()
+ add_library_ex(armnnTestUtils SHARED ${armnnTestUtils_sources})
+endif()
set_target_properties(armnnTestUtils PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
@@ -59,4 +69,4 @@ install(TARGETS armnnTestUtils
add_library(Armnn::armnnTestUtils ALIAS armnnTestUtils)
-set_target_properties(armnnTestUtils PROPERTIES VERSION ${ARMNN_TEST_UTILS_LIB_VERSION} SOVERSION ${ARMNN_TEST_UTILS_LIB_SOVERSION}) \ No newline at end of file
+set_target_properties(armnnTestUtils PROPERTIES VERSION ${ARMNN_TEST_UTILS_LIB_VERSION} SOVERSION ${ARMNN_TEST_UTILS_LIB_SOVERSION})
diff --git a/src/armnnUtils/Filesystem.cpp b/src/armnnUtils/Filesystem.cpp
index 1f636d895f..d917e508d5 100644
--- a/src/armnnUtils/Filesystem.cpp
+++ b/src/armnnUtils/Filesystem.cpp
@@ -2,6 +2,7 @@
// Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
// SPDX-License-Identifier: MIT
//
+#if !defined(ARMNN_DISABLE_FILESYSTEM)
#include <armnnUtils/Filesystem.hpp>
@@ -31,5 +32,7 @@ fs::path NamedTempFile(const char* fileName)
return namedTempFile;
}
-}
-}
+} // namespace armnnUtils
+} // namespace Filesystem
+
+#endif // !defined(ARMNN_DISABLE_FILESYSTEM)
diff --git a/src/backends/backendsCommon/DynamicBackendUtils.cpp b/src/backends/backendsCommon/DynamicBackendUtils.cpp
index 3d042dc74b..7e4edce8a0 100644
--- a/src/backends/backendsCommon/DynamicBackendUtils.cpp
+++ b/src/backends/backendsCommon/DynamicBackendUtils.cpp
@@ -29,6 +29,7 @@ void* DynamicBackendUtils::OpenHandle(const std::string& sharedObjectPath)
return sharedObjectHandle;
#else
+ armnn::IgnoreUnused(sharedObjectPath);
throw RuntimeException("Dynamic backends not supported on this platform");
#endif
}
@@ -43,6 +44,7 @@ void DynamicBackendUtils::CloseHandle(const void* sharedObjectHandle)
dlclose(const_cast<void*>(sharedObjectHandle));
#else
+ armnn::IgnoreUnused(sharedObjectHandle);
throw RuntimeException("Dynamic backends not supported on this platform");
#endif
}
@@ -148,6 +150,7 @@ bool DynamicBackendUtils::IsPathValid(const std::string& path)
return false;
}
+#if !defined(ARMNN_DISABLE_FILESYSTEM)
fs::path fsPath(path);
if (!fs::exists(fsPath))
@@ -167,6 +170,7 @@ bool DynamicBackendUtils::IsPathValid(const std::string& path)
ARMNN_LOG(warning) << "WARNING: The given backend path \"" << path << "\" is not absolute";
return false;
}
+#endif // !defined(ARMNN_DISABLE_FILESYSTEM)
return true;
}
@@ -176,6 +180,7 @@ std::vector<std::string> DynamicBackendUtils::GetSharedObjects(const std::vector
std::unordered_set<std::string> uniqueSharedObjects;
std::vector<std::string> sharedObjects;
+#if !defined(ARMNN_DISABLE_FILESYSTEM)
for (const std::string& backendPath : backendPaths)
{
using namespace fs;
@@ -254,6 +259,9 @@ std::vector<std::string> DynamicBackendUtils::GetSharedObjects(const std::vector
}
}
}
+#else
+ armnn::IgnoreUnused(backendPaths);
+#endif // !defined(ARMNN_DISABLE_FILESYSTEM)
return sharedObjects;
}
diff --git a/src/backends/backendsCommon/DynamicBackendUtils.hpp b/src/backends/backendsCommon/DynamicBackendUtils.hpp
index 32215adec4..71747fcdd2 100644
--- a/src/backends/backendsCommon/DynamicBackendUtils.hpp
+++ b/src/backends/backendsCommon/DynamicBackendUtils.hpp
@@ -80,6 +80,8 @@ EntryPointType DynamicBackendUtils::GetEntryPoint(const void* sharedObjectHandle
return entryPoint;
#else
+ armnn::IgnoreUnused(sharedObjectHandle);
+ armnn::IgnoreUnused(symbolName);
throw RuntimeException("Dynamic backends not supported on this platform");
#endif
}
diff --git a/src/backends/dynamic/reference/CMakeLists.txt b/src/backends/dynamic/reference/CMakeLists.txt
index 67e3495841..de46f7a5cb 100644
--- a/src/backends/dynamic/reference/CMakeLists.txt
+++ b/src/backends/dynamic/reference/CMakeLists.txt
@@ -3,6 +3,8 @@
# SPDX-License-Identifier: MIT
#
+if(NOT BUILD_BARE_METAL)
+
# File needed to wrap the existing backend into a dynamic one
list(APPEND armnnRefDynamicBackend_sources
RefDynamicBackend.cpp
@@ -30,3 +32,6 @@ target_include_directories(Arm_CpuRef_backend PRIVATE ${PROJECT_SOURCE_DIR}/prof
target_include_directories(Arm_CpuRef_backend PRIVATE ${PROJECT_SOURCE_DIR}/profiling/client/include)
set_target_properties(Arm_CpuRef_backend PROPERTIES PREFIX "")
target_link_libraries(Arm_CpuRef_backend armnn)
+
+# BUILD_BARE_METAL
+endif()
diff --git a/src/backends/reference/workloads/ConvImpl.cpp b/src/backends/reference/workloads/ConvImpl.cpp
index e1bbc6bc52..320690eb90 100644
--- a/src/backends/reference/workloads/ConvImpl.cpp
+++ b/src/backends/reference/workloads/ConvImpl.cpp
@@ -25,7 +25,7 @@ QuantizedMultiplierSmallerThanOne::QuantizedMultiplierSmallerThanOne(float multi
{
const double q = std::frexp(multiplier, &m_RightShift);
m_RightShift = -m_RightShift;
- int64_t qFixed = static_cast<int64_t>(std::round(q * (1ll << 31)));
+ int64_t qFixed = static_cast<int64_t>(::round(q * (1ll << 31)));
ARMNN_ASSERT(qFixed <= (1ll << 31));
if (qFixed == (1ll << 31))
{