From 2401cebc87ff22212c3f58fd7f6633c3db9c57b7 Mon Sep 17 00:00:00 2001 From: jlbuild Date: Wed, 7 Aug 2024 10:18:45 +0000 Subject: [PATCH] CUDA_Driver_jll build 0.10.0+0 --- Artifacts.toml | 4 +- Project.toml | 2 +- README.md | 4 +- src/wrappers/aarch64-linux-gnu.jl | 171 ++++++++---------------------- src/wrappers/x86_64-linux-gnu.jl | 171 ++++++++---------------------- 5 files changed, 93 insertions(+), 259 deletions(-) diff --git a/Artifacts.toml b/Artifacts.toml index 0d6bea9..c643e99 100644 --- a/Artifacts.toml +++ b/Artifacts.toml @@ -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" @@ -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" diff --git a/Project.toml b/Project.toml index 0192762..6124ea0 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/README.md b/README.md index 175088b..ce27af3 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/wrappers/aarch64-linux-gnu.jl b/src/wrappers/aarch64-linux-gnu.jl index 298f98b..0c48eb0 100644 --- a/src/wrappers/aarch64-linux-gnu.jl +++ b/src/wrappers/aarch64-linux-gnu.jl @@ -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") @@ -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__() diff --git a/src/wrappers/x86_64-linux-gnu.jl b/src/wrappers/x86_64-linux-gnu.jl index 32d5196..9fffc18 100644 --- a/src/wrappers/x86_64-linux-gnu.jl +++ b/src/wrappers/x86_64-linux-gnu.jl @@ -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") @@ -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__()