1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
//
// Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
// SPDX-License-Identifier: MIT
//
#pragma once
#include "IProfilingGuidGenerator.hpp"
#include "ProfilingGuid.hpp"
#include <functional>
#include <mutex>
namespace arm
{
namespace pipe
{
class ProfilingGuidGenerator : public IProfilingGuidGenerator
{
public:
/// Construct a generator with the default address space static/dynamic partitioning
ProfilingGuidGenerator() : m_Sequence(0) {}
/// Return the next random Guid in the sequence
inline ProfilingDynamicGuid NextGuid() override
{
#if !defined(ARMNN_DISABLE_THREADS)
std::lock_guard<std::mutex> sequencelock(m_SequenceMutex);
#endif
ProfilingDynamicGuid guid(m_Sequence);
m_Sequence++;
if (m_Sequence >= MIN_STATIC_GUID)
{
// Reset the sequence to 0 when it reaches the upper bound of dynamic guid
m_Sequence = 0;
}
return guid;
}
/// Create a ProfilingStaticGuid based on a hash of the string
inline ProfilingStaticGuid GenerateStaticId(const std::string& str) override
{
uint64_t staticHash = m_Hash(str) | MIN_STATIC_GUID;
return ProfilingStaticGuid(staticHash);
}
/// Reset the generator back to zero. Used mainly for test.
inline void Reset()
{
#if !defined(ARMNN_DISABLE_THREADS)
std::lock_guard<std::mutex> sequencelock(m_SequenceMutex);
#endif
m_Sequence = 0;
}
private:
std::hash<std::string> m_Hash;
uint64_t m_Sequence;
#if !defined(ARMNN_DISABLE_THREADS)
std::mutex m_SequenceMutex;
#endif
};
} // namespace pipe
} // namespace arm
|