diff options
author | Matteo Martincigh <matteo.martincigh@arm.com> | 2019-09-05 12:02:04 +0100 |
---|---|---|
committer | Jim Flynn Arm <jim.flynn@arm.com> | 2019-09-17 15:48:37 +0000 |
commit | 6db5f20ade72896ebf0f6513a4832b8f2e917aa0 (patch) | |
tree | 654e0502a35d6fa11c51be31edf60a6106a15a54 /src/profiling/ProfilingUtils.cpp | |
parent | 10e0786f15bdb60e1d632c9a368fce2737852ae4 (diff) | |
download | armnn-6db5f20ade72896ebf0f6513a4832b8f2e917aa0.tar.gz |
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 <matteo.martincigh@arm.com>
Diffstat (limited to 'src/profiling/ProfilingUtils.cpp')
-rw-r--r-- | src/profiling/ProfilingUtils.cpp | 73 |
1 files changed, 60 insertions, 13 deletions
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 <armnn/Version.hpp> +#include <armnn/Conversion.hpp> #include <boost/assert.hpp> #include <fstream> #include <limits> -#include <mutex> 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<std::mutex> 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<uint16_t>::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<uint16_t>::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<uint16_t>::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<uint16_t> 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<uint16_t> 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) |