Skip to content

Commit 81870a6

Browse files
authored
Add unit test for OpenCounterContext (#72)
* Add unit test for OpenCounterContext The unit tests should have a check that GpaCounterLibOpenCounterContext() can be called with that various possibilities for GpaOpenContextBits. There were gaps and bugs with the GPUs I was adding but that didn't reveal itself until a client tried asking for the hw counters when creating a counter context. This could and should have been caught by the GPA unit test. Also, I obsoleted two GpaOpenContextBits enum values, as they are pointless with the latest GPA. kGpaOpenContextHideSoftwareCountersBit was made pointless when support for SW counters was removed in GPA 3.0. Similarly, it appears at one point GPA dished out the HW counters by default and excluded them only on demand. Now they are excluded by default, and shown only on demand. That made kGpaOpenContextHideHardwareCountersBit pointless. Both those enums have been renamed to have an _obsolete suffix. This aproach maintains backwards runtime compatibility, but building against the latest GPA will make clients cleanup (remove) any use of those now pointless flags. This is beneficial to them and allows us to improve the GPA interface and implementation. Change-Id: Ie8cfeb66b787a2705a80beca574b98eee279872c
1 parent dee5e3c commit 81870a6

File tree

13 files changed

+148
-13
lines changed

13 files changed

+148
-13
lines changed

ReleaseNotes.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# GPU Performance API Release Notes
2-
---
2+
3+
## Upcoming Release
4+
* Renamed kGpaOpenContextHideSoftwareCountesrBit and kGpaOpenContextHideHardwareCountersBit since they are obsolete.
35

46
## Version 3.12 (12/14/22)
57
* Add support for AMD Radeon™ RX 7900 XTX and AMD Radeon™ RX 7900 XT GPUs.

include/gpu_performance_api/gpu_perf_api_types.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ typedef enum
193193
0, ///< Open contexts using all default options (all counters exposed, clocks are set to stable frequencies which are known to be power and thermal sustainable. The ratio between the engine and memory clock frequencies will be kept the same as much as possible).
194194
kGpaOpenContextHideDerivedCountersBit = 0x01, ///< Prevent the derived counters from being exposed.
195195
kGpaOpenContextHidePublicCountersBit = kGpaOpenContextHideDerivedCountersBit, ///< For backwards compatibility.
196-
kGpaOpenContextHideSoftwareCountersBit = 0x02, ///< Prevent the software counters from being exposed.
197-
kGpaOpenContextHideHardwareCountersBit = 0x04, ///< Prevent the hardware counters from being exposed.
196+
kGpaOpenContextHideSoftwareCountersBit_obsolete = 0x02, ///< Prevent the software counters from being exposed. OBSOLETE: sw counters not supported as of GPA 3.0
197+
kGpaOpenContextHideHardwareCountersBit_obsolete = 0x04, ///< Prevent the hardware counters from being exposed. OBSOLETE: hw counters hidden by default. kGpaOpenContextEnableHardwareCountersBit enables them
198198
kGpaOpenContextClockModeNoneBit = 0x0008, ///< Clock frequencies are not altered and may vary widely during profiling based on GPU usage and other factors.
199199
kGpaOpenContextClockModePeakBit =
200200
0x0010, ///< Clocks are set to peak frequencies. In most cases this is safe to do for short periods of time while profiling. However, the GPU clock frequencies could still be reduced from peak level under power and thermal constraints.

source/gpu_perf_api_common/gpa_context.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,13 @@ bool GpaContext::ArePublicCountersExposed() const
216216

217217
bool GpaContext::AreHardwareCountersExposed() const
218218
{
219-
return (context_flags_ & kGpaOpenContextHideHardwareCountersBit) == 0;
219+
return (context_flags_ & kGpaOpenContextEnableHardwareCountersBit) == 0;
220220
}
221221

222222
bool GpaContext::AreSoftwareCountersExposed() const
223223
{
224-
return (context_flags_ & kGpaOpenContextHideSoftwareCountersBit) == 0;
224+
// GPA no longer support SW counters
225+
return false;
225226
}
226227

227228
GpaCounterSource GpaContext::GetCounterSource(GpaUInt32 internal_counter_index) const

source/gpu_perf_api_common/gpu_perf_api.cc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,6 @@ GPA_LIB_DECL GpaStatus GpaOpenContext(void* api_context, GpaOpenContextFlags gpa
328328
return kGpaStatusErrorNullPointer;
329329
}
330330

331-
// For GPA 3.0 - disable Software counters.
332-
gpa_open_context_flags |= kGpaOpenContextHideSoftwareCountersBit;
333-
334331
GpaStatus ret_status = gpa_imp->OpenContext(api_context, gpa_open_context_flags, gpa_context_id);
335332

336333
GPA_INTERNAL_LOG(GpaOpenContext,

source/gpu_perf_api_counter_generator/gpa_counter_generator.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ GpaStatus GenerateCounters(GpaApiType desired_api,
196196
}
197197

198198
bool allow_public = (flags & kGpaOpenContextHidePublicCountersBit) == 0;
199-
bool allow_software = (flags & kGpaOpenContextHideSoftwareCountersBit) == 0;
199+
bool allow_software = false; // SW counters no longer supported as of GPA 3.0
200200
bool allow_hardware_exposed = (flags & kGpaOpenContextEnableHardwareCountersBit) == kGpaOpenContextEnableHardwareCountersBit;
201201
bool enable_hardware = allow_hardware_exposed;
202202

source/gpu_perf_api_counters/gpu_perf_api_counters.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,14 @@ GPU_PERF_API_COUNTERS_DECL GpaStatus GpaCounterLibOpenCounterContext(GpaApiType
8282
return kGpaStatusErrorNullPointer;
8383
}
8484

85-
// Gpa no longer supports software counters
86-
const GpaOpenContextFlags context_flags_temp = context_flags | kGpaOpenContextHideSoftwareCountersBit;
85+
if ((context_flags & kGpaOpenContextHideDerivedCountersBit) && !(context_flags & kGpaOpenContextEnableHardwareCountersBit))
86+
{
87+
GPA_LOG_ERROR("Requested no counters. Specify a different GpaOpenContextFlags argument.");
88+
return kGpaStatusErrorInvalidParameter;
89+
}
8790

8891
return GpaCounterContextManager::Instance()->OpenCounterContext(
89-
api, gpa_counter_context_hardware_info, context_flags_temp, generate_asic_specific_counters, gpa_virtual_context);
92+
api, gpa_counter_context_hardware_info, context_flags, generate_asic_specific_counters, gpa_virtual_context);
9093
}
9194

9295
GPU_PERF_API_COUNTERS_DECL GpaStatus GpaCounterLibCloseCounterContext(const GpaCounterContext gpa_virtual_context)

source/gpu_perf_api_unit_tests/counter_generator_cl_tests.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,11 @@ TEST(CounterDllTests, OpenClCounterNames)
163163
// Test the openCL counter names on each generation
164164
TEST(CounterDllTests, OpenClCounterNamesByGeneration)
165165
{
166+
VerifyHardwareNotSupported(kGpaApiOpencl, kGpaHwGenerationNone, FALSE);
166167
VerifyHardwareNotSupported(kGpaApiOpencl, kGpaHwGenerationNvidia, FALSE);
167168
VerifyHardwareNotSupported(kGpaApiOpencl, kGpaHwGenerationIntel, FALSE);
169+
VerifyHardwareNotSupported(kGpaApiOpencl, kGpaHwGenerationGfx6, FALSE);
170+
VerifyHardwareNotSupported(kGpaApiOpencl, kGpaHwGenerationGfx7, FALSE);
168171

169172
std::vector<const char*> counterNames;
170173
GetExpectedCountersForGeneration(kGpaHwGenerationGfx8, counterNames);
@@ -179,6 +182,21 @@ TEST(CounterDllTests, OpenClCounterNamesByGeneration)
179182
VerifyCounterNames(kGpaApiOpencl, kGpaHwGenerationGfx11, FALSE, counterNames);
180183
}
181184

185+
TEST(CounterDllTests, ClOpenCounterContext)
186+
{
187+
VerifyHardwareNotSupported(kGpaApiOpencl, kGpaHwGenerationNone, FALSE);
188+
VerifyHardwareNotSupported(kGpaApiOpencl, kGpaHwGenerationNvidia, FALSE);
189+
VerifyHardwareNotSupported(kGpaApiOpencl, kGpaHwGenerationIntel, FALSE);
190+
VerifyHardwareNotSupported(kGpaApiOpencl, kGpaHwGenerationGfx6, FALSE);
191+
VerifyHardwareNotSupported(kGpaApiOpencl, kGpaHwGenerationGfx7, FALSE);
192+
193+
VerifyOpenCounterContext(kGpaApiOpencl, kGpaHwGenerationGfx8);
194+
VerifyOpenCounterContext(kGpaApiOpencl, kGpaHwGenerationGfx9);
195+
VerifyOpenCounterContext(kGpaApiOpencl, kGpaHwGenerationGfx10);
196+
VerifyOpenCounterContext(kGpaApiOpencl, kGpaHwGenerationGfx103);
197+
VerifyOpenCounterContext(kGpaApiOpencl, kGpaHwGenerationGfx11);
198+
}
199+
182200
TEST(CounterDllTests, ClCounterLibTestGfx8)
183201
{
184202
VerifyCounterLibInterface(kGpaApiOpencl, kDevIdVI, REVISION_ID_ANY, false);

source/gpu_perf_api_unit_tests/counter_generator_dx11_tests.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,21 @@ TEST(CounterDllTests, Dx11CounterNamesByGeneration)
179179
VerifyCounterNames(kGpaApiDirectx11, kGpaHwGenerationGfx11, FALSE, counter_names);
180180
}
181181

182+
TEST(CounterDllTests, Dx11OpenCounterContext)
183+
{
184+
VerifyHardwareNotSupported(kGpaApiDirectx11, kGpaHwGenerationNone, FALSE);
185+
VerifyHardwareNotSupported(kGpaApiDirectx11, kGpaHwGenerationNvidia, FALSE);
186+
VerifyHardwareNotSupported(kGpaApiDirectx11, kGpaHwGenerationIntel, FALSE);
187+
VerifyHardwareNotSupported(kGpaApiDirectx11, kGpaHwGenerationGfx6, FALSE);
188+
VerifyHardwareNotSupported(kGpaApiDirectx11, kGpaHwGenerationGfx7, FALSE);
189+
190+
VerifyOpenCounterContext(kGpaApiDirectx11, kGpaHwGenerationGfx8);
191+
VerifyOpenCounterContext(kGpaApiDirectx11, kGpaHwGenerationGfx9);
192+
VerifyOpenCounterContext(kGpaApiDirectx11, kGpaHwGenerationGfx10);
193+
VerifyOpenCounterContext(kGpaApiDirectx11, kGpaHwGenerationGfx103);
194+
VerifyOpenCounterContext(kGpaApiDirectx11, kGpaHwGenerationGfx11);
195+
}
196+
182197
TEST(CounterDllTests, Dx11CounterLibTestGfx8)
183198
{
184199
VerifyCounterLibInterface(kGpaApiDirectx11, kDevIdVI, REVISION_ID_ANY, false);

source/gpu_perf_api_unit_tests/counter_generator_dx12_tests.cc

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,13 @@ static std::vector<GpaCounterDesc> GetExpectedPublicCounters(GpaHwGeneration gen
132132
// Test the Dx12 derived counter blocks
133133
TEST(CounterDllTests, Dx12DerivedCounterBlocks)
134134
{
135+
VerifyHardwareNotSupported(kGpaApiDirectx11, kGpaHwGenerationNone, FALSE);
136+
VerifyHardwareNotSupported(kGpaApiDirectx11, kGpaHwGenerationNvidia, FALSE);
137+
VerifyHardwareNotSupported(kGpaApiDirectx11, kGpaHwGenerationIntel, FALSE);
138+
VerifyHardwareNotSupported(kGpaApiDirectx11, kGpaHwGenerationNone, FALSE);
139+
VerifyHardwareNotSupported(kGpaApiDirectx11, kGpaHwGenerationGfx6, FALSE);
140+
VerifyHardwareNotSupported(kGpaApiDirectx11, kGpaHwGenerationGfx7, FALSE);
141+
135142
VerifyDerivedCounterCount(kGpaApiDirectx12, kGpaHwGenerationGfx8, FALSE, GetExpectedPublicCounters(kGpaHwGenerationGfx8));
136143
VerifyDerivedCounterCount(kGpaApiDirectx12, kGpaHwGenerationGfx9, FALSE, GetExpectedPublicCounters(kGpaHwGenerationGfx9));
137144
VerifyDerivedCounterCount(kGpaApiDirectx12, kGpaHwGenerationGfx10, FALSE, GetExpectedPublicCounters(kGpaHwGenerationGfx10));
@@ -163,9 +170,9 @@ TEST(CounterDllTests, Dx12CounterNames)
163170
TEST(CounterDllTests, Dx12CounterNamesByGeneration)
164171
{
165172
VerifyHardwareNotSupported(kGpaApiDirectx12, kGpaHwGenerationNone, FALSE);
166-
VerifyHardwareNotSupported(kGpaApiDirectx12, kGpaHwGenerationGfx6, FALSE);
167173
VerifyHardwareNotSupported(kGpaApiDirectx12, kGpaHwGenerationNvidia, FALSE);
168174
VerifyHardwareNotSupported(kGpaApiDirectx12, kGpaHwGenerationIntel, FALSE);
175+
VerifyHardwareNotSupported(kGpaApiDirectx12, kGpaHwGenerationGfx6, FALSE);
169176
VerifyHardwareNotSupported(kGpaApiDirectx12, kGpaHwGenerationGfx7, FALSE);
170177

171178
std::vector<const char*> counter_names;
@@ -181,6 +188,21 @@ TEST(CounterDllTests, Dx12CounterNamesByGeneration)
181188
VerifyCounterNames(kGpaApiDirectx12, kGpaHwGenerationGfx11, FALSE, counter_names);
182189
}
183190

191+
TEST(CounterDllTests, Dx12OpenCounterContext)
192+
{
193+
VerifyHardwareNotSupported(kGpaApiDirectx12, kGpaHwGenerationNone, FALSE);
194+
VerifyHardwareNotSupported(kGpaApiDirectx12, kGpaHwGenerationNvidia, FALSE);
195+
VerifyHardwareNotSupported(kGpaApiDirectx12, kGpaHwGenerationIntel, FALSE);
196+
VerifyHardwareNotSupported(kGpaApiDirectx12, kGpaHwGenerationGfx6, FALSE);
197+
VerifyHardwareNotSupported(kGpaApiDirectx12, kGpaHwGenerationGfx7, FALSE);
198+
199+
VerifyOpenCounterContext(kGpaApiDirectx12, kGpaHwGenerationGfx8);
200+
VerifyOpenCounterContext(kGpaApiDirectx12, kGpaHwGenerationGfx9);
201+
VerifyOpenCounterContext(kGpaApiDirectx12, kGpaHwGenerationGfx10);
202+
VerifyOpenCounterContext(kGpaApiDirectx12, kGpaHwGenerationGfx103);
203+
VerifyOpenCounterContext(kGpaApiDirectx12, kGpaHwGenerationGfx11);
204+
}
205+
184206
TEST(CounterDllTests, Dx12CounterLibTestGfx8)
185207
{
186208
VerifyCounterLibInterface(kGpaApiDirectx12, kDevIdVI, REVISION_ID_ANY, false);

source/gpu_perf_api_unit_tests/counter_generator_gl_tests.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,20 @@ TEST(CounterDllTests, OpenGlCounterNamesByGeneration)
235235
VerifyCounterNames(kGpaApiOpengl, kGpaHwGenerationGfx11, FALSE, counter_names);
236236
}
237237

238+
TEST(CounterDllTests, OpenGlOpenCounterContext)
239+
{
240+
VerifyHardwareNotSupported(kGpaApiOpengl, kGpaHwGenerationNvidia, FALSE);
241+
VerifyHardwareNotSupported(kGpaApiOpengl, kGpaHwGenerationIntel, FALSE);
242+
VerifyHardwareNotSupported(kGpaApiOpengl, kGpaHwGenerationGfx6, FALSE);
243+
VerifyHardwareNotSupported(kGpaApiOpengl, kGpaHwGenerationGfx7, FALSE);
244+
245+
VerifyOpenCounterContext(kGpaApiOpengl, kGpaHwGenerationGfx8);
246+
VerifyOpenCounterContext(kGpaApiOpengl, kGpaHwGenerationGfx9);
247+
VerifyOpenCounterContext(kGpaApiOpengl, kGpaHwGenerationGfx10);
248+
VerifyOpenCounterContext(kGpaApiOpengl, kGpaHwGenerationGfx103);
249+
VerifyOpenCounterContext(kGpaApiOpengl, kGpaHwGenerationGfx11);
250+
}
251+
238252
#ifdef _WIN32
239253
TEST(CounterDllTests, GlCounterLibTestDeviceIdGfx8)
240254
{

source/gpu_perf_api_unit_tests/counter_generator_tests.cc

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,51 @@ void VerifyCounterNames(GpaApiType api, unsigned int device_id, GpaUInt8 generat
265265
UnloadLib(lib_handle);
266266
}
267267

268+
// Verifies that GpaCounterLibOpenCounterContext() succeeds with all values of
269+
// GpaOpenContextBits, as well as with or without generate_asic_specific_counters
270+
//
271+
void VerifyOpenCounterContext(GpaApiType api, GpaHwGeneration generation)
272+
{
273+
LibHandle lib_handle = nullptr;
274+
GpaCounterLibFuncTable gpa_counter_lib_func_table = {};
275+
276+
LOAD_AND_VERIFY_COUNTER_LIB(&lib_handle, &gpa_counter_lib_func_table);
277+
278+
GpaCounterContextHardwareInfo counter_context_hardware_info = {kAmdVendorId, generation_device_map[generation], REVISION_ID_ANY, nullptr, 0};
279+
280+
GpaOpenContextBits context_bits_values[] = {
281+
kGpaOpenContextDefaultBit,
282+
283+
// This alone will generate an error--requested no counters
284+
// kGpaOpenContextHideDerivedCountersBit,
285+
286+
kGpaOpenContextClockModeNoneBit,
287+
kGpaOpenContextClockModePeakBit,
288+
kGpaOpenContextClockModeMinMemoryBit,
289+
kGpaOpenContextClockModeMinEngineBit,
290+
kGpaOpenContextEnableHardwareCountersBit,
291+
292+
// Ask for only the HW counters (exclude derived counters)
293+
(GpaOpenContextBits)(kGpaOpenContextHideDerivedCountersBit | kGpaOpenContextEnableHardwareCountersBit),
294+
};
295+
296+
for (GpaOpenContextBits context_bits : context_bits_values)
297+
{
298+
for (GpaUInt8 generate_asic_specific_counters = 0; generate_asic_specific_counters < 2; generate_asic_specific_counters++)
299+
{
300+
GpaCounterContext gpa_counter_context = nullptr;
301+
gpa_status = gpa_counter_lib_func_table.GpaCounterLibOpenCounterContext(
302+
api, counter_context_hardware_info, context_bits, generate_asic_specific_counters, &gpa_counter_context);
303+
EXPECT_EQ(kGpaStatusOk, gpa_status);
304+
EXPECT_NE(gpa_counter_context, nullptr);
305+
306+
gpa_status = gpa_counter_lib_func_table.GpaCounterLibCloseCounterContext(gpa_counter_context);
307+
EXPECT_EQ(kGpaStatusOk, gpa_status);
308+
}
309+
}
310+
UnloadLib(lib_handle);
311+
}
312+
268313
void VerifyCounterNames(GpaApiType api, GpaHwGeneration generation, GpaUInt8 generate_asic_specific_counters, std::vector<const char*> expectedNames)
269314
{
270315
assert(generation_device_map.size() == GDT_HW_GENERATION_LAST);

source/gpu_perf_api_unit_tests/counter_generator_tests.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ void VerifyCounterNames(GpaApiType api, unsigned int device_id, GpaUInt8 generat
8484

8585
void VerifyCounterNames(GpaApiType api, GpaHwGeneration generation, GpaUInt8 generate_asic_specific_counters, std::vector<const char*> expected_names);
8686

87+
void VerifyOpenCounterContext(GpaApiType api, GpaHwGeneration generation);
88+
8789
void VerifyCounterLibInterface(GpaApiType api,
8890
unsigned int device_id,
8991
unsigned int revision_id,

source/gpu_perf_api_unit_tests/counter_generator_vk_tests.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,22 @@ TEST(CounterDllTests, VkCounterNamesByGeneration)
184184
VerifyCounterNames(kGpaApiVulkan, kGpaHwGenerationGfx11, FALSE, counter_names);
185185
}
186186

187+
TEST(CounterDllTests, VkOpenCounterContext)
188+
{
189+
VerifyHardwareNotSupported(kGpaApiVulkan, kGpaHwGenerationNone, FALSE);
190+
VerifyHardwareNotSupported(kGpaApiVulkan, kGpaHwGenerationGfx6, FALSE);
191+
VerifyHardwareNotSupported(kGpaApiVulkan, kGpaHwGenerationNvidia, FALSE);
192+
VerifyHardwareNotSupported(kGpaApiVulkan, kGpaHwGenerationIntel, FALSE);
193+
VerifyHardwareNotSupported(kGpaApiVulkan, kGpaHwGenerationGfx6, FALSE);
194+
VerifyHardwareNotSupported(kGpaApiVulkan, kGpaHwGenerationGfx7, FALSE);
195+
196+
VerifyOpenCounterContext(kGpaApiVulkan, kGpaHwGenerationGfx8);
197+
VerifyOpenCounterContext(kGpaApiVulkan, kGpaHwGenerationGfx9);
198+
VerifyOpenCounterContext(kGpaApiVulkan, kGpaHwGenerationGfx10);
199+
VerifyOpenCounterContext(kGpaApiVulkan, kGpaHwGenerationGfx103);
200+
VerifyOpenCounterContext(kGpaApiVulkan, kGpaHwGenerationGfx11);
201+
}
202+
187203
#ifdef _WIN32
188204
TEST(CounterDllTests, VkCounterLibTestGfx8)
189205
{

0 commit comments

Comments
 (0)