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 --- CMakeLists.txt | 7 ++++- cmake/GlobalConfig.cmake | 22 +++++++++++-- include/armnn/Threadpool.hpp | 3 ++ include/armnn/backends/Workload.hpp | 5 ++- include/armnnUtils/Filesystem.hpp | 7 +++-- profiling/client/include/Holder.hpp | 2 ++ profiling/client/src/Holder.cpp | 6 ++-- profiling/client/src/ProfilingService.cpp | 36 +++++++++++++++++++++- .../common/include/ProfilingGuidGenerator.hpp | 6 ++++ profiling/common/src/CMakeLists.txt | 1 + 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 +++--- src/armnnSerializer/CMakeLists.txt | 6 +++- src/armnnTestUtils/CMakeLists.txt | 14 +++++++-- src/armnnUtils/Filesystem.cpp | 7 +++-- .../backendsCommon/DynamicBackendUtils.cpp | 8 +++++ .../backendsCommon/DynamicBackendUtils.hpp | 2 ++ src/backends/dynamic/reference/CMakeLists.txt | 5 +++ src/backends/reference/workloads/ConvImpl.cpp | 2 +- 25 files changed, 187 insertions(+), 32 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e996163f5..27dcd17dd4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -438,7 +438,11 @@ foreach(lib ${armnnLibraries}) list(APPEND armnn_sources $) endforeach() -add_library_ex(armnn SHARED ${armnn_sources}) +if(BUILD_BARE_METAL) + add_library_ex(armnn STATIC ${armnn_sources}) +else() + add_library_ex(armnn SHARED ${armnn_sources}) +endif() target_compile_definitions(armnn PRIVATE "ARMNN_COMPILING_DLL") @@ -479,6 +483,7 @@ endif() if(BUILD_ONNX_PARSER) install(TARGETS armnnOnnxParser LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/cmake/GlobalConfig.cmake b/cmake/GlobalConfig.cmake index 2c5bc837e6..2cc184c796 100644 --- a/cmake/GlobalConfig.cmake +++ b/cmake/GlobalConfig.cmake @@ -3,6 +3,9 @@ # Copyright 2020 NXP # SPDX-License-Identifier: MIT # + +cmake_policy(SET CMP0077 NEW) + option(BUILD_ONNX_PARSER "Build Onnx parser" OFF) option(BUILD_UNIT_TESTS "Build unit tests" ON) option(BUILD_TESTS "Build test applications" OFF) @@ -33,6 +36,7 @@ option(BUILD_STATIC_PIPE_LIBS "Build Static PIPE libraries" OFF) option(BUILD_PIPE_ONLY "Build the PIPE libraries only" OFF) option(BUILD_ARMNN_TFLITE_DELEGATE "Build the Arm NN TfLite delegate" OFF) option(BUILD_MEMORY_STRATEGY_BENCHMARK "Build the MemoryBenchmark" OFF) +option(BUILD_BARE_METAL "Disable features requiring operating system support" OFF) include(SelectLibraryConfigurations) @@ -72,7 +76,8 @@ if(COMPILER_IS_GNU_LIKE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-psabi") endif() elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC) - # Disable C4996 (use of deprecated identifier) due to https://developercommunity.visualstudio.com/content/problem/252574/deprecated-compilation-warning-for-virtual-overrid.html + # Disable C4996 (use of deprecated identifier) due to + # https://developercommunity.visualstudio.com/content/problem/252574/deprecated-compilation-warning-for-virtual-overrid.html set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /MP /wd4996") add_definitions(-DNO_STRICT=1) endif() @@ -140,7 +145,9 @@ if (NOT BUILD_PIPE_ONLY) endif() # pthread -find_dependency(Threads) +if (NOT BUILD_BARE_METAL) +find_package(Threads) +endif() # Favour the protobuf passed on command line if(BUILD_ONNX_PARSER) @@ -345,6 +352,7 @@ if(PROFILING_BACKEND_STREAMLINE) add_definitions(-DARMNN_STREAMLINE_ENABLED) endif() +if(NOT BUILD_BARE_METAL) if(HEAP_PROFILING OR LEAK_CHECKING) # enable heap profiling for everything except for referencetests if(NOT ${PROJECT_NAME} STREQUAL "referencetests") @@ -371,7 +379,7 @@ else() # Valgrind only works with gperftools version number <= 2.4 CHECK_INCLUDE_FILE(valgrind/memcheck.h VALGRIND_FOUND) endif() - +endif() if(NOT BUILD_TF_LITE_PARSER) message(STATUS "Tensorflow Lite parser support is disabled") @@ -406,5 +414,13 @@ if(BUILD_PYTHON_WHL OR BUILD_PYTHON_SRC) endif() endif() +if(BUILD_BARE_METAL) + add_definitions(-DARMNN_BUILD_BARE_METAL + -DARMNN_DISABLE_FILESYSTEM + -DARMNN_DISABLE_PROCESSES + -DARMNN_DISABLE_THREADS + -DARMNN_DISABLE_SOCKETS) +endif() + # ArmNN source files required for all build options include_directories(SYSTEM third-party) diff --git a/include/armnn/Threadpool.hpp b/include/armnn/Threadpool.hpp index e2458dbb65..672f8b8de6 100644 --- a/include/armnn/Threadpool.hpp +++ b/include/armnn/Threadpool.hpp @@ -2,6 +2,7 @@ // Copyright © 2021 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // +#if !defined(ARMNN_DISABLE_THREADS) #pragma once @@ -76,3 +77,5 @@ private: } // namespace experimental } // namespace armnn + +#endif diff --git a/include/armnn/backends/Workload.hpp b/include/armnn/backends/Workload.hpp index d426486f89..6c9fcabd55 100644 --- a/include/armnn/backends/Workload.hpp +++ b/include/armnn/backends/Workload.hpp @@ -43,8 +43,9 @@ public: void ExecuteAsync(WorkingMemDescriptor& workingMemDescriptor) override { ARMNN_LOG(info) << "Using default async workload execution, this will network affect performance"; +#if !defined(ARMNN_DISABLE_THREADS) std::lock_guard lockGuard(m_AsyncWorkloadMutex); - +#endif m_Data.m_Inputs = workingMemDescriptor.m_Inputs; m_Data.m_Outputs = workingMemDescriptor.m_Outputs; @@ -81,7 +82,9 @@ protected: const arm::pipe::ProfilingGuid m_Guid; private: +#if !defined(ARMNN_DISABLE_THREADS) std::mutex m_AsyncWorkloadMutex; +#endif }; // TypedWorkload used diff --git a/include/armnnUtils/Filesystem.hpp b/include/armnnUtils/Filesystem.hpp index ba0d97a272..0d29a7558d 100644 --- a/include/armnnUtils/Filesystem.hpp +++ b/include/armnnUtils/Filesystem.hpp @@ -4,6 +4,7 @@ // #pragma once +#if !defined(ARMNN_DISABLE_FILESYSTEM) #if defined(_MSC_VER) // ghc includes Windows.h directly, bringing in macros that we don't want (e.g. min/max). @@ -21,5 +22,7 @@ namespace Filesystem /// Returns a path to a file in the system temporary folder. If the file existed it will be deleted. fs::path NamedTempFile(const char* fileName); -} -} +} // namespace armnnUtils +} // namespace Filesystem + +#endif // !defined(ARMNN_DISABLE_FILESYSTEM) diff --git a/profiling/client/include/Holder.hpp b/profiling/client/include/Holder.hpp index db5468feda..27d6789355 100644 --- a/profiling/client/include/Holder.hpp +++ b/profiling/client/include/Holder.hpp @@ -58,7 +58,9 @@ public: const std::set& activeBackends); private: +#if !defined(ARMNN_DISABLE_THREADS) mutable std::mutex m_CaptureThreadMutex; +#endif CaptureData m_CaptureData; }; diff --git a/profiling/client/src/Holder.cpp b/profiling/client/src/Holder.cpp index d144e244d9..2fee6f994a 100644 --- a/profiling/client/src/Holder.cpp +++ b/profiling/client/src/Holder.cpp @@ -52,8 +52,9 @@ const std::vector& CaptureData::GetCounterIds() const CaptureData Holder::GetCaptureData() const { +#if !defined(ARMNN_DISABLE_THREADS) std::lock_guard lockGuard(m_CaptureThreadMutex); - +#endif return m_CaptureData; } @@ -74,8 +75,9 @@ void Holder::SetCaptureData(uint32_t capturePeriod, const std::vector& counterIds, const std::set& activeBackends) { +#if !defined(ARMNN_DISABLE_THREADS) std::lock_guard lockGuard(m_CaptureThreadMutex); - +#endif m_CaptureData.SetCapturePeriod(capturePeriod); m_CaptureData.SetCounterIds(counterIds); m_CaptureData.SetActiveBackends(activeBackends); diff --git a/profiling/client/src/ProfilingService.cpp b/profiling/client/src/ProfilingService.cpp index 7acddf1129..3a5c74b6da 100644 --- a/profiling/client/src/ProfilingService.cpp +++ b/profiling/client/src/ProfilingService.cpp @@ -21,6 +21,7 @@ namespace pipe void ProfilingService::ResetExternalProfilingOptions(const arm::pipe::ProfilingOptions& options, bool resetProfilingService) { +#if !defined(ARMNN_BUILD_BARE_METAL) // Update the profiling options m_Options = options; m_TimelineReporting = options.m_TimelineEnabled; @@ -32,17 +33,23 @@ void ProfilingService::ResetExternalProfilingOptions(const arm::pipe::ProfilingO // Reset the profiling service Reset(); } +#endif // ARMNN_BUILD_BARE_METAL } bool ProfilingService::IsProfilingEnabled() const { +#if !defined(ARMNN_BUILD_BARE_METAL) return m_Options.m_EnableProfiling; +#else + return false; +#endif // ARMNN_BUILD_BARE_METAL } ProfilingState ProfilingService::ConfigureProfilingService( const ProfilingOptions& options, bool resetProfilingService) { +#if !defined(ARMNN_BUILD_BARE_METAL) ResetExternalProfilingOptions(options, resetProfilingService); ProfilingState currentState = m_StateMachine.GetCurrentState(); if (options.m_EnableProfiling) @@ -87,10 +94,12 @@ ProfilingState ProfilingService::ConfigureProfilingService( return m_StateMachine.GetCurrentState(); } } +#endif // ARMNN_BUILD_BARE_METAL } void ProfilingService::Update() { +#if !defined(ARMNN_BUILD_BARE_METAL) if (!m_Options.m_EnableProfiling) { // Don't run if profiling is disabled @@ -168,10 +177,12 @@ void ProfilingService::Update() throw arm::pipe::ProfilingException(fmt::format("Unknown profiling service state: {}", static_cast(currentState))); } +#endif // ARMNN_BUILD_BARE_METAL } void ProfilingService::Disconnect() { +#if !defined(ARMNN_BUILD_BARE_METAL) ProfilingState currentState = m_StateMachine.GetCurrentState(); switch (currentState) { @@ -188,16 +199,20 @@ void ProfilingService::Disconnect() throw arm::pipe::ProfilingException(fmt::format("Unknown profiling service state: {}", static_cast(currentState))); } +#endif // ARMNN_BUILD_BARE_METAL } // Store a profiling context returned from a backend that support profiling, and register its counters -void ProfilingService::AddBackendProfilingContext(const std::string& backendId, +void ProfilingService::AddBackendProfilingContext( + const std::string& backendId, std::shared_ptr profilingContext) { +#if !defined(ARMNN_BUILD_BARE_METAL) ARM_PIPE_ASSERT(profilingContext != nullptr); // Register the backend counters m_MaxGlobalCounterId = profilingContext->RegisterCounters(m_MaxGlobalCounterId); m_BackendProfilingContexts.emplace(backendId, std::move(profilingContext)); +#endif // ARMNN_BUILD_BARE_METAL } const ICounterDirectory& ProfilingService::GetCounterDirectory() const { @@ -313,11 +328,14 @@ std::unique_ptr ProfilingService::GetSendTimelinePacket() c void ProfilingService::Initialize() { +#if !defined(ARMNN_BUILD_BARE_METAL) m_Initialiser.InitialiseProfilingService(*this); +#endif // ARMNN_BUILD_BARE_METAL } void ProfilingService::InitializeCounterValue(uint16_t counterUid) { +#if !defined(ARMNN_BUILD_BARE_METAL) // Increase the size of the counter index if necessary if (counterUid >= m_CounterIndex.size()) { @@ -330,10 +348,12 @@ void ProfilingService::InitializeCounterValue(uint16_t counterUid) // Register the new counter to the counter index for quick access std::atomic* counterValuePtr = &(m_CounterValues.back()); m_CounterIndex.at(counterUid) = counterValuePtr; +#endif // ARMNN_BUILD_BARE_METAL } void ProfilingService::Reset() { +#if !defined(ARMNN_BUILD_BARE_METAL) // Stop the profiling service... Stop(); @@ -347,10 +367,12 @@ void ProfilingService::Reset() // ...finally reset the profiling state machine m_StateMachine.Reset(); m_BackendProfilingContexts.clear(); +#endif // ARMNN_BUILD_BARE_METAL } void ProfilingService::Stop() { +#if !defined(ARMNN_BUILD_BARE_METAL) { // only lock when we are updating the inference completed variable std::unique_lock lck(m_ServiceActiveMutex); m_ServiceActive = false; @@ -372,18 +394,22 @@ void ProfilingService::Stop() // ...then move to the "NotConnected" state m_StateMachine.TransitionToState(ProfilingState::NotConnected); +#endif // ARMNN_BUILD_BARE_METAL } inline void ProfilingService::CheckCounterUid(uint16_t counterUid) const { +#if !defined(ARMNN_BUILD_BARE_METAL) if (!IsCounterRegistered(counterUid)) { throw arm::pipe::InvalidArgumentException(fmt::format("Counter UID {} is not registered", counterUid)); } +#endif // ARMNN_BUILD_BARE_METAL } void ProfilingService::NotifyBackendsForTimelineReporting() { +#if !defined(ARMNN_BUILD_BARE_METAL) BackendProfilingContext::iterator it = m_BackendProfilingContexts.begin(); while (it != m_BackendProfilingContexts.end()) { @@ -392,19 +418,23 @@ void ProfilingService::NotifyBackendsForTimelineReporting() // Increment the Iterator to point to next entry it++; } +#endif // ARMNN_BUILD_BARE_METAL } void ProfilingService::NotifyProfilingServiceActive() { +#if !defined(ARMNN_BUILD_BARE_METAL) { // only lock when we are updating the inference completed variable std::unique_lock lck(m_ServiceActiveMutex); m_ServiceActive = true; } m_ServiceActiveConditionVariable.notify_one(); +#endif // ARMNN_BUILD_BARE_METAL } void ProfilingService::WaitForProfilingServiceActivation(unsigned int timeout) { +#if !defined(ARMNN_BUILD_BARE_METAL) std::unique_lock lck(m_ServiceActiveMutex); auto start = std::chrono::high_resolution_clock::now(); @@ -425,12 +455,16 @@ void ProfilingService::WaitForProfilingServiceActivation(unsigned int timeout) ARM_PIPE_LOG(warning) << ss.str(); } return; +#endif // ARMNN_BUILD_BARE_METAL } ProfilingService::~ProfilingService() { +#if !defined(ARMNN_BUILD_BARE_METAL) Stop(); +#endif // ARMNN_BUILD_BARE_METAL } + } // namespace pipe } // namespace arm diff --git a/profiling/common/include/ProfilingGuidGenerator.hpp b/profiling/common/include/ProfilingGuidGenerator.hpp index bfee7642e9..22a488df93 100644 --- a/profiling/common/include/ProfilingGuidGenerator.hpp +++ b/profiling/common/include/ProfilingGuidGenerator.hpp @@ -26,7 +26,9 @@ public: /// Return the next random Guid in the sequence inline ProfilingDynamicGuid NextGuid() override { +#if !defined(ARMNN_DISABLE_THREADS) std::lock_guard sequencelock(m_SequenceMutex); +#endif ProfilingDynamicGuid guid(m_Sequence); m_Sequence++; if (m_Sequence >= MIN_STATIC_GUID) @@ -47,14 +49,18 @@ public: /// Reset the generator back to zero. Used mainly for test. inline void Reset() { +#if !defined(ARMNN_DISABLE_THREADS) std::lock_guard sequencelock(m_SequenceMutex); +#endif m_Sequence = 0; } private: std::hash m_Hash; uint64_t m_Sequence; +#if !defined(ARMNN_DISABLE_THREADS) std::mutex m_SequenceMutex; +#endif }; } // namespace pipe diff --git a/profiling/common/src/CMakeLists.txt b/profiling/common/src/CMakeLists.txt index 94aec874f8..08d77c2b0f 100644 --- a/profiling/common/src/CMakeLists.txt +++ b/profiling/common/src/CMakeLists.txt @@ -30,6 +30,7 @@ # will only build a static version of this common code # to simplify the build. No extra .so file to deploy to boards etc. add_library_ex(pipeCommon STATIC ${pipeCommon_sources}) + target_link_libraries(pipeCommon fmt) target_compile_definitions(pipeCommon PRIVATE "ARMNN_COMPILING_DLL") 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 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 @@ -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(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 DynamicBackendUtils::GetSharedObjects(const std::vector std::unordered_set uniqueSharedObjects; std::vector sharedObjects; +#if !defined(ARMNN_DISABLE_FILESYSTEM) for (const std::string& backendPath : backendPaths) { using namespace fs; @@ -254,6 +259,9 @@ std::vector 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(std::round(q * (1ll << 31))); + int64_t qFixed = static_cast(::round(q * (1ll << 31))); ARMNN_ASSERT(qFixed <= (1ll << 31)); if (qFixed == (1ll << 31)) { -- cgit v1.2.1