-
Notifications
You must be signed in to change notification settings - Fork 46
/
gpa_derived_counter.h
274 lines (237 loc) · 11.1 KB
/
gpa_derived_counter.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
//==============================================================================
// Copyright (c) 2016-2023 Advanced Micro Devices, Inc. All rights reserved.
/// @author AMD Developer Tools Team
/// @file
/// @brief Manages a set of derived counters.
//==============================================================================
#ifndef GPU_PERF_API_COUNTER_GENERATOR_COMMON_GPA_DERIVED_COUNTER_H_
#define GPU_PERF_API_COUNTER_GENERATOR_COMMON_GPA_DERIVED_COUNTER_H_
#include <assert.h>
#include <vector>
#include "gpu_performance_api/gpu_perf_api_counters.h"
#include "gpu_perf_api_common/gpa_hw_info.h"
class IGpaCounterAccessor;
using std::vector;
/// @brief Information about a derived counter that is exposed through the interface.
class GpaDerivedCounterInfoClass
{
public:
/// @brief Constructor taking a compute expression string.
///
/// @param [in] index The index of the derived counter.
/// @param [in] counter_name The name of the derived counter.
/// @param [in] counter_group The group of the derived counter.
/// @param [in] counter_description The description of the derived counter.
/// @param [in] data_type The data type of the derived counter.
/// @param [in] usage_type The usage type of the derived counter.
/// @param [in] internal_counters_required The list of hardware counters required by the derived counter.
/// @param [in] compute_expression The formula used to compute the derived counter.
/// @param [in] uuid UUID string that uniquely and consistently identifies the derived counter.
GpaDerivedCounterInfoClass(unsigned int index,
const char* counter_name,
const char* counter_group,
const char* counter_description,
GpaDataType data_type,
GpaUsageType usage_type,
vector<GpaUInt32>& internal_counters_required,
const char* compute_expression,
const char* uuid);
/// @brief Default Constructor.
///
/// Temporary addition of a default constructor to allow vector to build and execute.
GpaDerivedCounterInfoClass();
/// @brief Destructor.
~GpaDerivedCounterInfoClass();
/// @brief Returns the derived counter info.
///
/// @param [in] gpa_counter_accessor Hardware counter accessor.
///
/// @return Pointer to derived counter info.
GpaCounterInfo* GetCounterInfo(const IGpaCounterAccessor* gpa_counter_accessor);
unsigned int counter_index_; ///< Index of this counter.
const char* counter_name_; ///< The name of the counter.
const char* counter_group_; ///< A group to which the counter is related.
const char* counter_description_; ///< A description of what the counter means.
GpaDataType data_type_; ///< Data type.
GpaUsageType usage_type_; ///< How the counter should be interpreted (percentage, ratio, bytes, etc).
vector<GpaUInt32> internal_counters_required_; ///< List of internal counters that are needed to calculate this derived counter.
const char* compute_expression_; ///< A string expression that shows how to calculate this counter.
GpaUuid uuid_ = {}; ///< UUID that uniquely and consistently identifies a counter.
private:
/// @brief Initializes the derived counter info.
///
/// @param [in] gpa_counter_accessor Hardware counter accessor.
///
/// @return True upon success otherwise false.
bool InitializeDerivedCounterHardwareInfo(const IGpaCounterAccessor* gpa_counter_accessor);
GpaCounterInfo* counter_info_; ///< Derived counter info for the counter.
bool derived_counter_info_init_; ///< Flag indicating derive counter is initialized.
std::vector<GpaHwCounter> hw_counter_info_list_; ///< List of gpa hardware counter.
};
/// @brief The set of available derived counters.
class GpaDerivedCounters
{
public:
/// @brief Initializes an instance of the GpaDerivedCounters class.
GpaDerivedCounters()
: counters_generated_(false)
{
}
/// @brief Virtual destructor.
virtual ~GpaDerivedCounters() = default;
/// @brief Obtains the number of derived counters.
///
/// @return The number of derived counters.
virtual GpaUInt32 GetNumCounters() const;
/// @brief Gets a counter's name.
///
/// @param [in] index The index of the requested counter.
///
/// @return The counter's name.
virtual const char* GetCounterName(GpaUInt32 index) const
{
assert(index < derived_counter_list_.size());
return derived_counter_list_[index].counter_name_;
}
/// @brief Gets a counter's group name.
///
/// @param [in] index The index of the requested counter.
///
/// @return The counter's group name.
virtual const char* GetCounterGroup(GpaUInt32 index) const
{
assert(index < derived_counter_list_.size());
return derived_counter_list_[index].counter_group_;
}
/// @brief Gets a counter's description.
///
/// @param [in] index The index of the requested counter.
///
/// @return The counter's description.
virtual const char* GetCounterDescription(GpaUInt32 index) const
{
assert(index < derived_counter_list_.size());
return derived_counter_list_[index].counter_description_;
}
/// @brief Gets a counter's usage type.
///
/// @param [in] index The index of the requested counter.
///
/// @return The counter's usage type.
virtual GpaUsageType GetCounterUsageType(GpaUInt32 index) const
{
assert(index < derived_counter_list_.size());
return derived_counter_list_[index].usage_type_;
}
/// @brief Gets a counter's data type.
///
/// @param [in] index The index of the requested counter.
///
/// @return The counter's data type.
virtual GpaDataType GetCounterDataType(GpaUInt32 index) const
{
assert(index < derived_counter_list_.size());
return derived_counter_list_[index].data_type_;
}
/// @brief Gets a counter's UUID.
///
/// @param [in] index The index of the requested counter.
///
/// @return The counter's UUID.
virtual GpaUuid GetCounterUuid(GpaUInt32 index) const
{
assert(index < derived_counter_list_.size());
return derived_counter_list_[index].uuid_;
}
/// @brief Gets a counter's supported sample type.
///
/// @param [in] index The index of the requested counter.
///
/// @return The counter's supported sample types (a combination of GpaCounterSampleBits).
virtual GpaCounterSampleType GetCounterSampleType(GpaUInt32 index) const
{
assert(index < derived_counter_list_.size());
GpaCounterSampleType type = kGpaCounterSampleTypeDiscrete;
UNREFERENCED_PARAMETER(index);
return type;
}
/// @brief Defines a public counter based on an expression.
///
/// @param [in] counter_name The name of the counter.
/// @param [in] counter_group The group that the counter is related to.
/// @param [in] counter_description The description of the counter.
/// @param [in] data_type The data type of the counter.
/// @param [in] usage_type The usage type of the counter.
/// @param [in] internal_counters_required The list of required internal counters.
/// @param [in] compute_expression The compute expression of the counter.
/// @param [in] uuid UUID string that uniquely and consistently identifies the counter.
virtual void DefineDerivedCounter(const char* counter_name,
const char* counter_group,
const char* counter_description,
GpaDataType data_type,
GpaUsageType usage_type,
vector<GpaUInt32>& internal_counters_required,
const char* compute_expression,
const char* uuid);
/// @brief Updates an existing derived counter based on ASIC-specific registers.
///
/// @param [in] counter_name The name of the counter.
/// @param [in] internal_counters_required The list of required internal counters.
/// @param [in] compute_expression The compute expression of the counter.
virtual void UpdateAsicSpecificDerivedCounter(const char* counter_name, vector<GpaUInt32>& internal_counters_required, const char* compute_expression);
/// @brief Adds a derived counter to the set of available counters.
///
/// @param [in] derived_counter the derived counter to add.
virtual void AddDerivedCounter(GpaDerivedCounterInfoClass& derived_counter)
{
derived_counter_list_.push_back(derived_counter);
}
/// @brief Get the counter at the specified index.
///
/// @param [in] index The index of the requested counter.
///
/// @return The counter at the specified index.
virtual const GpaDerivedCounterInfoClass* GetCounter(GpaUInt32 index) const
{
assert(index < derived_counter_list_.size());
return &derived_counter_list_[index];
}
/// @brief Clears the list of available counters.
virtual void Clear();
/// @brief Gets the list of internal counters that are required for a derived counter.
///
/// @param [in] index The index of the requested counter.
///
/// @return The list of internal counters.
virtual const vector<GpaUInt32>& GetInternalCountersRequired(GpaUInt32 index) const
{
assert(index < derived_counter_list_.size());
return derived_counter_list_[index].internal_counters_required_;
}
/// @brief Computes a counter's result.
///
/// @param [in] counter_index The index of the counter.
/// @param [in] results The counter results buffer.
/// @param [in] internal_counter_types The list of internal counter types.
/// @param [in] result The result of the computation.
/// @param [in] hw_info The hardware info for the current hardware.
///
/// @return kGpaStatusOk on success, otherwise an error code.
virtual GpaStatus ComputeCounterValue(GpaUInt32 counter_index,
const vector<const GpaUInt64*>& results,
vector<GpaDataType>& internal_counter_types,
void* result,
const GpaHwInfo* hw_info) const;
bool GetCountersGenerated() const
{
return counters_generated_;
}
void SetCountersGenerated(bool generated)
{
counters_generated_ = generated;
}
protected:
vector<GpaDerivedCounterInfoClass> derived_counter_list_; ///< The set of available derived counters.
bool counters_generated_; ///< Indicates that the derived counters have been generated.
};
#endif // GPU_PERF_API_COUNTER_GENERATOR_COMMON_GPA_DERIVED_COUNTER_H_