aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Flynn <jim.flynn@arm.com>2022-04-12 17:19:28 +0100
committerTeresaARM <teresa.charlinreyes@arm.com>2022-04-14 14:06:56 +0000
commite195a0418d86650e132737716059bff0ec80257f (patch)
tree1678283a958a2ab74cd27b648f5a69ef5270d289
parent69515d3b36653a00a5abee8bf52ac26dd6522bee (diff)
downloadarmnn-e195a0418d86650e132737716059bff0ec80257f.tar.gz
IVGCVSW-6710 Add compile of BareMetalDeserializedGraph sample
Change-Id: Ice69c2a22f589f68d302f80500dfe4e514a796d2 Signed-off-by: Jim Flynn <jim.flynn@arm.com>
-rw-r--r--CMakeLists.txt10
-rw-r--r--profiling/client/src/BufferManager.cpp35
-rw-r--r--profiling/client/src/BufferManager.hpp6
-rw-r--r--profiling/client/src/CommandHandler.cpp12
-rw-r--r--profiling/client/src/CommandHandler.hpp7
-rw-r--r--profiling/client/src/FileOnlyProfilingConnection.cpp29
-rw-r--r--profiling/client/src/FileOnlyProfilingConnection.hpp11
-rw-r--r--profiling/client/src/PeriodicCounterCapture.cpp8
-rw-r--r--profiling/client/src/PeriodicCounterCapture.hpp7
-rw-r--r--profiling/client/src/ProfilingService.cpp22
-rw-r--r--profiling/client/src/ProfilingService.hpp2
-rw-r--r--profiling/client/src/ProfilingUtils.cpp5
-rw-r--r--profiling/client/src/SendThread.cpp37
-rw-r--r--profiling/client/src/SendThread.hpp7
-rw-r--r--profiling/client/src/SocketProfilingConnection.cpp24
-rw-r--r--profiling/client/src/SocketProfilingConnection.hpp2
-rw-r--r--profiling/common/include/NetworkSockets.hpp4
-rw-r--r--profiling/common/include/SocketConnectionException.hpp30
-rw-r--r--profiling/common/src/CMakeLists.txt6
-rw-r--r--profiling/common/src/NetworkSockets.cpp4
-rw-r--r--profiling/common/src/Processes.cpp4
-rw-r--r--profiling/common/src/Threads.cpp4
-rw-r--r--samples/BareMetalDeserializedGraph.cpp11
-rw-r--r--samples/CMakeLists.txt42
-rw-r--r--src/backends/backendsCommon/CMakeLists.txt5
25 files changed, 285 insertions, 49 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 27dcd17dd4..60e0e52870 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -51,6 +51,9 @@ endif()
include(GNUInstallDirs)
+add_subdirectory(profiling/common/src)
+add_subdirectory(profiling/client/src)
+
add_subdirectory(samples)
add_subdirectory(src/armnnTfLiteParser)
add_subdirectory(src/armnnSerializer)
@@ -474,7 +477,10 @@ target_link_libraries(armnn PUBLIC armnnUtils)
target_link_libraries(armnn PUBLIC pipeCommon)
target_link_libraries(armnn PUBLIC pipeClient)
-target_link_libraries(armnn PUBLIC ${CMAKE_DL_LIBS})
+if(NOT BUILD_BARE_METAL)
+ target_link_libraries(armnn PUBLIC ${CMAKE_DL_LIBS})
+endif()
+
if ("${CMAKE_SYSTEM_NAME}" STREQUAL Windows)
target_link_libraries(armnn PUBLIC Ws2_32.lib)
endif()
@@ -871,8 +877,6 @@ endif()
if(BUILD_TIMELINE_DECODER)
add_subdirectory(profiling/server/src/timelineDecoder)
- add_subdirectory(profiling/common/src)
- add_subdirectory(profiling/client/src)
add_subdirectory(src/timelineDecoder)
endif()
diff --git a/profiling/client/src/BufferManager.cpp b/profiling/client/src/BufferManager.cpp
index 42e32009e4..592d374817 100644
--- a/profiling/client/src/BufferManager.cpp
+++ b/profiling/client/src/BufferManager.cpp
@@ -24,19 +24,25 @@ BufferManager::BufferManager(unsigned int numberOfBuffers, unsigned int maxPacke
IPacketBufferPtr BufferManager::Reserve(unsigned int requestedSize, unsigned int& reservedSize)
{
reservedSize = 0;
+#if !defined(ARMNN_DISABLE_THREADS)
std::unique_lock<std::mutex> availableListLock(m_AvailableMutex, std::defer_lock);
+#endif
if (requestedSize > m_MaxBufferSize)
{
return nullptr;
}
+#if !defined(ARMNN_DISABLE_THREADS)
availableListLock.lock();
+#endif
if (m_AvailableList.empty())
{
if (m_CurrentNumberOfBuffers < m_MaxNumberOfBuffers)
{
// create a temporary overflow/surge buffer and hand it back
m_CurrentNumberOfBuffers++;
+#if !defined(ARMNN_DISABLE_THREADS)
availableListLock.unlock();
+#endif
IPacketBufferPtr buffer = std::make_unique<PacketBuffer>(m_MaxBufferSize);
reservedSize = requestedSize;
return buffer;
@@ -44,25 +50,34 @@ IPacketBufferPtr BufferManager::Reserve(unsigned int requestedSize, unsigned int
else
{
// we have totally busted the limit. call a halt to new memory allocations.
+#if !defined(ARMNN_DISABLE_THREADS)
availableListLock.unlock();
+#endif
return nullptr;
}
}
IPacketBufferPtr buffer = std::move(m_AvailableList.back());
m_AvailableList.pop_back();
+#if !defined(ARMNN_DISABLE_THREADS)
availableListLock.unlock();
+#endif
reservedSize = requestedSize;
return buffer;
}
void BufferManager::Commit(IPacketBufferPtr& packetBuffer, unsigned int size, bool notifyConsumer)
{
+#if !defined(ARMNN_DISABLE_THREADS)
std::unique_lock<std::mutex> readableListLock(m_ReadableMutex, std::defer_lock);
+#endif
packetBuffer->Commit(size);
+#if !defined(ARMNN_DISABLE_THREADS)
readableListLock.lock();
+#endif
m_ReadableList.push(std::move(packetBuffer));
+#if !defined(ARMNN_DISABLE_THREADS)
readableListLock.unlock();
-
+#endif
if (notifyConsumer)
{
FlushReadList();
@@ -82,9 +97,13 @@ void BufferManager::Initialize()
void BufferManager::Release(IPacketBufferPtr& packetBuffer)
{
+#if !defined(ARMNN_DISABLE_THREADS)
std::unique_lock<std::mutex> availableListLock(m_AvailableMutex, std::defer_lock);
+#endif
packetBuffer->Release();
+#if !defined(ARMNN_DISABLE_THREADS)
availableListLock.lock();
+#endif
if (m_AvailableList.size() <= m_NumberOfBuffers)
{
m_AvailableList.push_back(std::move(packetBuffer));
@@ -98,14 +117,18 @@ void BufferManager::Release(IPacketBufferPtr& packetBuffer)
--m_CurrentNumberOfBuffers;
}
}
+#if !defined(ARMNN_DISABLE_THREADS)
availableListLock.unlock();
+#endif
}
void BufferManager::Reset()
{
//This method should only be called once all threads have been joined
+#if !defined(ARMNN_DISABLE_THREADS)
std::lock_guard<std::mutex> readableListLock(m_ReadableMutex);
std::lock_guard<std::mutex> availableListLock(m_AvailableMutex);
+#endif
m_AvailableList.clear();
std::queue<IPacketBufferPtr>().swap(m_ReadableList);
@@ -115,12 +138,16 @@ void BufferManager::Reset()
IPacketBufferPtr BufferManager::GetReadableBuffer()
{
+#if !defined(ARMNN_DISABLE_THREADS)
std::unique_lock<std::mutex> readableListLock(m_ReadableMutex);
+#endif
if (!m_ReadableList.empty())
{
IPacketBufferPtr buffer = std::move(m_ReadableList.front());
m_ReadableList.pop();
+#if !defined(ARMNN_DISABLE_THREADS)
readableListLock.unlock();
+#endif
return buffer;
}
return nullptr;
@@ -128,9 +155,13 @@ IPacketBufferPtr BufferManager::GetReadableBuffer()
void BufferManager::MarkRead(IPacketBufferPtr& packetBuffer)
{
+#if !defined(ARMNN_DISABLE_THREADS)
std::unique_lock<std::mutex> availableListLock(m_AvailableMutex, std::defer_lock);
+#endif
packetBuffer->MarkRead();
+#if !defined(ARMNN_DISABLE_THREADS)
availableListLock.lock();
+#endif
if (m_AvailableList.size() <= m_NumberOfBuffers)
{
m_AvailableList.push_back(std::move(packetBuffer));
@@ -144,7 +175,9 @@ void BufferManager::MarkRead(IPacketBufferPtr& packetBuffer)
--m_CurrentNumberOfBuffers;
}
}
+#if !defined(ARMNN_DISABLE_THREADS)
availableListLock.unlock();
+#endif
}
void BufferManager::SetConsumer(IConsumer* consumer)
diff --git a/profiling/client/src/BufferManager.hpp b/profiling/client/src/BufferManager.hpp
index 0ab3e0e534..548edec0f4 100644
--- a/profiling/client/src/BufferManager.hpp
+++ b/profiling/client/src/BufferManager.hpp
@@ -8,8 +8,10 @@
#include "IBufferManager.hpp"
#include "IConsumer.hpp"
-#include <condition_variable>
+#if !defined(ARMNN_DISABLE_THREADS)
#include <mutex>
+#endif
+
#include <vector>
#include <queue>
@@ -61,11 +63,13 @@ private:
// List of readable packet buffers
std::queue<IPacketBufferPtr> m_ReadableList;
+#if !defined(ARMNN_DISABLE_THREADS)
// Mutex for available packet buffer list
std::mutex m_AvailableMutex;
// Mutex for readable packet buffer list
std::mutex m_ReadableMutex;
+#endif
// Consumer thread to notify packet is ready to read
IConsumer* m_Consumer = nullptr;
diff --git a/profiling/client/src/CommandHandler.cpp b/profiling/client/src/CommandHandler.cpp
index 6ba49c227d..b5a7551d9a 100644
--- a/profiling/client/src/CommandHandler.cpp
+++ b/profiling/client/src/CommandHandler.cpp
@@ -8,6 +8,10 @@
#include <common/include/Logging.hpp>
+#if defined(ARMNN_DISABLE_THREADS)
+#include <common/include/IgnoreUnused.hpp>
+#endif
+
namespace arm
{
@@ -21,24 +25,32 @@ void CommandHandler::Start(IProfilingConnection& profilingConnection)
return;
}
+#if !defined(ARMNN_DISABLE_THREADS)
if (m_CommandThread.joinable())
{
m_CommandThread.join();
}
+#endif
m_IsRunning.store(true);
m_KeepRunning.store(true);
+#if !defined(ARMNN_DISABLE_THREADS)
m_CommandThread = std::thread(&CommandHandler::HandleCommands, this, std::ref(profilingConnection));
+#else
+ IgnoreUnused(profilingConnection);
+#endif
}
void CommandHandler::Stop()
{
m_KeepRunning.store(false);
+#if !defined(ARMNN_DISABLE_THREADS)
if (m_CommandThread.joinable())
{
m_CommandThread.join();
}
+#endif
}
void CommandHandler::HandleCommands(IProfilingConnection& profilingConnection)
diff --git a/profiling/client/src/CommandHandler.hpp b/profiling/client/src/CommandHandler.hpp
index b097f9ef20..bc0461f1c2 100644
--- a/profiling/client/src/CommandHandler.hpp
+++ b/profiling/client/src/CommandHandler.hpp
@@ -11,7 +11,9 @@
#include <common/include/CommandHandlerRegistry.hpp>
#include <atomic>
+#if !defined(ARMNN_DISABLE_THREADS)
#include <thread>
+#endif
namespace arm
{
@@ -30,7 +32,9 @@ public:
m_StopAfterTimeout(stopAfterTimeout),
m_IsRunning(false),
m_KeepRunning(false),
+#if !defined(ARMNN_DISABLE_THREADS)
m_CommandThread(),
+#endif
m_CommandHandlerRegistry(commandHandlerRegistry),
m_PacketVersionResolver(packetVersionResolver)
{}
@@ -38,7 +42,6 @@ public:
void SetTimeout(uint32_t timeout) { m_Timeout.store(timeout); }
void SetStopAfterTimeout(bool stopAfterTimeout) { m_StopAfterTimeout.store(stopAfterTimeout); }
-
void Start(IProfilingConnection& profilingConnection);
void Stop();
bool IsRunning() const { return m_IsRunning.load(); }
@@ -50,7 +53,9 @@ private:
std::atomic<bool> m_StopAfterTimeout;
std::atomic<bool> m_IsRunning;
std::atomic<bool> m_KeepRunning;
+#if !defined(ARMNN_DISABLE_THREADS)
std::thread m_CommandThread;
+#endif
arm::pipe::CommandHandlerRegistry& m_CommandHandlerRegistry;
arm::pipe::PacketVersionResolver& m_PacketVersionResolver;
diff --git a/profiling/client/src/FileOnlyProfilingConnection.cpp b/profiling/client/src/FileOnlyProfilingConnection.cpp
index bee2c62de0..01ea3a2d71 100644
--- a/profiling/client/src/FileOnlyProfilingConnection.cpp
+++ b/profiling/client/src/FileOnlyProfilingConnection.cpp
@@ -11,7 +11,10 @@
#include <algorithm>
#include <iostream>
-#include <thread>
+
+#if defined(ARMNN_DISABLE_THREADS)
+#include <common/include/IgnoreUnused.hpp>
+#endif
namespace arm
{
@@ -97,12 +100,14 @@ void FileOnlyProfilingConnection::Close()
}
// dispose of the processing thread
m_KeepRunning.store(false);
+#if !defined(ARMNN_DISABLE_THREADS)
if (m_LocalHandlersThread.joinable())
{
// make sure the thread wakes up and sees it has to stop
m_ConditionPacketReadable.notify_one();
m_LocalHandlersThread.join();
}
+#endif
}
bool FileOnlyProfilingConnection::WritePacket(const unsigned char* buffer, uint32_t length)
@@ -116,14 +121,19 @@ bool FileOnlyProfilingConnection::WritePacket(const unsigned char* buffer, uint3
void FileOnlyProfilingConnection::ReturnPacket(arm::pipe::Packet& packet)
{
{
+#if !defined(ARMNN_DISABLE_THREADS)
std::lock_guard<std::mutex> lck(m_PacketAvailableMutex);
+#endif
m_PacketQueue.push(std::move(packet));
}
+#if !defined(ARMNN_DISABLE_THREADS)
m_ConditionPacketAvailable.notify_one();
+#endif
}
arm::pipe::Packet FileOnlyProfilingConnection::ReadPacket(uint32_t timeout)
{
+#if !defined(ARMNN_DISABLE_THREADS)
std::unique_lock<std::mutex> lck(m_PacketAvailableMutex);
// Here we are using m_PacketQueue.empty() as a predicate variable
@@ -135,6 +145,9 @@ arm::pipe::Packet FileOnlyProfilingConnection::ReadPacket(uint32_t timeout)
arm::pipe::Packet empty;
return empty;
}
+#else
+ IgnoreUnused(timeout);
+#endif
arm::pipe::Packet returnedPacket = std::move(m_PacketQueue.front());
m_PacketQueue.pop();
@@ -188,13 +201,17 @@ void FileOnlyProfilingConnection::StartProcessingThread()
return;
}
// make sure if there was one running before it is joined
+#if !defined(ARMNN_DISABLE_THREADS)
if (m_LocalHandlersThread.joinable())
{
m_LocalHandlersThread.join();
}
+#endif
m_IsRunning.store(true);
m_KeepRunning.store(true);
+#if !defined(ARMNN_DISABLE_THREADS)
m_LocalHandlersThread = std::thread(&FileOnlyProfilingConnection::ServiceLocalHandlers, this);
+#endif
}
void FileOnlyProfilingConnection::ForwardPacketToHandlers(arm::pipe::Packet& packet)
@@ -208,14 +225,18 @@ void FileOnlyProfilingConnection::ForwardPacketToHandlers(arm::pipe::Packet& pac
return;
}
{
+#if !defined(ARMNN_DISABLE_THREADS)
std::unique_lock<std::mutex> readableListLock(m_ReadableMutex);
+#endif
if (!m_KeepRunning.load())
{
return;
}
m_ReadableList.push(std::move(packet));
}
+#if !defined(ARMNN_DISABLE_THREADS)
m_ConditionPacketReadable.notify_one();
+#endif
}
void FileOnlyProfilingConnection::ServiceLocalHandlers()
@@ -225,17 +246,23 @@ void FileOnlyProfilingConnection::ServiceLocalHandlers()
arm::pipe::Packet returnedPacket;
bool readPacket = false;
{ // only lock while we are taking the packet off the incoming list
+#if !defined(ARMNN_DISABLE_THREADS)
std::unique_lock<std::mutex> lck(m_ReadableMutex);
+#endif
if (m_Timeout < 0)
{
+#if !defined(ARMNN_DISABLE_THREADS)
m_ConditionPacketReadable.wait(lck,
[&] { return !m_ReadableList.empty(); });
+#endif
}
else
{
+#if !defined(ARMNN_DISABLE_THREADS)
m_ConditionPacketReadable.wait_for(lck,
std::chrono::milliseconds(std::max(m_Timeout, 1000)),
[&] { return !m_ReadableList.empty(); });
+#endif
}
if (m_KeepRunning.load())
{
diff --git a/profiling/client/src/FileOnlyProfilingConnection.hpp b/profiling/client/src/FileOnlyProfilingConnection.hpp
index c7e60f564e..9ecbd6ccaf 100644
--- a/profiling/client/src/FileOnlyProfilingConnection.hpp
+++ b/profiling/client/src/FileOnlyProfilingConnection.hpp
@@ -17,12 +17,15 @@
#include <server/include/timelineDecoder/DirectoryCaptureCommandHandler.hpp>
#include <atomic>
-#include <condition_variable>
#include <fstream>
#include <map>
-#include <mutex>
#include <queue>
+
+#if !defined(ARMNN_DISABLE_THREADS)
+#include <condition_variable>
+#include <mutex>
#include <thread>
+#endif
namespace arm
{
@@ -111,8 +114,10 @@ private:
std::queue<arm::pipe::Packet> m_PacketQueue;
TargetEndianness m_Endianness;
+#if !defined(ARMNN_DISABLE_THREADS)
std::mutex m_PacketAvailableMutex;
std::condition_variable m_ConditionPacketAvailable;
+#endif
std::vector<ILocalPacketHandlerSharedPtr> m_PacketHandlers;
std::map<uint32_t, std::vector<ILocalPacketHandlerSharedPtr>> m_IndexedHandlers;
@@ -121,11 +126,13 @@ private:
// List of readable packets for the local packet handlers
std::queue<arm::pipe::Packet> m_ReadableList;
// Mutex and condition variable for the readable packet list
+#if !defined(ARMNN_DISABLE_THREADS)
std::mutex m_ReadableMutex;
std::condition_variable m_ConditionPacketReadable;
// thread that takes items from the readable list and dispatches them
// to the handlers.
std::thread m_LocalHandlersThread;
+#endif
// atomic booleans that control the operation of the local handlers thread
std::atomic<bool> m_IsRunning;
std::atomic<bool> m_KeepRunning;
diff --git a/profiling/client/src/PeriodicCounterCapture.cpp b/profiling/client/src/PeriodicCounterCapture.cpp
index 490173c7e0..25d1a1789a 100644
--- a/profiling/client/src/PeriodicCounterCapture.cpp
+++ b/profiling/client/src/PeriodicCounterCapture.cpp
@@ -31,7 +31,9 @@ void PeriodicCounterCapture::Start()
m_KeepRunning.store(true);
// Start the new capture thread.
+#if !defined(ARMNN_DISABLE_THREADS)
m_PeriodCaptureThread = std::thread(&PeriodicCounterCapture::Capture, this, std::ref(m_ReadCounterValues));
+#endif
}
void PeriodicCounterCapture::Stop()
@@ -39,12 +41,14 @@ void PeriodicCounterCapture::Stop()
// Signal the capture thread to stop
m_KeepRunning.store(false);
+#if !defined(ARMNN_DISABLE_THREADS)
// Check that the capture thread is running
if (m_PeriodCaptureThread.joinable())
{
// Wait for the capture thread to complete operations
m_PeriodCaptureThread.join();
}
+#endif
// Mark the capture thread as not running
m_IsRunning = false;
@@ -85,7 +89,9 @@ void PeriodicCounterCapture::Capture(IReadCounterValues& readCounterValues)
if (capturePeriod == 0)
{
// No data capture, wait the indicated capture period (milliseconds), if it is not zero
+#if !defined(ARMNN_DISABLE_THREADS)
std::this_thread::sleep_for(std::chrono::milliseconds(50u));
+#endif
continue;
}
@@ -129,7 +135,9 @@ void PeriodicCounterCapture::Capture(IReadCounterValues& readCounterValues)
});
// Wait the indicated capture period (microseconds)
+#if !defined(ARMNN_DISABLE_THREADS)
std::this_thread::sleep_for(std::chrono::microseconds(capturePeriod));
+#endif
}
while (m_KeepRunning.load());
}
diff --git a/profiling/client/src/PeriodicCounterCapture.hpp b/profiling/client/src/PeriodicCounterCapture.hpp
index 88084172ca..35ceb0cb77 100644
--- a/profiling/client/src/PeriodicCounterCapture.hpp
+++ b/profiling/client/src/PeriodicCounterCapture.hpp
@@ -17,8 +17,11 @@
#include <common/include/Packet.hpp>
#include <atomic>
+
+#if !defined(ARMNN_DISABLE_THREADS)
#include <mutex>
#include <thread>
+#endif
namespace arm
{
@@ -34,7 +37,7 @@ public:
IReadCounterValues& readCounterValue,
const ICounterMappings& counterIdMap,
const std::unordered_map<std::string,
- std::shared_ptr<IBackendProfilingContext>>& backendProfilingContexts)
+ std::shared_ptr<IBackendProfilingContext>>& backendProfilingContexts)
: m_CaptureDataHolder(data)
, m_IsRunning(false)
, m_KeepRunning(false)
@@ -58,7 +61,9 @@ private:
const Holder& m_CaptureDataHolder;
bool m_IsRunning;
std::atomic<bool> m_KeepRunning;
+#if !defined(ARMNN_DISABLE_THREADS)
std::thread m_PeriodCaptureThread;
+#endif
IReadCounterValues& m_ReadCounterValues;
ISendCounterPacket& m_SendCounterPacket;
const ICounterMappings& m_CounterIdMap;
diff --git a/profiling/client/src/ProfilingService.cpp b/profiling/client/src/ProfilingService.cpp
index 3a5c74b6da..b8e034809b 100644
--- a/profiling/client/src/ProfilingService.cpp
+++ b/profiling/client/src/ProfilingService.cpp
@@ -10,6 +10,11 @@
#include <common/include/ProfilingGuid.hpp>
#include <common/include/SocketConnectionException.hpp>
+#if defined(ARMNN_BUILD_BARE_METAL)
+#include <common/include/IgnoreUnused.hpp>
+#endif
+
+
#include <fmt/format.h>
namespace arm
@@ -33,6 +38,9 @@ void ProfilingService::ResetExternalProfilingOptions(const arm::pipe::ProfilingO
// Reset the profiling service
Reset();
}
+#else
+ IgnoreUnused(options);
+ IgnoreUnused(resetProfilingService);
#endif // ARMNN_BUILD_BARE_METAL
}
@@ -94,6 +102,10 @@ ProfilingState ProfilingService::ConfigureProfilingService(
return m_StateMachine.GetCurrentState();
}
}
+#else
+ IgnoreUnused(options);
+ IgnoreUnused(resetProfilingService);
+ return ProfilingState::Uninitialised;
#endif // ARMNN_BUILD_BARE_METAL
}
@@ -212,6 +224,9 @@ void ProfilingService::AddBackendProfilingContext(
// Register the backend counters
m_MaxGlobalCounterId = profilingContext->RegisterCounters(m_MaxGlobalCounterId);
m_BackendProfilingContexts.emplace(backendId, std::move(profilingContext));
+#else
+ IgnoreUnused(backendId);
+ IgnoreUnused(profilingContext);
#endif // ARMNN_BUILD_BARE_METAL
}
const ICounterDirectory& ProfilingService::GetCounterDirectory() const
@@ -348,6 +363,8 @@ void ProfilingService::InitializeCounterValue(uint16_t counterUid)
// Register the new counter to the counter index for quick access
std::atomic<uint32_t>* counterValuePtr = &(m_CounterValues.back());
m_CounterIndex.at(counterUid) = counterValuePtr;
+#else
+ IgnoreUnused(counterUid);
#endif // ARMNN_BUILD_BARE_METAL
}
@@ -404,6 +421,8 @@ inline void ProfilingService::CheckCounterUid(uint16_t counterUid) const
{
throw arm::pipe::InvalidArgumentException(fmt::format("Counter UID {} is not registered", counterUid));
}
+#else
+ IgnoreUnused(counterUid);
#endif // ARMNN_BUILD_BARE_METAL
}
@@ -454,7 +473,8 @@ void ProfilingService::WaitForProfilingServiceActivation(unsigned int timeout)
ss << "Timed out waiting on profiling service activation for " << elapsed.count() << " ms";
ARM_PIPE_LOG(warning) << ss.str();
}
- return;
+#else
+ IgnoreUnused(timeout);
#endif // ARMNN_BUILD_BARE_METAL
}
diff --git a/profiling/client/src/ProfilingService.hpp b/profiling/client/src/ProfilingService.hpp
index b84b39d0df..588bcd20d7 100644
--- a/profiling/client/src/ProfilingService.hpp
+++ b/profiling/client/src/ProfilingService.hpp
@@ -261,8 +261,10 @@ private:
uint16_t m_MaxGlobalCounterId;
// Signalling to let external actors know when service is active or not
+#if !defined(ARMNN_DISABLE_THREADS)
std::mutex m_ServiceActiveMutex;
std::condition_variable m_ServiceActiveConditionVariable;
+#endif
bool m_ServiceActive;
IInitialiseProfilingService& m_Initialiser;
diff --git a/profiling/client/src/ProfilingUtils.cpp b/profiling/client/src/ProfilingUtils.cpp
index 2963a98621..4426d41f4d 100644
--- a/profiling/client/src/ProfilingUtils.cpp
+++ b/profiling/client/src/ProfilingUtils.cpp
@@ -13,6 +13,7 @@
#include <armnn/Version.hpp>
+#include <chrono>
#include <fstream>
#include <iostream>
#include <limits>
@@ -593,11 +594,7 @@ TimelinePacketStatus WriteTimelineEventBinary(uint64_t timestamp,
uint64_t GetTimestamp()
{
-#if USE_CLOCK_MONOTONIC_RAW
- using clock = armnn::MonotonicClockRaw;
-#else
using clock = std::chrono::steady_clock;
-#endif
// Take a timestamp
auto timestamp = std::chrono::duration_cast<std::chrono::nanoseconds>(clock::now().time_since_epoch());
diff --git a/profiling/client/src/SendThread.cpp b/profiling/client/src/SendThread.cpp
index 7fb8e659f5..9a13dae057 100644
--- a/profiling/client/src/SendThread.cpp
+++ b/profiling/client/src/SendThread.cpp
@@ -9,6 +9,10 @@
#include <common/include/NumericCast.hpp>
#include <common/include/ProfilingException.hpp>
+#if defined(ARMNN_DISABLE_THREADS)
+#include <common/include/IgnoreUnused.hpp>
+#endif
+
#include <cstring>
namespace arm
@@ -36,11 +40,15 @@ void SendThread::SetReadyToRead()
{
// We need to wait for the send thread to release its mutex
{
+#if !defined(ARMNN_DISABLE_THREADS)
std::lock_guard<std::mutex> lck(m_WaitMutex);
+#endif
m_ReadyToRead = true;
}
// Signal the send thread that there's something to read in the buffer
+#if !defined(ARMNN_DISABLE_THREADS)
m_WaitCondition.notify_one();
+#endif
}
void SendThread::Start(IProfilingConnection& profilingConnection)
@@ -52,10 +60,12 @@ void SendThread::Start(IProfilingConnection& profilingConnection)
return;
}
+#if !defined(ARMNN_DISABLE_THREADS)
if (m_SendThread.joinable())
{
m_SendThread.join();
}
+#endif
// Mark the send thread as running
m_IsRunning.store(true);
@@ -70,7 +80,11 @@ void SendThread::Start(IProfilingConnection& profilingConnection)
m_PacketSent = false;
// Start the send thread
+#if !defined(ARMNN_DISABLE_THREADS)
m_SendThread = std::thread(&SendThread::Send, this, std::ref(profilingConnection));
+#else
+ IgnoreUnused(profilingConnection);
+#endif
}
void SendThread::Stop(bool rethrowSendThreadExceptions)
@@ -79,6 +93,7 @@ void SendThread::Stop(bool rethrowSendThreadExceptions)
m_KeepRunning.store(false);
// Check that the send thread is running
+#if !defined(ARMNN_DISABLE_THREADS)
if (m_SendThread.joinable())
{
// Kick the send thread out of the wait condition
@@ -86,6 +101,7 @@ void SendThread::Stop(bool rethrowSendThreadExceptions)
// Wait for the send thread to complete operations
m_SendThread.join();
}
+#endif
// Check if the send thread exception has to be rethrown
if (!rethrowSendThreadExceptions)
@@ -147,17 +163,19 @@ void SendThread::Send(IProfilingConnection& profilingConnection)
// Wait condition lock scope - Begin
{
+#if !defined(ARMNN_DISABLE_THREADS)
std::unique_lock<std::mutex> lock(m_WaitMutex);
bool timeout = m_WaitCondition.wait_for(lock,
std::chrono::milliseconds(std::max(m_Timeout, 1000)),
[&]{ return m_ReadyToRead; });
// If we get notified we need to flush the buffer again
- if(timeout)
+ if (timeout)
{
// Otherwise if we just timed out don't flush the buffer
continue;
}
+#endif
//reset condition variable predicate for next use
m_ReadyToRead = false;
}
@@ -167,20 +185,25 @@ void SendThread::Send(IProfilingConnection& profilingConnection)
default:
// Wait condition lock scope - Begin
{
+#if !defined(ARMNN_DISABLE_THREADS)
std::unique_lock<std::mutex> lock(m_WaitMutex);
-
+#endif
// Normal working state for the send thread
// Check if the send thread is required to enforce a timeout wait policy
if (m_Timeout < 0)
{
// Wait indefinitely until notified that something to read has become available in the buffer
+#if !defined(ARMNN_DISABLE_THREADS)
m_WaitCondition.wait(lock, [&] { return m_ReadyToRead; });
+#endif
}
else
{
// Wait until the thread is notified of something to read from the buffer,
// or check anyway after the specified number of milliseconds
+#if !defined(ARMNN_DISABLE_THREADS)
m_WaitCondition.wait_for(lock, std::chrono::milliseconds(m_Timeout), [&] { return m_ReadyToRead; });
+#endif
}
//reset condition variable predicate for next use
@@ -246,25 +269,33 @@ void SendThread::FlushBuffer(IProfilingConnection& profilingConnection, bool not
{
// Wait for the parent thread to release its mutex if necessary
{
+#if !defined(ARMNN_DISABLE_THREADS)
std::lock_guard<std::mutex> lck(m_PacketSentWaitMutex);
+#endif
m_PacketSent = true;
}
// Notify to any watcher that something has been sent
+#if !defined(ARMNN_DISABLE_THREADS)
m_PacketSentWaitCondition.notify_one();
+#endif
}
}
bool SendThread::WaitForPacketSent(uint32_t timeout = 1000)
{
+#if !defined(ARMNN_DISABLE_THREADS)
std::unique_lock<std::mutex> lock(m_PacketSentWaitMutex);
// Blocks until notified that at least a packet has been sent or until timeout expires.
bool timedOut = m_PacketSentWaitCondition.wait_for(lock,
std::chrono::milliseconds(timeout),
[&] { return m_PacketSent; });
-
m_PacketSent = false;
return timedOut;
+#else
+ IgnoreUnused(timeout);
+ return false;
+#endif
}
} // namespace pipe
diff --git a/profiling/client/src/SendThread.hpp b/profiling/client/src/SendThread.hpp
index b96a6d54f3..f462ae07d8 100644
--- a/profiling/client/src/SendThread.hpp
+++ b/profiling/client/src/SendThread.hpp
@@ -17,9 +17,11 @@
#include <common/include/ICounterDirectory.hpp>
#include <atomic>
+#if !defined(ARMNN_DISABLE_THREADS)
#include <condition_variable>
#include <mutex>
#include <thread>
+#endif
#include <type_traits>
namespace arm
@@ -57,9 +59,11 @@ private:
IBufferManager& m_BufferManager;
ISendCounterPacket& m_SendCounterPacket;
int m_Timeout;
+#if !defined(ARMNN_DISABLE_THREADS)
std::mutex m_WaitMutex;
std::condition_variable m_WaitCondition;
std::thread m_SendThread;
+#endif
std::atomic<bool> m_IsRunning;
std::atomic<bool> m_KeepRunning;
// m_ReadyToRead will be protected by m_WaitMutex
@@ -67,9 +71,10 @@ private:
// m_PacketSent will be protected by m_PacketSentWaitMutex
bool m_PacketSent;
std::exception_ptr m_SendThreadException;
+#if !defined(ARMNN_DISABLE_THREADS)
std::mutex m_PacketSentWaitMutex;
std::condition_variable m_PacketSentWaitCondition;
-
+#endif
};
} // namespace pipe
diff --git a/profiling/client/src/SocketProfilingConnection.cpp b/profiling/client/src/SocketProfilingConnection.cpp
index a211567f7f..b924f8dbc6 100644
--- a/profiling/client/src/SocketProfilingConnection.cpp
+++ b/profiling/client/src/SocketProfilingConnection.cpp
@@ -20,6 +20,7 @@ namespace pipe
SocketProfilingConnection::SocketProfilingConnection()
{
+#if !defined(ARMNN_DISABLE_SOCKETS)
arm::pipe::Initialize();
memset(m_Socket, 0, sizeof(m_Socket));
// Note: we're using Linux specific SOCK_CLOEXEC flag.
@@ -59,15 +60,21 @@ SocketProfilingConnection::SocketProfilingConnection()
m_Socket[0].fd,
errno);
}
+#endif
}
bool SocketProfilingConnection::IsOpen() const
{
+#if !defined(ARMNN_DISABLE_SOCKETS)
return m_Socket[0].fd > 0;
+#else
+ return false;
+#endif
}
void SocketProfilingConnection::Close()
{
+#if !defined(ARMNN_DISABLE_SOCKETS)
if (arm::pipe::Close(m_Socket[0].fd) != 0)
{
throw arm::pipe::SocketConnectionException(
@@ -77,6 +84,7 @@ void SocketProfilingConnection::Close()
}
memset(m_Socket, 0, sizeof(m_Socket));
+#endif
}
bool SocketProfilingConnection::WritePacket(const unsigned char* buffer, uint32_t length)
@@ -85,12 +93,16 @@ bool SocketProfilingConnection::WritePacket(const unsigned char* buffer, uint32_
{
return false;
}
-
+#if !defined(ARMNN_DISABLE_SOCKETS)
return arm::pipe::Write(m_Socket[0].fd, buffer, length) != -1;
+#else
+ return false;
+#endif
}
arm::pipe::Packet SocketProfilingConnection::ReadPacket(uint32_t timeout)
{
+#if !defined(ARMNN_DISABLE_SOCKETS)
// Is there currently at least a header worth of data waiting to be read?
int bytes_available = 0;
arm::pipe::Ioctl(m_Socket[0].fd, FIONREAD, &bytes_available);
@@ -156,10 +168,16 @@ arm::pipe::Packet SocketProfilingConnection::ReadPacket(uint32_t timeout)
return ReceivePacket();
}
+#else
+ IgnoreUnused(timeout);
+ throw arm::pipe::TimeoutException(
+ "SocketProfilingConnection: Cannot use ReadPacket function with sockets disabled");
+#endif
}
arm::pipe::Packet SocketProfilingConnection::ReceivePacket()
{
+#if !defined(ARMNN_DISABLE_SOCKETS)
char header[8] = {};
long receiveResult = arm::pipe::Read(m_Socket[0].fd, &header, sizeof(header));
// We expect 8 as the result here. 0 means EOF, socket is closed. -1 means there been some other kind of error.
@@ -219,6 +237,10 @@ arm::pipe::Packet SocketProfilingConnection::ReceivePacket()
}
return arm::pipe::Packet(metadataIdentifier, dataLength, packetData);
+#else
+ throw arm::pipe::TimeoutException(
+ "SocketProfilingConnection: Cannot use ReceivePacket function with sockets disabled");
+#endif
}
} // namespace pipe
diff --git a/profiling/client/src/SocketProfilingConnection.hpp b/profiling/client/src/SocketProfilingConnection.hpp
index 52616c9a27..db6b5123d1 100644
--- a/profiling/client/src/SocketProfilingConnection.hpp
+++ b/profiling/client/src/SocketProfilingConnection.hpp
@@ -35,7 +35,9 @@ private:
// MACOSX does not support abstract UDS
const char* m_GatorNamespace = "/tmp/gatord_namespace";
#endif
+#if !defined(ARMNN_DISABLE_SOCKETS)
arm::pipe::PollFd m_Socket[1]{};
+#endif
};
} // namespace pipe
diff --git a/profiling/common/include/NetworkSockets.hpp b/profiling/common/include/NetworkSockets.hpp
index 29575cdcd6..be94be6aa3 100644
--- a/profiling/common/include/NetworkSockets.hpp
+++ b/profiling/common/include/NetworkSockets.hpp
@@ -8,6 +8,8 @@
// is needed (typically just forwarding the parameters to a differently named function).
// Some of the APIs are in fact completely identical and so no forwarding function is needed.
+#if !defined(ARMNN_DISABLE_SOCKETS)
+
#pragma once
#if defined(__unix__) || defined(__APPLE__)
@@ -77,3 +79,5 @@ Socket Accept(Socket s, sockaddr* addr, socklen_t* addrlen, int flags);
} // namespace arm
} // namespace pipe
+
+#endif
diff --git a/profiling/common/include/SocketConnectionException.hpp b/profiling/common/include/SocketConnectionException.hpp
index 42b8d9d67e..f4ed2ebb23 100644
--- a/profiling/common/include/SocketConnectionException.hpp
+++ b/profiling/common/include/SocketConnectionException.hpp
@@ -20,24 +20,42 @@ namespace pipe
class SocketConnectionException : public std::exception
{
public:
- explicit SocketConnectionException(const std::string &message, arm::pipe::Socket socket)
- : m_Message(message), m_Socket(socket), m_ErrNo(-1) {};
+ explicit SocketConnectionException(const std::string& message
+#if !defined(ARMNN_DISABLE_SOCKETS)
+ , arm::pipe::Socket socket
+#endif
+ )
+ : m_Message(message),
+#if !defined(ARMNN_DISABLE_SOCKETS)
+ m_Socket(socket),
+#endif
+ m_ErrNo(-1) {};
- explicit SocketConnectionException(const std::string &message, arm::pipe::Socket socket, int errNo)
- : m_Message(message), m_Socket(socket), m_ErrNo(errNo) {};
+ explicit SocketConnectionException(const std::string& message,
+#if !defined(ARMNN_DISABLE_SOCKETS)
+ arm::pipe::Socket socket,
+#endif
+ int errNo)
+ : m_Message(message),
+#if !defined(ARMNN_DISABLE_SOCKETS)
+ m_Socket(socket),
+#endif
+ m_ErrNo(errNo) {};
/// @return - Error message of SocketProfilingConnection
- virtual const char *what() const noexcept override
+ virtual const char* what() const noexcept override
{
return m_Message.c_str();
}
/// @return - Socket File Descriptor of SocketProfilingConnection
/// or '-1', an invalid file descriptor
+#if !defined(ARMNN_DISABLE_SOCKETS)
arm::pipe::Socket GetSocketFd() const noexcept
{
return m_Socket;
}
+#endif
/// @return - errno of SocketProfilingConnection
int GetErrorNo() const noexcept
@@ -47,7 +65,9 @@ public:
private:
std::string m_Message;
+#if !defined(ARMNN_DISABLE_SOCKETS)
arm::pipe::Socket m_Socket;
+#endif
int m_ErrNo;
};
} // namespace pipe
diff --git a/profiling/common/src/CMakeLists.txt b/profiling/common/src/CMakeLists.txt
index 08d77c2b0f..54fd914bcf 100644
--- a/profiling/common/src/CMakeLists.txt
+++ b/profiling/common/src/CMakeLists.txt
@@ -21,12 +21,6 @@
include_directories(${PROJECT_SOURCE_DIR}/profiling/common/include)
include_directories(${PROJECT_SOURCE_DIR}/common/include)
- if(BUILD_UNIT_TESTS)
- include_directories(${PROJECT_SOURCE_DIR}/src/profiling
- ${PROJECT_SOURCE_DIR}/src/armnnUtils)
- target_include_directories(UnitTests PRIVATE ${PROJECT_SOURCE_DIR}/profiling/common/include)
- endif()
-
# 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})
diff --git a/profiling/common/src/NetworkSockets.cpp b/profiling/common/src/NetworkSockets.cpp
index 15ad087d1e..84711c6215 100644
--- a/profiling/common/src/NetworkSockets.cpp
+++ b/profiling/common/src/NetworkSockets.cpp
@@ -3,6 +3,8 @@
// SPDX-License-Identifier: MIT
//
+#if !defined(ARMNN_DISABLE_SOCKETS)
+
#include <common/include/NetworkSockets.hpp>
#if defined(__unix__) || defined(__APPLE__)
@@ -112,3 +114,5 @@ arm::pipe::Socket Accept(Socket s, sockaddr* addr, socklen_t* addrlen, int flags
} // pipe
} // arm
+
+#endif
diff --git a/profiling/common/src/Processes.cpp b/profiling/common/src/Processes.cpp
index 94e809529a..b8c2941e5a 100644
--- a/profiling/common/src/Processes.cpp
+++ b/profiling/common/src/Processes.cpp
@@ -18,11 +18,15 @@ namespace pipe
int GetCurrentProcessId()
{
+#if !defined(ARMNN_DISABLE_PROCESSES)
#if defined(__unix__) || defined(__APPLE__)
return getpid();
#elif defined(_MSC_VER)
return ::GetCurrentProcessId();
#endif
+#else
+ return 0;
+#endif
}
} // namespace pipe
diff --git a/profiling/common/src/Threads.cpp b/profiling/common/src/Threads.cpp
index 10533b77b9..d9e60167e8 100644
--- a/profiling/common/src/Threads.cpp
+++ b/profiling/common/src/Threads.cpp
@@ -26,6 +26,7 @@ namespace pipe
int GetCurrentThreadId()
{
+#if !defined(ARMNN_DISABLE_THREADS)
#if defined(__linux__)
return static_cast<int>(gettid());
#elif defined(_MSC_VER)
@@ -39,6 +40,9 @@ int GetCurrentThreadId()
}
return static_cast<int>(threadId);
#endif
+#else
+ return 0;
+#endif
}
} // namespace pipe
diff --git a/samples/BareMetalDeserializedGraph.cpp b/samples/BareMetalDeserializedGraph.cpp
new file mode 100644
index 0000000000..8b0df5f6dd
--- /dev/null
+++ b/samples/BareMetalDeserializedGraph.cpp
@@ -0,0 +1,11 @@
+//
+// Copyright © 2022 Arm Ltd and Contributors. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+#include <cstdio>
+
+int main()
+{
+ printf("The bare metal deserialized graph was successfully executed\n");
+ return 0;
+}
diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt
index 210dc9c864..42e5a476cf 100644
--- a/samples/CMakeLists.txt
+++ b/samples/CMakeLists.txt
@@ -1,23 +1,29 @@
-if(BUILD_SAMPLE_APP AND ARMNNREF)
- add_executable(SimpleSample SimpleSample.cpp)
- target_link_libraries(SimpleSample armnn ${CMAKE_THREAD_LIBS_INIT})
+if (NOT BUILD_BARE_METAL)
+ if(BUILD_SAMPLE_APP AND ARMNNREF)
+ add_executable(SimpleSample SimpleSample.cpp)
+ target_link_libraries(SimpleSample armnn ${CMAKE_THREAD_LIBS_INIT})
- add_executable(AsyncExecutionSample AsyncExecutionSample.cpp)
- target_link_libraries(AsyncExecutionSample armnn ${CMAKE_THREAD_LIBS_INIT})
-endif()
+ add_executable(AsyncExecutionSample AsyncExecutionSample.cpp)
+ target_link_libraries(AsyncExecutionSample armnn ${CMAKE_THREAD_LIBS_INIT})
+ endif()
-if(BUILD_SAMPLE_APP AND SAMPLE_DYNAMIC_BACKEND)
- add_executable(DynamicSample DynamicSample.cpp)
- target_link_libraries(DynamicSample armnn ${CMAKE_THREAD_LIBS_INIT})
-endif()
+ if(BUILD_SAMPLE_APP AND SAMPLE_DYNAMIC_BACKEND)
+ add_executable(DynamicSample DynamicSample.cpp)
+ target_link_libraries(DynamicSample armnn ${CMAKE_THREAD_LIBS_INIT})
+ endif()
-if(BUILD_SAMPLE_APP AND ARMCOMPUTECL)
- add_executable(CustomMemoryAllocatorSample CustomMemoryAllocatorSample.cpp)
- target_link_libraries(CustomMemoryAllocatorSample armnn ${CMAKE_THREAD_LIBS_INIT})
-endif()
+ if(BUILD_SAMPLE_APP AND ARMCOMPUTECL)
+ add_executable(CustomMemoryAllocatorSample CustomMemoryAllocatorSample.cpp)
+ target_link_libraries(CustomMemoryAllocatorSample armnn ${CMAKE_THREAD_LIBS_INIT})
+ endif()
-if(BUILD_SAMPLE_APP AND ARMNNREF)
- add_executable(PreImportMemorySample PreImportMemorySample.cpp)
- target_link_libraries(PreImportMemorySample armnn ${CMAKE_THREAD_LIBS_INIT})
+ if(BUILD_SAMPLE_APP AND ARMNNREF)
+ add_executable(PreImportMemorySample PreImportMemorySample.cpp)
+ target_link_libraries(PreImportMemorySample armnn ${CMAKE_THREAD_LIBS_INIT})
+ endif()
+else()
+ if (ARMNNREF)
+ add_executable(BareMetalDeserializedGraph BareMetalDeserializedGraph.cpp)
+ target_link_libraries(BareMetalDeserializedGraph fmt pipeCommon pipeClient armnn)
+ endif()
endif()
-
diff --git a/src/backends/backendsCommon/CMakeLists.txt b/src/backends/backendsCommon/CMakeLists.txt
index e94e657bca..436f28749a 100644
--- a/src/backends/backendsCommon/CMakeLists.txt
+++ b/src/backends/backendsCommon/CMakeLists.txt
@@ -3,11 +3,16 @@
# SPDX-License-Identifier: MIT
#
+if(NOT BUILD_BARE_METAL)
list(APPEND armnnBackendsCommon_sources
DynamicBackend.cpp
DynamicBackend.hpp
DynamicBackendUtils.cpp
DynamicBackendUtils.hpp
+)
+endif()
+
+list(APPEND armnnBackendsCommon_sources
IBackendContext.hpp
IBackendInternal.cpp
IMemoryManager.hpp