Skip to content

Commit 0108be9

Browse files
authored
Merge pull request #483 from djwoun/rocm7
rocp_sdk: add multi-alias dlsym + *_cb typedefs for ROCm 7.0.0
2 parents 6bdc7ea + 589c09d commit 0108be9

File tree

2 files changed

+70
-16
lines changed

2 files changed

+70
-16
lines changed

src/components/rocp_sdk/sdk_class.cpp

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,31 @@ static std::unordered_map<std::string, unsigned int> event_instance_name_to_papi
7474
/* *** */
7575
typedef rocprofiler_status_t (* rocprofiler_flush_buffer_t) (rocprofiler_buffer_id_t buffer_id);
7676

77-
typedef rocprofiler_status_t (* rocprofiler_sample_device_counting_service_t) (rocprofiler_context_id_t context_id, rocprofiler_user_data_t user_data, rocprofiler_counter_flag_t flags, rocprofiler_record_counter_t* output_records, size_t* rec_count);
78-
79-
typedef rocprofiler_status_t (* rocprofiler_configure_callback_dispatch_counting_service_t) (rocprofiler_context_id_t context_id, rocprofiler_dispatch_counting_service_callback_t dispatch_callback, void *dispatch_callback_args, rocprofiler_profile_counting_record_callback_t record_callback, void *record_callback_args);
80-
81-
typedef rocprofiler_status_t (* rocprofiler_configure_device_counting_service_t) (rocprofiler_context_id_t context_id, rocprofiler_buffer_id_t buffer_id, rocprofiler_agent_id_t agent_id, rocprofiler_device_counting_service_callback_t cb, void *user_data);
82-
77+
#if defined(ROCPROFILER_VERSION_MAJOR) && ROCPROFILER_VERSION_MAJOR >= 1
78+
// ROCm 7.0+ (ROCprofiler SDK 1.x) - use new types
79+
typedef rocprofiler_status_t (*rocprofiler_sample_device_counting_service_t)(
80+
rocprofiler_context_id_t, rocprofiler_user_data_t, rocprofiler_counter_flag_t,
81+
rocprofiler_counter_record_t *output_records, size_t *rec_count);
82+
typedef rocprofiler_status_t (*rocprofiler_configure_callback_dispatch_counting_service_t)(
83+
rocprofiler_context_id_t,
84+
rocprofiler_dispatch_counting_service_cb_t dispatch_callback, void *dispatch_callback_args,
85+
rocprofiler_dispatch_counting_record_cb_t record_callback, void *record_callback_args);
86+
typedef rocprofiler_status_t (*rocprofiler_configure_device_counting_service_t)(
87+
rocprofiler_context_id_t, rocprofiler_buffer_id_t, rocprofiler_agent_id_t,
88+
rocprofiler_device_counting_service_cb_t cb, void *user_data);
89+
#else
90+
// Pre-7.0 ROCm - use old types
91+
typedef rocprofiler_status_t (*rocprofiler_sample_device_counting_service_t)(
92+
rocprofiler_context_id_t, rocprofiler_user_data_t, rocprofiler_counter_flag_t,
93+
rocprofiler_record_counter_t *output_records, size_t *rec_count);
94+
typedef rocprofiler_status_t (*rocprofiler_configure_callback_dispatch_counting_service_t)(
95+
rocprofiler_context_id_t,
96+
rocprofiler_dispatch_counting_service_callback_t dispatch_callback, void *dispatch_callback_args,
97+
rocprofiler_profile_counting_record_callback_t record_callback, void *record_callback_args);
98+
typedef rocprofiler_status_t (*rocprofiler_configure_device_counting_service_t)(
99+
rocprofiler_context_id_t, rocprofiler_buffer_id_t, rocprofiler_agent_id_t,
100+
rocprofiler_device_counting_service_callback_t cb, void *user_data);
101+
#endif
83102

84103

85104
typedef rocprofiler_status_t (* rocprofiler_create_buffer_t) (rocprofiler_context_id_t context, unsigned long size, unsigned long watermark, rocprofiler_buffer_policy_t policy, rocprofiler_buffer_tracing_cb_t callback, void *callback_data, rocprofiler_buffer_id_t *buffer_id);
@@ -133,6 +152,7 @@ rocprofiler_stop_context_t rocprofiler_stop_context_FPTR;
133152
rocprofiler_context_is_active_t rocprofiler_context_is_active_FPTR;
134153
rocprofiler_context_is_valid_t rocprofiler_context_is_valid_FPTR;
135154
rocprofiler_create_profile_config_t rocprofiler_create_profile_config_FPTR;
155+
rocprofiler_destroy_profile_config_t rocprofiler_destroy_profile_config_FPTR;
136156
rocprofiler_force_configure_t rocprofiler_force_configure_FPTR;
137157
rocprofiler_get_status_string_t rocprofiler_get_status_string_FPTR;
138158
rocprofiler_get_thread_id_t rocprofiler_get_thread_id_FPTR;
@@ -251,7 +271,13 @@ obtain_function_pointers()
251271
DLL_SYM_CHECK(rocprofiler_stop_context, rocprofiler_stop_context_t);
252272
DLL_SYM_CHECK(rocprofiler_context_is_valid, rocprofiler_context_is_valid_t);
253273
DLL_SYM_CHECK(rocprofiler_context_is_active, rocprofiler_context_is_active_t);
254-
DLL_SYM_CHECK(rocprofiler_create_profile_config, rocprofiler_create_profile_config_t);
274+
DLL_SYM_CHECK(rocprofiler_create_profile_config,
275+
"rocprofiler_create_counter_config",
276+
rocprofiler_create_profile_config_t);
277+
278+
DLL_SYM_CHECK(rocprofiler_destroy_profile_config,
279+
"rocprofiler_destroy_counter_config",
280+
rocprofiler_destroy_profile_config_t);
255281
DLL_SYM_CHECK(rocprofiler_force_configure, rocprofiler_force_configure_t);
256282
DLL_SYM_CHECK(rocprofiler_get_status_string, rocprofiler_get_status_string_t);
257283
DLL_SYM_CHECK(rocprofiler_get_thread_id, rocprofiler_get_thread_id_t);

src/components/rocp_sdk/sdk_class.hpp

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,43 @@ extern "C"
5151
#include <thread>
5252
#include <vector>
5353

54-
#define DLL_SYM_CHECK(name, type) \
55-
do { \
56-
char *err; \
57-
name##_FPTR = (type) dlsym(dllHandle, #name);\
58-
err = dlerror(); \
59-
if(NULL != err) { \
60-
return err; \
61-
} \
62-
} while (0)
54+
// required, single name
55+
#define DLL_SYM_CHECK_2(name, type) \
56+
do { \
57+
char* __err; \
58+
/* clear any prior dlerror */ \
59+
dlerror(); \
60+
name##_FPTR = (type) dlsym(dllHandle, #name); \
61+
__err = dlerror(); \
62+
if(__err != NULL) { \
63+
return __err; \
64+
} \
65+
} while(0)
66+
67+
// required, either of two names (try alt first, then primary)
68+
#define DLL_SYM_CHECK_3(name, alt, type) \
69+
do { \
70+
char* __err; \
71+
void* __p; \
72+
dlerror(); \
73+
__p = dlsym(dllHandle, alt); \
74+
__err = dlerror(); \
75+
if(__err == NULL && __p) { \
76+
name##_FPTR = (type) __p; \
77+
} else { \
78+
dlerror(); \
79+
name##_FPTR = (type) dlsym(dllHandle, #name); \
80+
__err = dlerror(); \
81+
if(__err != NULL) { \
82+
return __err; \
83+
} \
84+
} \
85+
} while(0)
86+
87+
// arity dispatcher: DLL_SYM_CHECK(name, type) or DLL_SYM_CHECK(name, "alt", type)
88+
#define __DLL_SYM_GET_MACRO(_1,_2,_3,NAME,...) NAME
89+
#define DLL_SYM_CHECK(...) __DLL_SYM_GET_MACRO(__VA_ARGS__, DLL_SYM_CHECK_3, DLL_SYM_CHECK_2)(__VA_ARGS__)
90+
6391

6492
#if defined(PAPI_ROCPSDK_DEBUG)
6593
#define ROCPROFILER_CALL(result, msg) \

0 commit comments

Comments
 (0)