-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathgpa_context.h
146 lines (111 loc) · 5.84 KB
/
gpa_context.h
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//==============================================================================
// Copyright (c) 2017-2025 Advanced Micro Devices, Inc. All rights reserved.
/// @author AMD Developer Tools Team
/// @file
/// @brief GPA Common Context class.
//==============================================================================
#ifndef GPU_PERF_API_COMMON_GPA_CONTEXT_H_
#define GPU_PERF_API_COMMON_GPA_CONTEXT_H_
#include <functional>
#include <list>
#include <mutex>
#include <numeric>
#include "gpu_performance_api/gpu_perf_api_types.h"
#include "gpu_perf_api_common/gpa_common_defs.h"
#include "gpu_perf_api_common/gpa_context_interface.h"
#include "gpu_perf_api_common/gpa_session_interface.h"
/// @brief Type alias for list of IGpaSession objects.
using GpaSessionList = std::list<IGpaSession*>;
/// @brief Abstract GPAContext for common context code.
class GpaContext : public IGpaContext
{
public:
/// @brief Delete default constructor.
GpaContext() = delete;
/// @brief Virtual Destructor.
virtual ~GpaContext();
/// @copydoc IGpaContext::GetSupportedSampleTypes()
GpaStatus GetSupportedSampleTypes(GpaContextSampleTypeFlags* sample_types) const override;
/// @copydoc IGpaContext::ArePublicCountersExposed()
bool ArePublicCountersExposed() const override;
/// @copydoc IGpaContext::AreHardwareCountersExposed()
bool AreHardwareCountersExposed() const override;
/// @copydoc IGpaContext::SetInvalidateAndFlushL2Cache()
void SetInvalidateAndFlushL2Cache(bool should_invalidate_and_flush_l2_cache) override;
/// @copydoc IGpaContext::IsInvalidateAndFlushL2CacheEnabled()
bool IsInvalidateAndFlushL2CacheEnabled() const override;
/// @copydoc IGpaContext::GetHwInfo()
const GpaHwInfo* GetHwInfo() const override;
/// @copydoc IGpaContext::UpdateHwInfo()
void UpdateHwInfo(GpaUInt32 num_shader_engines, GpaUInt32 num_compute_units, GpaUInt32 num_simds, GpaUInt32 num_waves_per_simd) override;
/// @copydoc IGpaContext::IsOpen()
bool IsOpen() const override;
/// @copydoc IGpaContext::GetDeviceClockMode()
DeviceClockMode GetDeviceClockMode() const override;
/// @copydoc IGpaInterfaceTrait::ObjectType()
GpaObjectType ObjectType() const override;
/// @copydoc IGpaContext::DoesSessionExist()
bool DoesSessionExist(GpaSessionId gpa_session_id) const override;
/// @copydoc IGpaContext::GetSessionCount()
GpaUInt32 GetSessionCount() const override;
/// @copydoc IGpaContext::BeginSession()
GpaStatus BeginSession(IGpaSession* gpa_session) override;
/// @copydoc IGpaContext::EndSession()
GpaStatus EndSession(IGpaSession* gpa_session, bool force_end) override;
/// @copydoc IGpaContext::GetShaderEngineCount()
uint32_t GetShaderEngineCount() const override;
/// @copydoc IGpaContext::GetContextFlags()
GpaOpenContextFlags GetContextFlags() const override
{
return context_flags_;
}
/// @copydoc IGpaContext::GetActiveSession()
const IGpaSession* GetActiveSession() const override;
protected:
/// @brief Protected constructor.
///
/// @param [in] hw_info The hardware info for the context.
/// @param [in] flags Creation flags for context.
GpaContext(GpaHwInfo& hw_info, GpaOpenContextFlags flags);
/// @brief Marks the context to be opened.
///
/// @param [in] open Flag indicating context to be marked open or closed.
void SetAsOpened(bool open);
/// @brief Returns whether the device is AMD device or not.
///
/// @return true if context device is AMD device otherwise false.
bool IsAmdDevice() const;
/// @brief Adds the GPA session to the session list.
///
/// @param [in] gpa_session GPA session object pointer.
GPA_THREAD_SAFE_FUNCTION void AddGpaSession(IGpaSession* gpa_session);
/// @brief Removes the GPA session from the session list.
///
/// @param [in] gpa_session GPA session object pointer.
GPA_THREAD_SAFE_FUNCTION void RemoveGpaSession(IGpaSession* gpa_session);
/// @brief Iterate over GPA session list for the passed function.
///
/// @param [in] function Function to be executed for each object in the list. The function may return false to terminate iteration.
GPA_THREAD_SAFE_FUNCTION void IterateGpaSessionList(std::function<bool(IGpaSession* gpa_session)> function) const;
/// @brief Clears the list of the GPA session.
GPA_THREAD_SAFE_FUNCTION void ClearSessionList();
/// @brief Returns the index of the GPA session if it exists.
///
/// @param [in] gpa_session GPA session.
/// @param [out] index Index of the the GPA session in the list.
///
/// @return True if the index was found, false otherwise.
bool GetIndex(IGpaSession* gpa_session, unsigned int* index = nullptr) const;
GpaContextSampleTypeFlags supported_sample_types_; ///< The supported sample types. Expected to be set by the derived class.
private:
GpaOpenContextFlags context_flags_; ///< Context flags.
GpaHwInfo hw_info_; ///< Hw info.
bool invalidate_and_flush_l2_cache_enabled_; ///< Flag indicating flush and invalidation of L2 cache is enabled or not.
bool is_open_; ///< Flag indicating context is open or not.
GpaSessionList gpa_session_list_; ///< List of GPA sessions in the context.
bool is_amd_device_; ///< Flag indicating whether the device is AMD or not.
mutable std::mutex gpa_session_list_mutex_; ///< Mutex for GPA session list.
IGpaSession* active_session_; ///< Gpa session to keep track of active session.
mutable std::mutex active_session_mutex_; ///< Mutex for the active session.
};
#endif // GPU_PERF_API_COMMON_GPA_CONTEXT_H_