From 6db5f20ade72896ebf0f6513a4832b8f2e917aa0 Mon Sep 17 00:00:00 2001 From: Matteo Martincigh Date: Thu, 5 Sep 2019 12:02:04 +0100 Subject: IVGCVSW-3691 Rework the CounterDirectory class to take into consideration the connections between components * Added constructors and connections to the profiling classes * Used hash table to keep track of the profiling objects by UID * Added register methods * Added find/check helper methods * Updated the makefile to include the profiling directory * Added unit tests for the CounterDirectory class * Added ICounterDirectory interface class for read-only use * Added custom macro to locally disable conversion warnings Change-Id: I3f53a68663ee77b8d03ac0ef7dc01e90c6893511 Signed-off-by: Matteo Martincigh --- src/profiling/ProfilingUtils.cpp | 73 +++++++++++++++++++++++++++++++++------- 1 file changed, 60 insertions(+), 13 deletions(-) (limited to 'src/profiling/ProfilingUtils.cpp') diff --git a/src/profiling/ProfilingUtils.cpp b/src/profiling/ProfilingUtils.cpp index ef67f0324c..e356ed739e 100644 --- a/src/profiling/ProfilingUtils.cpp +++ b/src/profiling/ProfilingUtils.cpp @@ -6,12 +6,12 @@ #include "ProfilingUtils.hpp" #include +#include #include #include #include -#include namespace armnn { @@ -19,25 +19,72 @@ namespace armnn namespace profiling { -uint16_t GetNextUid() +namespace { - // Static mutex for reading and modifying the global UID a single thread at the time - static std::mutex mutex; - std::unique_lock lock(mutex); +void ThrowIfCantGenerateNextUid(uint16_t uid, uint16_t cores = 0) +{ + // Check that it is possible to generate the next UID without causing an overflow + switch (cores) + { + case 0: + case 1: + // Number of cores not specified or set to 1 (a value of zero indicates the device is not capable of + // running multiple parallel workloads and will not provide multiple streams of data for each event) + if (uid == std::numeric_limits::max()) + { + throw RuntimeException("Generating the next UID for profiling would result in an overflow"); + } + break; + default: // cores > 1 + // Multiple cores available, as max_counter_uid has to be set to: counter_uid + cores - 1, the maximum + // allowed value for a counter UID is consequently: uint16_t_max - cores + 1 + if (uid >= std::numeric_limits::max() - cores + 1) + { + throw RuntimeException("Generating the next UID for profiling would result in an overflow"); + } + break; + } +} + +} // Anonymous namespace + +uint16_t GetNextUid(bool peekOnly) +{ // The UID used for profiling objects and events. The first valid UID is 1, as 0 is a reserved value - // (it is used to indicate that a record is not associated with any device) - static uint16_t uid{ 0 }; + static uint16_t uid = 1; - // Check that it is possible to generate the next UID without causing an overflow - if (uid == std::numeric_limits::max()) + // Check that it is possible to generate the next UID without causing an overflow (throws in case of error) + ThrowIfCantGenerateNextUid(uid); + + if (peekOnly) + { + // Peek only + return uid; + } + else { - throw RuntimeException("Generating the next UID for profiling would result in an overflow"); + // Get the next UID + return uid++; } +} - // Thread safe increment, the value that is incremented is the value checked for overflow, - // as this whole function is mutexed - return ++uid; +std::vector GetNextCounterUids(uint16_t cores) +{ + // The UID used for counters only. The first valid UID is 0 + static uint16_t counterUid = 0; + + // Check that it is possible to generate the next counter UID without causing an overflow (throws in case of error) + ThrowIfCantGenerateNextUid(counterUid, cores); + + // Get the next counter UIDs + size_t counterUidsSize = cores == 0 ? 1 : cores; + std::vector counterUids(counterUidsSize, 0); + for (size_t i = 0; i < counterUidsSize; i++) + { + counterUids[i] = counterUid++; + } + return counterUids; } void WriteUint64(unsigned char* buffer, unsigned int offset, uint64_t value) -- cgit v1.2.1