diff --git a/NEWS.md b/NEWS.md index 32c89cfe09861..1ce80e71dd90c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -42,6 +42,12 @@ Standard library changes #### LinearAlgebra +* We are now wholly reliant on libblastrampoline (LBT) for calling + BLAS and LAPACK. OpenBLAS is shipped by default, but building the + system image with other BLAS/LAPACK libraries is not + supported. Instead, it is recommended that the LBT mechanism be used + for swapping BLAS/LAPACK with vendor provided ones. ([#44360]) + #### Markdown #### Printf diff --git a/base/Makefile b/base/Makefile index f3ed73791085e..61f9647ebf24a 100644 --- a/base/Makefile +++ b/base/Makefile @@ -47,8 +47,6 @@ else @echo "const MACHINE = \"$(XC_HOST)\"" >> $@ endif @echo "const libm_name = \"$(LIBMNAME)\"" >> $@ - @echo "const libblas_name = \"$(LIBBLASNAME)\"" >> $@ - @echo "const liblapack_name = \"$(LIBLAPACKNAME)\"" >> $@ ifeq ($(USE_BLAS64), 1) @echo "const USE_BLAS64 = true" >> $@ else diff --git a/stdlib/LinearAlgebra/Project.toml b/stdlib/LinearAlgebra/Project.toml index d7121d2e3868e..46653aa795209 100644 --- a/stdlib/LinearAlgebra/Project.toml +++ b/stdlib/LinearAlgebra/Project.toml @@ -4,6 +4,7 @@ uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" [deps] Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb" libblastrampoline_jll = "8e850b90-86db-534c-a0d3-1478176c7d93" +OpenBLAS_jll = "4536629a-c528-5b80-bd46-f80d51c5b363" [extras] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/stdlib/LinearAlgebra/src/LinearAlgebra.jl b/stdlib/LinearAlgebra/src/LinearAlgebra.jl index 44deb7556e037..06561c188a5df 100644 --- a/stdlib/LinearAlgebra/src/LinearAlgebra.jl +++ b/stdlib/LinearAlgebra/src/LinearAlgebra.jl @@ -19,6 +19,8 @@ using Base: IndexLinear, promote_eltype, promote_op, promote_typeof, @propagate_inbounds, @pure, reduce, typed_hvcat, typed_vcat, require_one_based_indexing, splat using Base.Broadcast: Broadcasted, broadcasted +using OpenBLAS_jll +using libblastrampoline_jll import Libdl export @@ -563,42 +565,9 @@ function versioninfo(io::IO=stdout) return nothing end -function find_library_path(name) - shlib_ext = string(".", Libdl.dlext) - if !endswith(name, shlib_ext) - name_ext = string(name, shlib_ext) - end - - # On windows, we look in `bin` and never in `lib` - @static if Sys.iswindows() - path = joinpath(Sys.BINDIR, name_ext) - isfile(path) && return path - else - # On other platforms, we check `lib/julia` first, and if that doesn't exist, `lib`. - path = joinpath(Sys.BINDIR, Base.LIBDIR, "julia", name_ext) - isfile(path) && return path - - path = joinpath(Sys.BINDIR, Base.LIBDIR, name_ext) - isfile(path) && return path - end - - # If we can't find it by absolute path, we'll try just passing this straight through to `dlopen()` - return name -end - function __init__() try - libblas_path = find_library_path(Base.libblas_name) - liblapack_path = find_library_path(Base.liblapack_name) - # We manually `dlopen()` these libraries here, so that we search with `libjulia-internal`'s - # `RPATH` and not `libblastrampoline's`. Once it's been opened, when LBT tries to open it, - # it will find the library already loaded. - libblas_path = Libdl.dlpath(Libdl.dlopen(libblas_path)) - BLAS.lbt_forward(libblas_path; clear=true) - if liblapack_path != libblas_path - liblapack_path = Libdl.dlpath(Libdl.dlopen(liblapack_path)) - BLAS.lbt_forward(liblapack_path) - end + BLAS.lbt_forward(OpenBLAS_jll.libopenblas_path; clear=true) BLAS.check() catch ex Base.showerror_nostdio(ex, "WARNING: Error during initialization of module LinearAlgebra") diff --git a/stdlib/LinearAlgebra/src/blas.jl b/stdlib/LinearAlgebra/src/blas.jl index 22789f0a01866..1a2464d482050 100644 --- a/stdlib/LinearAlgebra/src/blas.jl +++ b/stdlib/LinearAlgebra/src/blas.jl @@ -63,19 +63,7 @@ export trsm!, trsm -# Eventually this will be replaced with `libblastrampoline_jll.libblastrampoline` -const libblastrampoline = "libblastrampoline" -libblastrampoline_handle = C_NULL - -# Legacy bindings that some packages (such as NNlib.jl) use. -# We maintain these for backwards-compatibility but new packages -# should not look at these, instead preferring to parse the output -# of BLAS.get_config() -const libblas = libblastrampoline -const liblapack = libblastrampoline - -import LinearAlgebra -using LinearAlgebra: BlasReal, BlasComplex, BlasFloat, BlasInt, DimensionMismatch, checksquare, stride1, chkstride1 +using ..LinearAlgebra: libblastrampoline, BlasReal, BlasComplex, BlasFloat, BlasInt, DimensionMismatch, checksquare, stride1, chkstride1 include("lbt.jl") diff --git a/stdlib/LinearAlgebra/src/lapack.jl b/stdlib/LinearAlgebra/src/lapack.jl index 0aa8f1689f23c..cd438f142a793 100644 --- a/stdlib/LinearAlgebra/src/lapack.jl +++ b/stdlib/LinearAlgebra/src/lapack.jl @@ -5,16 +5,9 @@ module LAPACK Interfaces to LAPACK subroutines. """ LAPACK -const libblastrampoline = "libblastrampoline" - -# Legacy binding maintained for backwards-compatibility but new packages -# should not look at this, instead preferring to parse the output -# of BLAS.get_config() -const liblapack = libblastrampoline - using ..LinearAlgebra.BLAS: @blasfunc, chkuplo -using ..LinearAlgebra: BlasFloat, BlasInt, LAPACKException, DimensionMismatch, +using ..LinearAlgebra: libblastrampoline, BlasFloat, BlasInt, LAPACKException, DimensionMismatch, SingularException, PosDefException, chkstride1, checksquare,triu, tril, dot using Base: iszero, require_one_based_indexing diff --git a/stdlib/LinearAlgebra/test/blas.jl b/stdlib/LinearAlgebra/test/blas.jl index d39f7c45ba205..117d7dc103605 100644 --- a/stdlib/LinearAlgebra/test/blas.jl +++ b/stdlib/LinearAlgebra/test/blas.jl @@ -668,10 +668,6 @@ end @test BLAS.get_num_threads() === default end -# https://github.com/JuliaLang/julia/pull/39845 -@test LinearAlgebra.BLAS.libblas == "libblastrampoline" -@test LinearAlgebra.BLAS.liblapack == "libblastrampoline" - @testset "test for 0-strides" for elty in (Float32, Float64, ComplexF32, ComplexF64) A = randn(elty, 10, 10); a = view([randn(elty)], 1 .+ 0(1:10)) diff --git a/stdlib/LinearAlgebra/test/lapack.jl b/stdlib/LinearAlgebra/test/lapack.jl index 284b512d93a18..dfcf3c89dac2a 100644 --- a/stdlib/LinearAlgebra/test/lapack.jl +++ b/stdlib/LinearAlgebra/test/lapack.jl @@ -702,9 +702,6 @@ let A = [NaN NaN; NaN NaN] @test_throws ArgumentError eigen(A) end -# # https://github.com/JuliaLang/julia/pull/39845 -@test LinearAlgebra.LAPACK.liblapack == "libblastrampoline" - # Issue #42762 https://github.com/JuliaLang/julia/issues/42762 # Tests geqrf! and gerqf! with null column dimensions a = zeros(2,0), zeros(0) diff --git a/stdlib/libblastrampoline_jll/Project.toml b/stdlib/libblastrampoline_jll/Project.toml index 26c67dae8dffd..63cad3d67acf8 100644 --- a/stdlib/libblastrampoline_jll/Project.toml +++ b/stdlib/libblastrampoline_jll/Project.toml @@ -5,7 +5,6 @@ version = "5.0.1+0" [deps] Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb" Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" -OpenBLAS_jll = "4536629a-c528-5b80-bd46-f80d51c5b363" [compat] julia = "1.8" diff --git a/test/precompile.jl b/test/precompile.jl index d39dcd9f7ccb8..e5e1c35ec34af 100644 --- a/test/precompile.jl +++ b/test/precompile.jl @@ -359,10 +359,10 @@ precompile_test_harness(false) do dir Dict(let m = Base.root_module(Base, s) Base.PkgId(m) => Base.module_build_id(m) end for s in - [:ArgTools, :Artifacts, :Base64, :CRC32c, :Dates, :DelimitedFiles, - :Distributed, :Downloads, :FileWatching, :Future, :InteractiveUtils, + [:ArgTools, :Artifacts, :Base64, :CompilerSupportLibraries_jll, :CRC32c, :Dates, :DelimitedFiles, + :Distributed, :Downloads, :FileWatching, :Future, :InteractiveUtils, :libblastrampoline_jll, :LazyArtifacts, :LibCURL, :LibCURL_jll, :LibGit2, :Libdl, :LinearAlgebra, - :Logging, :Markdown, :Mmap, :MozillaCACerts_jll, :NetworkOptions, :Pkg, :Printf, + :Logging, :Markdown, :Mmap, :MozillaCACerts_jll, :NetworkOptions, :OpenBLAS_jll, :Pkg, :Printf, :Profile, :p7zip_jll, :REPL, :Random, :SHA, :Serialization, :SharedArrays, :Sockets, :SparseArrays, :Statistics, :SuiteSparse, :TOML, :Tar, :Test, :UUIDs, :Unicode, :nghttp2_jll]