16
16
#include < cuda.h>
17
17
#ifdef XPTI_ENABLE_INSTRUMENTATION
18
18
#include < cupti.h>
19
- #include < dlfcn.h>
20
19
#endif // XPTI_ENABLE_INSTRUMENTATION
21
20
22
21
#include " tracing.hpp"
22
+ #include " ur_lib_loader.hpp"
23
23
#include < exception>
24
24
#include < iostream>
25
25
@@ -42,8 +42,9 @@ using cuptiEnableCallback_fn = CUPTIAPI
42
42
CUptiResult (*)(uint32_t enable, CUpti_SubscriberHandle subscriber,
43
43
CUpti_CallbackDomain domain, CUpti_CallbackId cbid);
44
44
45
- #define LOAD_CUPTI_SYM (p, x ) \
46
- p->x = (cupti##x##_fn)dlsym(p->Library, " cupti" #x);
45
+ #define LOAD_CUPTI_SYM (p, lib, x ) \
46
+ p->x = (cupti##x##_fn)ur_loader::LibLoader::getFunctionPtr(lib.get(), \
47
+ " cupti" #x);
47
48
48
49
#else
49
50
using tracing_event_t = void *;
@@ -58,7 +59,7 @@ struct cuda_tracing_context_t_ {
58
59
tracing_event_t CallEvent = nullptr ;
59
60
tracing_event_t DebugEvent = nullptr ;
60
61
subscriber_handle_t Subscriber = nullptr ;
61
- void * Library = nullptr ;
62
+ ur_loader::LibLoader::Lib Library;
62
63
cuptiSubscribe_fn Subscribe = nullptr ;
63
64
cuptiUnsubscribe_fn Unsubscribe = nullptr ;
64
65
cuptiEnableDomain_fn EnableDomain = nullptr ;
@@ -137,18 +138,19 @@ bool loadCUDATracingLibrary(cuda_tracing_context_t_ *Ctx) {
137
138
return false ;
138
139
if (Ctx->Library )
139
140
return true ;
140
- Ctx-> Library = dlopen (CUPTI_LIB_PATH, RTLD_NOW) ;
141
- if (!Ctx-> Library )
141
+ auto Lib{ ur_loader::LibLoader::loadAdapterLibrary (CUPTI_LIB_PATH)} ;
142
+ if (!Lib )
142
143
return false ;
143
- LOAD_CUPTI_SYM (Ctx, Subscribe)
144
- LOAD_CUPTI_SYM (Ctx, Unsubscribe)
145
- LOAD_CUPTI_SYM (Ctx, EnableDomain)
146
- LOAD_CUPTI_SYM (Ctx, EnableCallback)
144
+ LOAD_CUPTI_SYM (Ctx, Lib, Subscribe)
145
+ LOAD_CUPTI_SYM (Ctx, Lib, Unsubscribe)
146
+ LOAD_CUPTI_SYM (Ctx, Lib, EnableDomain)
147
+ LOAD_CUPTI_SYM (Ctx, Lib, EnableCallback)
147
148
if (!Ctx->Subscribe || !Ctx->Unsubscribe || !Ctx->EnableDomain ||
148
149
!Ctx->EnableCallback ) {
149
150
unloadCUDATracingLibrary (Ctx);
150
151
return false ;
151
152
}
153
+ Ctx->Library = std::move (Lib);
152
154
return true ;
153
155
#else
154
156
(void )Ctx;
@@ -164,8 +166,8 @@ void unloadCUDATracingLibrary(cuda_tracing_context_t_ *Ctx) {
164
166
Ctx->Unsubscribe = nullptr ;
165
167
Ctx->EnableDomain = nullptr ;
166
168
Ctx->EnableCallback = nullptr ;
167
- dlclose (Ctx-> Library );
168
- Ctx->Library = nullptr ;
169
+
170
+ Ctx->Library . reset () ;
169
171
#else
170
172
(void )Ctx;
171
173
#endif // XPTI_ENABLE_INSTRUMENTATION
0 commit comments