Skip to content

Commit

Permalink
CUDA_Driver_jll build 0.10.0+0
Browse files Browse the repository at this point in the history
  • Loading branch information
jlbuild committed Aug 7, 2024
1 parent 0e2a5a6 commit 2401ceb
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 259 deletions.
4 changes: 2 additions & 2 deletions Artifacts.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ os = "linux"

[[CUDA_Driver.download]]
sha256 = "fd12604de1839b403d770fbf930670abf7b38db47406de467125267b4d42f09f"
url = "https://github.com/JuliaBinaryWrappers/CUDA_Driver_jll.jl/releases/download/CUDA_Driver-v0.9.2+0/CUDA_Driver.v0.9.2.x86_64-linux-gnu.tar.gz"
url = "https://github.com/JuliaBinaryWrappers/CUDA_Driver_jll.jl/releases/download/CUDA_Driver-v0.10.0+0/CUDA_Driver.v0.10.0.x86_64-linux-gnu.tar.gz"
[[CUDA_Driver]]
arch = "aarch64"
git-tree-sha1 = "932750b5d643341ced7773df5c1b25fa90de7984"
Expand All @@ -15,4 +15,4 @@ os = "linux"

[[CUDA_Driver.download]]
sha256 = "0e7f04eec85ad902f200650e67c3645ec6c43236deb97634d3bd979bdc14c32b"
url = "https://github.com/JuliaBinaryWrappers/CUDA_Driver_jll.jl/releases/download/CUDA_Driver-v0.9.2+0/CUDA_Driver.v0.9.2.aarch64-linux-gnu.tar.gz"
url = "https://github.com/JuliaBinaryWrappers/CUDA_Driver_jll.jl/releases/download/CUDA_Driver-v0.10.0+0/CUDA_Driver.v0.10.0.aarch64-linux-gnu.tar.gz"
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "CUDA_Driver_jll"
uuid = "4ee394cb-3365-5eb0-8335-949819d2adfc"
version = "0.9.2+0"
version = "0.10.0+0"

[deps]
JLLWrappers = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# `CUDA_Driver_jll.jl` (v0.9.2+0)
# `CUDA_Driver_jll.jl` (v0.10.0+0)

[![deps](https://juliahub.com/docs/CUDA_Driver_jll/deps.svg)](https://juliahub.com/ui/Packages/General/CUDA_Driver_jll/)

This is an autogenerated package constructed using [`BinaryBuilder.jl`](https://github.com/JuliaPackaging/BinaryBuilder.jl).

The originating [`build_tarballs.jl`](https://github.com/JuliaPackaging/Yggdrasil/blob/aaebeab926b947eb3f8874887ba6ec1b3bb2d37c/C/CUDA/CUDA_Driver/build_tarballs.jl) script can be found on [`Yggdrasil`](https://github.com/JuliaPackaging/Yggdrasil/), the community build tree.
The originating [`build_tarballs.jl`](https://github.com/JuliaPackaging/Yggdrasil/blob/0661e4526f0c50d5cfde8ef60621e31645aa85a0/C/CUDA/CUDA_Driver/build_tarballs.jl) script can be found on [`Yggdrasil`](https://github.com/JuliaPackaging/Yggdrasil/), the community build tree.

## Bug Reports

Expand Down
171 changes: 44 additions & 127 deletions src/wrappers/aarch64-linux-gnu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,8 @@ function __init__()
)

JLLWrappers.@generate_init_footer()

global compat_version = v"12.6.0"
# global variables we will set
# global variables we will set
global libcuda = nothing
global libcuda_version = nothing
global libcuda_original_version = nothing
# compat_version is set in build_tarballs.jl

# manual use of preferences, as we can't depend on additional packages in JLLs.
CUDA_Driver_jll_uuid = Base.UUID("4ee394cb-3365-5eb0-8335-949819d2adfc")
Expand Down Expand Up @@ -68,153 +63,75 @@ function __init__()
missing
end

# minimal API call wrappers we need
function driver_version(library_handle)
function_handle = Libdl.dlsym(library_handle, "cuDriverGetVersion"; throw_error=false)
if function_handle === nothing
@debug "Driver library seems invalid (does not contain 'cuDriverGetVersion')"
return nothing
end
version_ref = Ref{Cint}()
status = ccall(function_handle, Cint, (Ptr{Cint},), version_ref)
if status != 0
@debug "Call to 'cuDriverGetVersion' failed with status $status"
return nothing
end
major, ver = divrem(version_ref[], 1000)
minor, patch = divrem(ver, 10)
return VersionNumber(major, minor, patch)
end
function init_driver(library_handle)
function_handle = Libdl.dlsym(library_handle, "cuInit")
status = ccall(function_handle, Cint, (UInt32,), 0)
# libcuda.cuInit dlopens NULL, aka. the main program, which increments the refcount
# of libcuda. this breaks future dlclose calls, so eagerly lower the refcount already.
Libdl.dlclose(library_handle)
return status
end

# find the system driver
system_driver = if Sys.iswindows()
# find and select the system driver
libcuda_system = if Sys.iswindows()
Libdl.find_library("nvcuda")
else
Libdl.find_library(["libcuda.so.1", "libcuda.so"])
end
if system_driver == ""
@debug "No system CUDA driver found"
return
end
libcuda = system_driver

# check if the system driver is already loaded. in that case, we have to use it because
# the code that loaded it in the first place might have made assumptions based on it.
system_driver_loaded = Libdl.dlopen(system_driver, Libdl.RTLD_NOLOAD;
throw_error=false) !== nothing
driver_handle = Libdl.dlopen(system_driver; throw_error=false)
if driver_handle === nothing
@debug "Failed to load system CUDA driver"
return
end

# query the system driver version
# XXX: apparently cuDriverGetVersion can be used before cuInit,
# despite the docs stating "any function [...] will return
# CUDA_ERROR_NOT_INITIALIZED"; is this a recent change?
system_version = driver_version(driver_handle)
if system_version === nothing
@debug "Failed to query system CUDA driver version"
# note that libcuda is already set here, so we'll continue using the system driver
# and CUDA.jl will likely report the reason cuDriverGetVersion didn't work.
if libcuda_system == ""
@debug "No system driver found"
return
end
@debug "System CUDA driver found at $system_driver, detected as version $system_version"
libcuda = system_driver
libcuda_version = system_version
@debug "System driver found at $libcuda_system"
libcuda = libcuda_system

# check if the system driver is already loaded (see above)
if system_driver_loaded
@debug "System CUDA driver already loaded, continuing using it"
# check if we even have an artifact
if !@isdefined(libcuda_compat)
@debug "No forward-compatible driver available for your platform."
return
end
@debug "Forward-compatible driver found at $libcuda_compat"

# check the user preference
if compat_preference !== missing
@debug "CUDA compat preference: $(compat_preference)"
if !compat_preference
@debug "User disallows using forward-compatible driver."
return
end
end

# check the version
if system_version >= compat_version
@debug "System CUDA driver is recent enough; not using forward-compatible driver"
# check if the system driver is already loaded. in that case, we have to use it because
# the code that loaded it in the first place might have made assumptions based on it.
if Libdl.dlopen(libcuda_system, Libdl.RTLD_NOLOAD; throw_error=false) !== nothing
@debug "System CUDA driver already loaded, continuing using it."
return
end

# check if we can unload the system driver.
# if we didn't, we can't consider a forward compatible library because that would
# risk having multiple copies of libcuda.so loaded (also see NVIDIA bug #3418723)
Libdl.dlclose(driver_handle)
system_driver_loaded = Libdl.dlopen(system_driver, Libdl.RTLD_NOLOAD;
throw_error=false) !== nothing
if system_driver_loaded
@debug "Could not unload the system CUDA library;" *
" this prevents use of the forward-compatible driver"
return
end
# try to load the forward-compatible driver in a separate process
function try_driver(driver, deps)
script = raw"""
using Libdl
driver, deps... = ARGS
# check if this process is hooked by CUDA's injection libraries, which prevents
# unloading libcuda after dlopening. this is problematic, because we might want to
# after loading a forwards-compatible libcuda and realizing we can't use it. without
# being able to unload the library, we'd run into issues (see NVIDIA bug #3418723)
hooked = haskey(ENV, "CUDA_INJECTION64_PATH")
if hooked
@debug "Running under CUDA injection tools;" *
" this prevents use of the forward-compatible driver"
return
end
for dep in deps
Libdl.dlopen(dep; throw_error=false) === nothing && exit(-1)
end
# check if we even have an artifact
if !@isdefined(libcuda_compat)
@debug "No forward-compatible CUDA library available for your platform."
return
end
compat_driver = libcuda_compat
@debug "Forward-compatible CUDA driver found at $compat_driver;" *
" known to be version $(compat_version)"

# finally, load the compatibility driver to see if it supports this platform
driver_handle = Libdl.dlopen(compat_driver; throw_error=true)

init_status = init_driver(driver_handle)
if init_status != 0
@debug "Could not use forward compatibility package (error $init_status)"

# see comment above about unloading the system driver
Libdl.dlclose(driver_handle)
compat_driver_loaded = Libdl.dlopen(compat_driver, Libdl.RTLD_NOLOAD;
throw_error=false) !== nothing
if compat_driver_loaded
error("Could not unload forwards compatible CUDA driver." *
"This is probably caused by running Julia under a tool that hooks CUDA API calls." *
"In that case, prevent Julia from loading multiple drivers" *
" by setting JULIA_CUDA_USE_COMPAT=false in your environment.")
end
library_handle = Libdl.dlopen(driver; throw_error=false)
library_handle === nothing && exit(-1)
function_handle = Libdl.dlsym(library_handle, "cuInit")
status = ccall(function_handle, Cint, (UInt32,), 0)
status == 0 || exit(-2)
exit(0)
"""
success(`$(Base.julia_cmd()) --compile=min -t1 --startup-file=no -e $script $driver $deps`)
end
libcuda_deps = [libcuda_debugger, libnvidia_nvvm, libnvidia_ptxjitcompiler]
if !try_driver(libcuda_compat, libcuda_deps)
@debug "Failed to load forwards-compatible driver."
return
end

# load dependent libraries
# XXX: we can do this after loading libcuda, because these are runtime dependencies.
# if loading libcuda or calling cuInit would already require these, do so earlier.
Libdl.dlopen(libcuda_debugger; throw_error=true)
Libdl.dlopen(libnvidia_nvvm; throw_error=true)
Libdl.dlopen(libnvidia_ptxjitcompiler; throw_error=true)

@debug "Successfully loaded forwards-compatible CUDA driver"
libcuda = compat_driver
libcuda_version = compat_version
libcuda_original_version = system_version
@debug "Successfully loaded forwards-compatible CUDA driver."
libcuda = libcuda_compat

# load driver dependencies
for dep in libcuda_deps
Libdl.dlopen(dep; throw_error=true)
end
# XXX: should we also load the driver here?

end # __init__()
Loading

0 comments on commit 2401ceb

Please sign in to comment.