blob: 45f523c98045b2596f21ca9e5a2f541c34f2f144 [file] [log] [blame]
Narumol Prangnawarat15effd82019-10-22 14:17:11 +01001//
2// Copyright © 2019 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#pragma once
7
Jim Flynn6b1bf1a2020-01-22 15:18:49 +00008#include "armnn/IProfilingGuidGenerator.hpp"
Narumol Prangnawarat15effd82019-10-22 14:17:11 +01009
Jim Flynnab845752019-10-25 13:17:30 +010010#include <functional>
11
Narumol Prangnawarat15effd82019-10-22 14:17:11 +010012namespace armnn
13{
14
15namespace profiling
16{
17
Jim Flynn00f3aaf2019-10-24 11:58:06 +010018class ProfilingGuidGenerator : public IProfilingGuidGenerator
Narumol Prangnawarat15effd82019-10-22 14:17:11 +010019{
20public:
21 /// Construct a generator with the default address space static/dynamic partitioning
Jim Flynnab845752019-10-25 13:17:30 +010022 ProfilingGuidGenerator() : m_Sequence(0) {}
Narumol Prangnawarat15effd82019-10-22 14:17:11 +010023
24 /// Return the next random Guid in the sequence
Jim Flynnab845752019-10-25 13:17:30 +010025 inline ProfilingDynamicGuid NextGuid() override
26 {
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +000027 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 Flynnab845752019-10-25 13:17:30 +010034 return guid;
35 }
Narumol Prangnawarat15effd82019-10-22 14:17:11 +010036
Jim Flynn00f3aaf2019-10-24 11:58:06 +010037 /// Create a ProfilingStaticGuid based on a hash of the string
Jim Flynnab845752019-10-25 13:17:30 +010038 inline ProfilingStaticGuid GenerateStaticId(const std::string& str) override
39 {
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +000040 uint64_t staticHash = m_Hash(str) | MIN_STATIC_GUID;
41 return ProfilingStaticGuid(staticHash);
Jim Flynnab845752019-10-25 13:17:30 +010042 }
43
44private:
Jim Flynnab845752019-10-25 13:17:30 +010045 uint64_t m_Sequence;
Narumol Prangnawaratdbdd1b42019-11-15 17:38:44 +000046 std::hash<std::string> m_Hash;
Narumol Prangnawarat15effd82019-10-22 14:17:11 +010047};
48
49} // namespace profiling
50
51} // namespace armnn