1
1
# Autogenerated wrapper script for CUDA_Driver_jll for powerpc64le-linux-gnu
2
- export libcuda , libnvidia_ptxjitcompiler
2
+ export libcuda_compat , libnvidia_ptxjitcompiler
3
3
4
4
JLLWrappers. @generate_wrapper_header (" CUDA_Driver" )
5
- JLLWrappers. @declare_library_product (libcuda , " libcuda.so.1" )
5
+ JLLWrappers. @declare_library_product (libcuda_compat , " libcuda.so.1" )
6
6
JLLWrappers. @declare_library_product (libnvidia_ptxjitcompiler, " libnvidia-ptxjitcompiler.so.1" )
7
7
function __init__ ()
8
8
JLLWrappers. @generate_init_header ()
9
9
JLLWrappers. @init_library_product (
10
- libcuda ,
10
+ libcuda_compat ,
11
11
" lib/libcuda.so" ,
12
12
nothing ,
13
13
)
@@ -19,6 +19,133 @@ function __init__()
19
19
)
20
20
21
21
JLLWrappers. @generate_init_footer ()
22
- global version = v " 11.8.0"
22
+ global compat_version = v " 11.8.0"
23
+ # minimal API call wrappers we need
24
+ function driver_version (library_handle)
25
+ function_handle = Libdl. dlsym (library_handle, " cuDriverGetVersion" )
26
+ version_ref = Ref {Cint} ()
27
+ status = ccall (function_handle, Cint, (Ptr{Cint},), version_ref)
28
+ if status != 0
29
+ return nothing
30
+ end
31
+ major, ver = divrem (version_ref[], 1000 )
32
+ minor, patch = divrem (ver, 10 )
33
+ return VersionNumber (major, minor, patch)
34
+ end
35
+ function init_driver (library_handle)
36
+ function_handle = Libdl. dlsym (library_handle, " cuInit" )
37
+ status = ccall (function_handle, Cint, (UInt32,), 0 )
38
+ Libdl. dlclose (library_handle)
39
+ return status
40
+ end
41
+
42
+ # find the system driver
43
+ system_driver = if Sys. iswindows ()
44
+ Libdl. find_library (" nvcuda" )
45
+ else
46
+ Libdl. find_library ([" libcuda.so.1" , " libcuda.so" ])
47
+ end
48
+ if system_driver == " "
49
+ @debug " No system CUDA driver found"
50
+ return
51
+ end
52
+ global libcuda = system_driver
53
+
54
+ # check if the system driver is already loaded. in that case, we have to use it because
55
+ # the code that loaded it in the first place might have made assumptions based on it.
56
+ system_driver_loaded = Libdl. dlopen (system_driver, Libdl. RTLD_NOLOAD;
57
+ throw_error= false ) != = nothing
58
+ if system_driver_loaded
59
+ @debug " System CUDA driver already loaded, continuing using it"
60
+ return
61
+ end
62
+ driver_handle = Libdl. dlopen (system_driver; throw_error= true )
63
+
64
+ # query the system driver version
65
+ # XXX : apparently cuDriverGetVersion can be used before cuInit,
66
+ # despite the docs stating "any function [...] will return
67
+ # CUDA_ERROR_NOT_INITIALIZED"; is this a recent change?
68
+ system_version = driver_version (driver_handle)
69
+ if system_version === nothing
70
+ @debug " Failed to query system CUDA driver version"
71
+ # note that libcuda is already set here, so we'll continue using the system driver
72
+ # and CUDA.jl will likely report the reason cuDriverGetVersion didn't work.
73
+ return
74
+ end
75
+ @debug " System CUDA driver found at $system_driver , detected as version $system_version "
76
+
77
+ # check the user preference
78
+ if ! parse (Bool, get (ENV , " JULIA_CUDA_USE_COMPAT" , " true" ))
79
+ @debug " User disallows using forward-compatible driver."
80
+ return
81
+ end
82
+
83
+ # check the version
84
+ if system_version >= compat_version
85
+ @debug " System CUDA driver is recent enough; not using forward-compatible driver"
86
+ return
87
+ end
88
+
89
+ # check if we can unload the system driver.
90
+ # if we didn't, we can't consider a forward compatible library because that would
91
+ # risk having multiple copies of libcuda.so loaded (also see NVIDIA bug #3418723)
92
+ Libdl. dlclose (driver_handle)
93
+ system_driver_loaded = Libdl. dlopen (system_driver, Libdl. RTLD_NOLOAD;
94
+ throw_error= false ) != = nothing
95
+ if system_driver_loaded
96
+ @debug " Could not unload the system CUDA library;" *
97
+ " this prevents use of the forward-compatible driver"
98
+ return
99
+ end
100
+
101
+ # check if this process is hooked by CUDA's injection libraries, which prevents
102
+ # unloading libcuda after dlopening. this is problematic, because we might want to
103
+ # after loading a forwards-compatible libcuda and realizing we can't use it. without
104
+ # being able to unload the library, we'd run into issues (see NVIDIA bug #3418723)
105
+ hooked = haskey (ENV , " CUDA_INJECTION64_PATH" )
106
+ if hooked
107
+ @debug " Running under CUDA injection tools;" *
108
+ " this prevents use of the forward-compatible driver"
109
+ return
110
+ end
111
+
112
+ # check if we even have an artifact
113
+ if ! @isdefined (libcuda_compat)
114
+ @debug " No forward-compatible CUDA library available for your platform."
115
+ return
116
+ end
117
+ compat_driver = libcuda_compat
118
+ @debug " Forward-compatible CUDA driver found at $compat_driver ;" *
119
+ " reported as version $(compat_version) "
120
+
121
+ # finally, load the compatibility driver to see if it supports this platform
122
+ driver_handle = Libdl. dlopen (compat_driver; throw_error= true )
123
+ # TODO : do we need to dlopen the JIT compiler library for it to be discoverable?
124
+ # doesn't that clash with a system one if compat cuInit fails? or should
125
+ # we load it _after_ the compat driver initialization succeeds?
126
+ # compiler_handle = libnvidia_ptxjitcompiler
127
+ # Libdl.dlopen(compiler_handle)
128
+
129
+ init_status = init_driver (driver_handle)
130
+ if init_status != 0
131
+ @debug " Could not use forward compatibility package (error $init_status )"
132
+
133
+ # see comment above about unloading the system driver
134
+ Libdl. dlclose (driver_handle)
135
+ compat_driver_loaded = Libdl. dlopen (compat_driver, Libdl. RTLD_NOLOAD;
136
+ throw_error= false ) != = nothing
137
+ if compat_driver_loaded
138
+ error (" Could not unload the forward compatible CUDA driver library." *
139
+ " This is probably caused by running Julia under a tool that hooks CUDA API calls." *
140
+ " In that case, prevent Julia from loading multiple drivers" *
141
+ " by setting JULIA_CUDA_USE_COMPAT=false in your environment." )
142
+ end
143
+
144
+ return
145
+ end
146
+
147
+ @debug " Successfully loaded forwards-compatible CUDA driver"
148
+ global system_version = system_version
149
+ global libcuda = compat_driver
23
150
24
151
end # __init__()
0 commit comments