11 #include <boost/format.hpp> 20 bool resetProfilingService)
26 if (resetProfilingService)
40 bool resetProfilingService)
109 m_CommandHandler.
Stop();
112 m_SendThread.
Stop(
false);
115 m_PeriodicCounterCapture.
Stop();
118 m_ProfilingConnection.reset();
123 BOOST_ASSERT(m_ProfilingConnectionFactory);
124 m_ProfilingConnection = m_ProfilingConnectionFactory->GetProfilingConnection(m_Options);
128 ARMNN_LOG(
warning) <<
"An error has occurred when creating the profiling connection: " 139 BOOST_ASSERT(m_ProfilingConnection);
142 m_CommandHandler.
Start(*m_ProfilingConnection);
146 m_SendThread.
Start(*m_ProfilingConnection);
159 throw RuntimeException(boost::str(boost::format(
"Unknown profiling service state: %1")
160 % static_cast<int>(currentState)));
167 switch (currentState)
179 throw RuntimeException(boost::str(boost::format(
"Unknown profiling service state: %1")
180 % static_cast<int>(currentState)));
186 std::shared_ptr<armnn::profiling::IBackendProfilingContext> profilingContext)
188 BOOST_ASSERT(profilingContext !=
nullptr);
190 m_MaxGlobalCounterId = profilingContext->RegisterCounters(m_MaxGlobalCounterId);
191 m_BackendProfilingContexts.emplace(backendId, std::move(profilingContext));
195 return m_CounterDirectory;
200 return m_CounterDirectory;
215 return counterUid < m_CounterIndex.size();
220 CheckCounterUid(counterUid);
221 std::atomic<uint32_t>* counterValuePtr = m_CounterIndex.at(counterUid);
222 BOOST_ASSERT(counterValuePtr);
223 return counterValuePtr->load(std::memory_order::memory_order_relaxed);
228 return m_CounterIdMap;
233 return m_CounterIdMap;
242 const std::vector<uint16_t>& counterIds,
243 const std::set<BackendId>& activeBackends)
245 m_Holder.
SetCaptureData(capturePeriod, counterIds, activeBackends);
250 CheckCounterUid(counterUid);
251 std::atomic<uint32_t>* counterValuePtr = m_CounterIndex.at(counterUid);
252 BOOST_ASSERT(counterValuePtr);
253 counterValuePtr->store(value, std::memory_order::memory_order_relaxed);
258 CheckCounterUid(counterUid);
259 std::atomic<uint32_t>* counterValuePtr = m_CounterIndex.at(counterUid);
260 BOOST_ASSERT(counterValuePtr);
261 return counterValuePtr->fetch_add(value, std::memory_order::memory_order_relaxed);
266 CheckCounterUid(counterUid);
267 std::atomic<uint32_t>* counterValuePtr = m_CounterIndex.at(counterUid);
268 BOOST_ASSERT(counterValuePtr);
269 return counterValuePtr->fetch_sub(value, std::memory_order::memory_order_relaxed);
274 CheckCounterUid(counterUid);
275 std::atomic<uint32_t>* counterValuePtr = m_CounterIndex.at(counterUid);
276 BOOST_ASSERT(counterValuePtr);
277 return counterValuePtr->operator++(std::memory_order::memory_order_relaxed);
295 void ProfilingService::Initialize()
306 const Counter* loadedNetworksCounter =
308 armnn::profiling::NETWORK_LOADS,
314 "The number of networks loaded at runtime",
315 std::string(
"networks"));
316 BOOST_ASSERT(loadedNetworksCounter);
317 InitializeCounterValue(loadedNetworksCounter->
m_Uid);
322 const Counter* unloadedNetworksCounter =
324 armnn::profiling::NETWORK_UNLOADS,
330 "The number of networks unloaded at runtime",
331 std::string(
"networks"));
332 BOOST_ASSERT(unloadedNetworksCounter);
333 InitializeCounterValue(unloadedNetworksCounter->
m_Uid);
338 const Counter* registeredBackendsCounter =
340 armnn::profiling::REGISTERED_BACKENDS,
345 "Backends registered",
346 "The number of registered backends",
347 std::string(
"backends"));
348 BOOST_ASSERT(registeredBackendsCounter);
349 InitializeCounterValue(registeredBackendsCounter->
m_Uid);
354 const Counter* unregisteredBackendsCounter =
356 armnn::profiling::UNREGISTERED_BACKENDS,
361 "Backends unregistered",
362 "The number of unregistered backends",
363 std::string(
"backends"));
364 BOOST_ASSERT(unregisteredBackendsCounter);
365 InitializeCounterValue(unregisteredBackendsCounter->
m_Uid);
370 const Counter* inferencesRunCounter =
372 armnn::profiling::INFERENCES_RUN,
378 "The number of inferences run",
379 std::string(
"inferences"));
380 BOOST_ASSERT(inferencesRunCounter);
381 InitializeCounterValue(inferencesRunCounter->
m_Uid);
385 void ProfilingService::InitializeCounterValue(uint16_t counterUid)
388 if (counterUid >= m_CounterIndex.size())
390 m_CounterIndex.resize(boost::numeric_cast<size_t>(counterUid) + 1);
394 m_CounterValues.emplace_back(0);
397 std::atomic<uint32_t>* counterValuePtr = &(m_CounterValues.back());
398 m_CounterIndex.at(counterUid) = counterValuePtr;
401 void ProfilingService::Reset()
407 m_CounterIndex.clear();
408 m_CounterValues.clear();
409 m_CounterDirectory.
Clear();
410 m_CounterIdMap.
Reset();
411 m_BufferManager.
Reset();
414 m_StateMachine.
Reset();
415 m_BackendProfilingContexts.clear();
416 m_MaxGlobalCounterId = armnn::profiling::INFERENCES_RUN;
419 void ProfilingService::Stop()
424 m_CommandHandler.
Stop();
425 m_PeriodicCounterCapture.
Stop();
427 m_SendThread.
Stop(
false);
430 if (m_ProfilingConnection !=
nullptr && m_ProfilingConnection->IsOpen())
432 m_ProfilingConnection->Close();
434 m_ProfilingConnection.reset();
440 inline void ProfilingService::CheckCounterUid(uint16_t counterUid)
const void Start(IProfilingConnection &profilingConnection) override
Start the thread.
ICounterRegistry & GetCounterRegistry()
uint32_t GetCounterValue(uint16_t counterUid) const override
uint32_t SubtractCounterValue(uint16_t counterUid, uint32_t value) override
uint32_t AddCounterValue(uint16_t counterUid, uint32_t value) override
const Category * RegisterCategory(const std::string &categoryName, const Optional< uint16_t > &deviceUid=EmptyOptional(), const Optional< uint16_t > &counterSetUid=EmptyOptional()) override
const ICounterMappings & GetCounterMappings() const override
ProfilingStaticGuid GenerateStaticId(const std::string &str) override
Create a ProfilingStaticGuid based on a hash of the string.
CaptureData GetCaptureData() const
void SetCaptureData(uint32_t capturePeriod, const std::vector< uint16_t > &counterIds, const std::set< armnn::BackendId > &activeBackends)
bool IsCategoryRegistered(const std::string &categoryName) const
IRegisterCounterMapping & GetCounterMappingRegistry()
ProfilingStaticGuid GenerateStaticId(const std::string &str) override
Create a ProfilingStaticGuid based on a hash of the string.
std::unique_ptr< ISendTimelinePacket > GetSendTimelinePacket() const
void TransitionToState(ProfilingState newState)
const Counter * RegisterCounter(const BackendId &backendId, const uint16_t uid, const std::string &parentCategoryName, uint16_t counterClass, uint16_t interpolation, double multiplier, const std::string &name, const std::string &description, const Optional< std::string > &units=EmptyOptional(), const Optional< uint16_t > &numberOfCores=EmptyOptional(), const Optional< uint16_t > &deviceUid=EmptyOptional(), const Optional< uint16_t > &counterSetUid=EmptyOptional()) override
ProfilingDynamicGuid NextGuid() override
Return the next random Guid in the sequence.
CaptureData GetCaptureData() override
void Stop(bool rethrowSendThreadExceptions=true) override
Stop the thread.
#define ARMNN_LOG(severity)
ProfilingDynamicGuid NextGuid() override
Return the next random Guid in the sequence.
void SetCounterValue(uint16_t counterUid, uint32_t value) override
void AddBackendProfilingContext(const BackendId backendId, std::shared_ptr< armnn::profiling::IBackendProfilingContext > profilingContext)
const ICounterDirectory & GetCounterDirectory() const
bool IsCounterRegistered(uint16_t counterUid) const override
bool IsProfilingEnabled() const override
virtual const char * what() const noexcept override
void Start(IProfilingConnection &profilingConnection)
uint16_t GetCounterCount() const override
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
ProfilingState GetCurrentState() const
uint32_t IncrementCounterValue(uint16_t counterUid) override
Base class for all ArmNN exceptions so that users can filter to just those.
Strongly typed guids to distinguish between those generated at runtime, and those that are statically...
uint16_t GetCounterCount() const override
ProfilingState GetCurrentState() const
std::unique_ptr< ISendTimelinePacket > GetSendTimelinePacket() const override
ProfilingState ConfigureProfilingService(const ExternalProfilingOptions &options, bool resetProfilingService=false)
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
bool IsCounterRegistered(uint16_t counterUid) const
void SetCaptureData(uint32_t capturePeriod, const std::vector< uint16_t > &counterIds, const std::set< BackendId > &activeBackends)