forked from GPUOpen-Tools/gpu_performance_api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgpa_session.h
211 lines (156 loc) · 9.62 KB
/
gpa_session.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
//==============================================================================
// Copyright (c) 2017-2021 Advanced Micro Devices, Inc. All rights reserved.
/// @author AMD Developer Tools Team
/// @file
/// @brief A base-class implementation of the GPA Session interface.
//==============================================================================
#ifndef GPU_PERF_API_COMMON_GPA_SESSION_H_
#define GPU_PERF_API_COMMON_GPA_SESSION_H_
#include "gpu_perf_api_counter_generator/gpa_counter_scheduler_interface.h"
#include "gpu_perf_api_common/gpa_pass.h"
#include "gpu_perf_api_common/gpa_session_interface.h"
using PassInfo = std::vector<GpaPass*>; ///< Type alias for pass index and its corresponding pass.
/// Timeout constant indicating "infinite", or no, timeout.
const uint32_t kGpaTimeoutInfinite = static_cast<uint32_t>(-1);
/// @brief Base class implementation for the IGpaSession.
class GpaSession : public IGpaSession
{
public:
/// @brief Constructor.
///
/// @param [in] parent_context The context Id on which this session is created.
/// @param [in] sample_type The type of samples that will be created on this session.
GpaSession(IGpaContext* parent_context, GpaSessionSampleType sample_type);
/// @brief Delete default constructor.
GpaSession() = delete;
/// @brief Virtual Destructor.
virtual ~GpaSession();
/// @copydoc IGpaInterfaceTrait::ObjectType()
GpaObjectType ObjectType() const override;
/// @copydoc IGpaSession::GetParentContext()
IGpaContext* GetParentContext() const override;
/// @copydoc IGpaSession::GetState()
GpaSessionState GetState() const override;
/// @copydoc IGpaSession::EnableCounter()
GpaStatus EnableCounter(GpaUInt32 index) override;
/// @copydoc IGpaSession::DisableCounter()
GpaStatus DisableCounter(GpaUInt32 index) override;
/// @copydoc IGpaSession::DisableAllCounters()
GpaStatus DisableAllCounters() override;
/// @copydoc IGpaSession::GetNumEnabledCounters()
GpaStatus GetNumEnabledCounters(GpaUInt32* counter_count) const override;
/// @copydoc IGpaSession::GetEnabledIndex()
GpaStatus GetEnabledIndex(GpaUInt32 enabled_number, GpaUInt32* enabled_counter_index) const override;
/// @copydoc IGpaSession::IsCounterEnabled()
GpaStatus IsCounterEnabled(GpaUInt32 counter_index) const override;
/// @copydoc IGpaSession::GetNumRequiredPasses()
GpaStatus GetNumRequiredPasses(GpaUInt32* num_passes) override;
/// @copydoc IGpaSession::Begin()
GpaStatus Begin() override;
/// @copydoc IGpaSession::End()
GpaStatus End() override;
/// @copydoc IGpaSession::CreateCommandList()
GpaCommandListId CreateCommandList(GpaUInt32 pass_index, void* cmd_list, GpaCommandListType cmd_type) override;
/// @copydoc IGpaSession::GetSampleCount()
GpaUInt32 GetSampleCount() const override;
/// @copydoc IGpaSession::GetSampleIdByIndex()
bool GetSampleIdByIndex(SampleIndex sample_index, ClientSampleId& client_sample_id) const override;
/// @copydoc IGpaSession::DoesCommandListExist()
bool DoesCommandListExist(GpaUInt32 pass_index, GpaCommandListId gpa_command_list_id) const override;
/// @copydoc IGpaSession::DoesSampleExist()
bool DoesSampleExist(GpaUInt32 sample_id) const override;
/// @copydoc IGpaSession::BeginSample()
bool BeginSample(ClientSampleId sample_id, GpaCommandListId command_list_id) override;
/// @copydoc IGpaSession::EndSample()
bool EndSample(GpaCommandListId command_list_id) override;
/// @copydoc IGpaSession::ContinueSampleOnCommandList()
GpaStatus ContinueSampleOnCommandList(GpaUInt32 src_sample_id, GpaCommandListId primary_command_list_id) override;
/// @copydoc IGpaSession::CopySecondarySamples()
GpaStatus CopySecondarySamples(GpaCommandListId secondary_cmd_list_id,
GpaCommandListId primary_cmd_list_id,
GpaUInt32 num_samples,
GpaUInt32* new_sample_ids) override;
/// @copydoc IGpaSession::UpdateResults()
bool UpdateResults() override;
/// @copydoc IGpaSession::UpdateResults(GpaUInt32)
bool UpdateResults(GpaUInt32 pass_index) override;
/// @copydoc IGpaSession::IsSessionRunning()
bool IsSessionRunning() const override;
/// @copydoc IGpaSession::IsPassComplete()
GpaStatus IsPassComplete(GpaUInt32 pass_index) const override;
/// @copydoc IGpaSession::IsResultReady()
bool IsResultReady() const override;
/// @copydoc IGpaSession::GetSampleResultSizeInBytes()
size_t GetSampleResultSizeInBytes(GpaUInt32 sample_id) const override;
/// @copydoc IGpaSession::GetSampleResult()
GpaStatus GetSampleResult(GpaUInt32 sample_id, size_t sample_result_size_in_bytes, void* counter_sample_results) override;
/// @copydoc IGpaSession::GetSampleType()
GpaSessionSampleType GetSampleType() const override;
/// @copydoc IGpaSession::GetSpmInterval()
GpaUInt32 GetSpmInterval() const override;
/// @copydoc IGpaSession::SetSpmInterval()
void SetSpmInterval(GpaUInt32 interval) override;
/// @copydoc IGpaSession::GetSpmMemoryLimit()
GpaUInt64 GetSpmMemoryLimit() const override;
/// @copydoc IGpaSession::SetSpmMemoryLimit()
void SetSpmMemoryLimit(GpaUInt64 memory_limit) override;
/// @copydoc IGpaSession::GetSqttInstructionMask()
GpaSqttInstructionFlags GetSqttInstructionMask() const override;
/// @copydoc IGpaSession::SetSqttInstructionMask()
void SetSqttInstructionMask(GpaSqttInstructionFlags sqtt_instruction_mask) override;
/// @copydoc IGpaSession::GetSqttComputeUnitId()
GpaUInt32 GetSqttComputeUnitId() const override;
/// @copydoc IGpaSession::SetSqttComputeUnitId()
void SetSqttComputeUnitId(GpaUInt32 sqtt_compute_unit_id) override;
/// @copydoc IGpaSession::GetSqttMemoryLimit()
GpaUInt64 GetSqttMemoryLimit() const override;
/// @copydoc IGpaSession::SetSqttMemoryLimit()
void SetSqttMemoryLimit(GpaUInt64 memory_limit) override;
/// @copydoc IGpaSession::GetCountersForPass()
CounterList* GetCountersForPass(PassIndex pass_index) override;
protected:
/// @brief Checks whether the multiple passes in the session have same number of samples.
///
/// @return True if number of samples in each are same.
bool CheckWhetherPassesAreFinishedAndConsistent() const;
/// @brief Creates the API specific pass.
///
/// @param [in] pass_index Index of the pass.
///
/// @return API specific pass object pointer.
virtual GpaPass* CreateApiPass(PassIndex pass_index) = 0;
private:
/// @brief Waits for all data requests to be complete (blocking).
///
/// @param [in] timeout The amount of time (in milliseconds) to wait before giving up.
///
/// @return True if all data requests are complete, false if a timeout occurred.
virtual bool Flush(uint32_t timeout = kGpaTimeoutInfinite);
/// @brief Gathers the counter result locations.
///
/// @return True upon successful copying otherwise false.
bool GatherCounterResultLocations();
using SessionCounters = std::vector<GpaUInt32>; ///< Type alias for counters in the session.
using CounterResultLocationPair = std::pair<DerivedCounterIndex, CounterResultLocationMap>; ///< Type alias for counter and its result location pair.
using CounterResultLocations = std::map<DerivedCounterIndex, CounterResultLocationMap>; ///< Type alias for counter and its result location map.
using PassCountersPair = std::pair<PassIndex, CounterList>; ///< Type alias for pass and its counters pair.
using PassCountersMap = std::map<PassIndex, CounterList>; ///< Type alias for pass and its counters map.
mutable std::mutex gpa_session_mutex_; ///< Mutex GPA session.
mutable GpaSessionState gpa_session_state_; ///< The state of the session.
IGpaContext* parent_context_; ///< The context on which this session was created.
PassInfo passes_; ///< List of pass objects in the session.
PassIndex max_pass_index_; ///< Maximum pass index reported for creating command list.
GpaSessionSampleType sample_type_; ///< The sample type supported by the session.
GpaUInt32 spm_interval_; ///< The interval (in clock cycles) at which to sample SPM counters.
GpaUInt64 spm_memory_limit_; ///< The maximum amount of GPU memory (in bytes) to use for SPM data.
GpaSqttInstructionFlags sqtt_instruction_mask_; ///< Mask of instructions included in the SQTT data.
GpaUInt32 sqtt_compute_unit_id_; ///< Id of the compute unit which should generate the instruction level data.
GpaUInt64 sqtt_memory_limit_; ///< The maximum amount of GPU memory (in bytes) to use for SQTT data.
SessionCounters session_counters_; ///< List of counters enabled in the session.
std::mutex session_counters_mutex_; ///< Mutex for enabled counter list.
GpaUInt32 pass_required_; ///< Cached number of passes.
bool counter_set_changed_; ///< Flag indicating the counter selection has changed or not for the pass.
CounterResultLocations counter_result_locations_; ///< Counter result location for the scheduled counter in the session.
PassCountersMap pass_counters_map_; ///< Map for the pass and its counters.
};
#endif // GPU_PERF_API_COMMON_GPA_SESSION_H_