diff --git a/src/BLIS.jl b/src/BLIS.jl index 08fc700..33e0515 100644 --- a/src/BLIS.jl +++ b/src/BLIS.jl @@ -5,19 +5,21 @@ using Libdl using blis_jll using LinearAlgebra +global libblis_path = "" global libblis = C_NULL __init__() = begin if length(get(ENV, "BLISDIR", "")) > 0 # BLIS installation overriden by environmental variables. @info "Using custom defined BLIS installation instead of blis_jll." + global libblis_path = joinpath(get(ENV, "BLISDIR", ""), "lib/libblis") global libblis = dlopen(joinpath(get(ENV, "BLISDIR", ""), "lib/libblis")) else - blis_path = blis_jll.blis_path + global libblis_path = blis_jll.blis_path # Use BinaryBuilder provided BLIS library. - @info "blis_jll yields BLIS installation: $blis_path." - global libblis = dlopen(blis_path) + @info "blis_jll yields BLIS installation: $libblis_path." end + global libblis = dlopen(libblis_path) end # Data types. diff --git a/src/switch_blas.jl b/src/switch_blas.jl index e69de29..9edd335 100644 --- a/src/switch_blas.jl +++ b/src/switch_blas.jl @@ -0,0 +1,26 @@ +# LBT-forward BLAS calls +# + +global fallback_lib = [] + +lbt_enable_blis(; clear=false) = begin + if length(fallback_lib) == 0 + libs = LinearAlgebra.BLAS.lbt_get_config().loaded_libs + if length(libs) > 0 + # Save currently loaded library path for resetting. + fallback_lib = [fallback_lib..., ] + end + + LinearAlgebra.BLAS.lbt_forward(libblis_path; clear=clear) + else + @warn "BLIS.lbt_enable_blis: BLIS already loaded. Not doing anything." + end +end + +lbt_disable_blis() = begin + if length(fallback_lib) > 0 + LinearAlgebra.BLAS.lbt_forward(fallback_lib[1]; clear=true) + else + @warn "BLIS.lbt_enable_blis: Fallback library not found. Not doing anything." + end +end