Skip to content

Commit

Permalink
Simplification of libblastrampoline stuff in LinearAlgebra (#44360)
Browse files Browse the repository at this point in the history
* Report libblastrampoline as Base.libblas_name and Base.liblapack_name

* Cleanup a lot of the LBT stuff

* Fix

* Remove test for LinearAlgebra.LAPACK.liblapack

* Fix

* Fix the precompile tests
  • Loading branch information
ViralBShah committed Feb 28, 2022
1 parent 675911a commit e84b06c
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 68 deletions.
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions base/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions stdlib/LinearAlgebra/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
37 changes: 3 additions & 34 deletions stdlib/LinearAlgebra/src/LinearAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
14 changes: 1 addition & 13 deletions stdlib/LinearAlgebra/src/blas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
9 changes: 1 addition & 8 deletions stdlib/LinearAlgebra/src/lapack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions stdlib/LinearAlgebra/test/blas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 0 additions & 3 deletions stdlib/LinearAlgebra/test/lapack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion stdlib/libblastrampoline_jll/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions test/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit e84b06c

Please sign in to comment.