Narumol Prangnawarat | 15effd8 | 2019-10-22 14:17:11 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2019 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
Colm Donelan | 5ccb33d | 2020-01-24 16:27:02 +0000 | [diff] [blame] | 8 | #include "armnn/profiling/IProfilingGuidGenerator.hpp" |
Narumol Prangnawarat | 15effd8 | 2019-10-22 14:17:11 +0100 | [diff] [blame] | 9 | |
Jim Flynn | ab84575 | 2019-10-25 13:17:30 +0100 | [diff] [blame] | 10 | #include <functional> |
| 11 | |
Narumol Prangnawarat | 15effd8 | 2019-10-22 14:17:11 +0100 | [diff] [blame] | 12 | namespace armnn |
| 13 | { |
| 14 | |
| 15 | namespace profiling |
| 16 | { |
| 17 | |
Jim Flynn | 00f3aaf | 2019-10-24 11:58:06 +0100 | [diff] [blame] | 18 | class ProfilingGuidGenerator : public IProfilingGuidGenerator |
Narumol Prangnawarat | 15effd8 | 2019-10-22 14:17:11 +0100 | [diff] [blame] | 19 | { |
| 20 | public: |
| 21 | /// Construct a generator with the default address space static/dynamic partitioning |
Jim Flynn | ab84575 | 2019-10-25 13:17:30 +0100 | [diff] [blame] | 22 | ProfilingGuidGenerator() : m_Sequence(0) {} |
Narumol Prangnawarat | 15effd8 | 2019-10-22 14:17:11 +0100 | [diff] [blame] | 23 | |
| 24 | /// Return the next random Guid in the sequence |
Jim Flynn | ab84575 | 2019-10-25 13:17:30 +0100 | [diff] [blame] | 25 | inline ProfilingDynamicGuid NextGuid() override |
| 26 | { |
Narumol Prangnawarat | dbdd1b4 | 2019-11-15 17:38:44 +0000 | [diff] [blame] | 27 | ProfilingDynamicGuid guid(m_Sequence); |
| 28 | m_Sequence++; |
| 29 | if (m_Sequence >= MIN_STATIC_GUID) |
| 30 | { |
| 31 | // Reset the sequence to 0 when it reaches the upper bound of dynamic guid |
| 32 | m_Sequence = 0; |
| 33 | } |
Jim Flynn | ab84575 | 2019-10-25 13:17:30 +0100 | [diff] [blame] | 34 | return guid; |
| 35 | } |
Narumol Prangnawarat | 15effd8 | 2019-10-22 14:17:11 +0100 | [diff] [blame] | 36 | |
Jim Flynn | 00f3aaf | 2019-10-24 11:58:06 +0100 | [diff] [blame] | 37 | /// Create a ProfilingStaticGuid based on a hash of the string |
Jim Flynn | ab84575 | 2019-10-25 13:17:30 +0100 | [diff] [blame] | 38 | inline ProfilingStaticGuid GenerateStaticId(const std::string& str) override |
| 39 | { |
Narumol Prangnawarat | dbdd1b4 | 2019-11-15 17:38:44 +0000 | [diff] [blame] | 40 | uint64_t staticHash = m_Hash(str) | MIN_STATIC_GUID; |
| 41 | return ProfilingStaticGuid(staticHash); |
Jim Flynn | ab84575 | 2019-10-25 13:17:30 +0100 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | private: |
Jim Flynn | ab84575 | 2019-10-25 13:17:30 +0100 | [diff] [blame] | 45 | uint64_t m_Sequence; |
Narumol Prangnawarat | dbdd1b4 | 2019-11-15 17:38:44 +0000 | [diff] [blame] | 46 | std::hash<std::string> m_Hash; |
Narumol Prangnawarat | 15effd8 | 2019-10-22 14:17:11 +0100 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | } // namespace profiling |
| 50 | |
| 51 | } // namespace armnn |