Skip to content

Commit 82c16f4

Browse files
Add SFINAE guards before accessing members not present in earlier CTK versions
1 parent d97ae49 commit 82c16f4

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

nvbench/cupti_profiler.cxx

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <stdexcept>
3030
#include <type_traits>
3131
#include <unordered_set>
32+
#include <utility>
3233

3334
namespace nvbench::detail
3435
{
@@ -60,6 +61,35 @@ void cupti_host_call(const CUptiResult status)
6061
cupti_call_impl(status, "CUPTI Host API call returned error: ");
6162
}
6263

64+
template <typename T>
65+
auto set_allow_device_level_counters(T &params, int)
66+
-> decltype(std::declval<T &>().bAllowDeviceLevelCounters, void())
67+
{
68+
params.bAllowDeviceLevelCounters = true;
69+
}
70+
71+
template <typename T>
72+
void set_allow_device_level_counters(T &, long)
73+
{}
74+
75+
template <typename T>
76+
auto is_context_scope(const T &params, int)
77+
-> decltype(std::declval<const T &>().metricCollectionScope, bool())
78+
{
79+
#if defined(CUPTI_METRIC_COLLECTION_SCOPE_CONTEXT)
80+
return params.metricCollectionScope == CUPTI_METRIC_COLLECTION_SCOPE_CONTEXT;
81+
#else
82+
(void)params;
83+
return true;
84+
#endif
85+
}
86+
87+
template <typename T>
88+
bool is_context_scope(const T &, long)
89+
{
90+
return true;
91+
}
92+
6393
} // namespace
6494

6595
struct cupti_profiler::host_impl
@@ -198,9 +228,9 @@ void cupti_profiler::initialize_availability_image()
198228
{
199229
CUpti_Profiler_GetCounterAvailability_Params params{};
200230

201-
params.structSize = CUpti_Profiler_GetCounterAvailability_Params_STRUCT_SIZE;
202-
params.ctx = m_device.get_context();
203-
params.bAllowDeviceLevelCounters = true;
231+
params.structSize = CUpti_Profiler_GetCounterAvailability_Params_STRUCT_SIZE;
232+
params.ctx = m_device.get_context();
233+
set_allow_device_level_counters(params, 0);
204234

205235
cupti_call(cuptiProfilerGetCounterAvailability(&params));
206236

@@ -330,7 +360,7 @@ void append_metric_names(CUpti_Profiler_Host_Object *host_object,
330360
continue;
331361
}
332362

333-
if (props_params.metricCollectionScope != CUPTI_METRIC_COLLECTION_SCOPE_CONTEXT)
363+
if (!is_context_scope(props_params, 0))
334364
{
335365
continue;
336366
}

0 commit comments

Comments
 (0)