@@ -23,29 +23,38 @@ namespace sycl {
23
23
inline namespace _V1 {
24
24
namespace detail {
25
25
26
+ std::function<void (void *)> jit_compiler::CustomDeleterForLibHandle =
27
+ [](void *StoredPtr) {
28
+ if (!StoredPtr)
29
+ return ;
30
+ std::ignore = sycl::detail::ur::unloadOsLibrary (StoredPtr);
31
+ };
32
+
26
33
static inline void printPerformanceWarning (const std::string &Message) {
27
34
if (detail::SYCLConfig<detail::SYCL_RT_WARNING_LEVEL>::get () > 0 ) {
28
35
std::cerr << " WARNING: " << Message << " \n " ;
29
36
}
30
37
}
31
38
32
- jit_compiler::jit_compiler () {
39
+ jit_compiler::jit_compiler ()
40
+ : LibraryHandle(nullptr , CustomDeleterForLibHandle) {
33
41
auto checkJITLibrary = [this ]() -> bool {
34
42
#ifdef _WIN32
35
43
static const std::string dir = sycl::detail::OSUtil::getCurrentDSODir ();
36
44
static const std::string JITLibraryName = dir + " \\ " + " sycl-jit.dll" ;
37
45
#else
38
46
static const std::string JITLibraryName = " libsycl-jit.so" ;
39
47
#endif
40
-
41
- void *LibraryPtr = sycl::detail::ur::loadOsLibrary (JITLibraryName);
48
+ std::unique_ptr<void , decltype (CustomDeleterForLibHandle)> LibraryPtr (
49
+ sycl::detail::ur::loadOsLibrary (JITLibraryName),
50
+ CustomDeleterForLibHandle);
42
51
if (LibraryPtr == nullptr ) {
43
52
printPerformanceWarning (" Could not find JIT library " + JITLibraryName);
44
53
return false ;
45
54
}
46
55
47
56
this ->AddToConfigHandle = reinterpret_cast <AddToConfigFuncT>(
48
- sycl::detail::ur::getOsLibraryFuncAddress (LibraryPtr,
57
+ sycl::detail::ur::getOsLibraryFuncAddress (LibraryPtr. get () ,
49
58
" addToJITConfiguration" ));
50
59
if (!this ->AddToConfigHandle ) {
51
60
printPerformanceWarning (
@@ -54,7 +63,7 @@ jit_compiler::jit_compiler() {
54
63
}
55
64
56
65
this ->ResetConfigHandle = reinterpret_cast <ResetConfigFuncT>(
57
- sycl::detail::ur::getOsLibraryFuncAddress (LibraryPtr,
66
+ sycl::detail::ur::getOsLibraryFuncAddress (LibraryPtr. get () ,
58
67
" resetJITConfiguration" ));
59
68
if (!this ->ResetConfigHandle ) {
60
69
printPerformanceWarning (
@@ -63,7 +72,8 @@ jit_compiler::jit_compiler() {
63
72
}
64
73
65
74
this ->FuseKernelsHandle = reinterpret_cast <FuseKernelsFuncT>(
66
- sycl::detail::ur::getOsLibraryFuncAddress (LibraryPtr, " fuseKernels" ));
75
+ sycl::detail::ur::getOsLibraryFuncAddress (LibraryPtr.get (),
76
+ " fuseKernels" ));
67
77
if (!this ->FuseKernelsHandle ) {
68
78
printPerformanceWarning (
69
79
" Cannot resolve JIT library function entry point" );
@@ -73,21 +83,22 @@ jit_compiler::jit_compiler() {
73
83
this ->MaterializeSpecConstHandle =
74
84
reinterpret_cast <MaterializeSpecConstFuncT>(
75
85
sycl::detail::ur::getOsLibraryFuncAddress (
76
- LibraryPtr, " materializeSpecConstants" ));
86
+ LibraryPtr. get () , " materializeSpecConstants" ));
77
87
if (!this ->MaterializeSpecConstHandle ) {
78
88
printPerformanceWarning (
79
89
" Cannot resolve JIT library function entry point" );
80
90
return false ;
81
91
}
82
92
83
93
this ->CompileSYCLHandle = reinterpret_cast <CompileSYCLFuncT>(
84
- sycl::detail::ur::getOsLibraryFuncAddress (LibraryPtr, " compileSYCL" ));
94
+ sycl::detail::ur::getOsLibraryFuncAddress (LibraryPtr.get (),
95
+ " compileSYCL" ));
85
96
if (!this ->CompileSYCLHandle ) {
86
97
printPerformanceWarning (
87
98
" Cannot resolve JIT library function entry point" );
88
99
return false ;
89
100
}
90
-
101
+ LibraryHandle = std::move (LibraryPtr);
91
102
return true ;
92
103
};
93
104
Available = checkJITLibrary ();
0 commit comments