@@ -18,6 +18,7 @@ import Base: USE_BLAS64, abs, acos, acosh, acot, acoth, acsc, acsch, adjoint, as
18
18
using Base: hvcat_fill, IndexLinear, promote_op, promote_typeof,
19
19
@propagate_inbounds , @pure , reduce, typed_vcat, require_one_based_indexing
20
20
using Base. Broadcast: Broadcasted, broadcasted
21
+ import Libdl
21
22
22
23
export
23
24
# Modules
@@ -433,21 +434,55 @@ function versioninfo(io::IO=stdout)
433
434
println (io, " LAPACK: " ,Base. liblapack_name)
434
435
end
435
436
436
- function __init__ ()
437
- try
438
- BLAS. check ()
439
- if BLAS. vendor () === :mkl
440
- ccall ((:MKL_Set_Interface_Layer , Base. libblas_name), Cvoid, (Cint,), USE_BLAS64 ? 1 : 0 )
437
+ function get_blas_lapack_path ()
438
+ shlib_ext = string (" ." , Libdl. dlext)
439
+ libblas_path = joinpath (Sys. BINDIR, Base. LIBDIR, " julia" , string (Base. libblas_name, shlib_ext))
440
+ if ! isfile (libblas_path)
441
+ libblas_path = joinpath (Sys. BINDIR, Base. LIBDIR, string (Base. libblas_name, shlib_ext))
442
+ if ! isfile (libblas_path)
443
+ libblas_path = joinpath (Sys. BINDIR, string (Base. libblas_name, shlib_ext))
444
+ if ! isfile (libblas_path)
445
+ error (" Cannot find BLAS at " , libblas_path)
446
+ end
447
+ end
448
+ end
449
+ liblapack_path = joinpath (Sys. BINDIR, Base. LIBDIR, " julia" , string (Base. liblapack_name, shlib_ext))
450
+ if ! isfile (liblapack_path)
451
+ liblapack_path = joinpath (Sys. BINDIR, Base. LIBDIR, string (Base. liblapack_name, shlib_ext))
452
+ if ! isfile (liblapack_path)
453
+ liblapack_path = joinpath (Sys. BINDIR, string (Base. liblapack_name, shlib_ext))
454
+ if ! isfile (liblapack_path)
455
+ error (" Cannot find LAPACK at " , liblapack_path)
456
+ end
441
457
end
442
- Threads. resize_nthreads! (Abuf)
443
- Threads. resize_nthreads! (Bbuf)
444
- Threads. resize_nthreads! (Cbuf)
445
- catch ex
446
- Base. showerror_nostdio (ex,
447
- " WARNING: Error during initialization of module LinearAlgebra" )
448
458
end
449
- # register a hook to disable BLAS threading
450
- Base. at_disable_library_threading (() -> BLAS. set_num_threads (1 ))
459
+
460
+ return (libblas_path, liblapack_path)
461
+ end
462
+
463
+ function set_blas_lapack_trampoline! (vendor, libblas_path, liblapack_path; verbose= 0 )
464
+ BLAS. set_vendor! (vendor)
465
+ ccall ((:lbt_forward , " libblastrampoline" ), Cvoid, (Cstring,Cint,Cint), libblas_path, 1 , verbose)
466
+ if liblapack_path != libblas_path
467
+ ccall ((:lbt_forward , " libblastrampoline" ), Cvoid, (Cstring,Cint,Cint), liblapack_path, 0 , verbose)
468
+ end
469
+ end
470
+
471
+ function __init__ ()
472
+ try
473
+ libblas_path, liblapack_path = get_blas_lapack_path ()
474
+ vendor = Base. USE_BLAS64 ? :openblas64 : :openblas
475
+ set_blas_lapack_trampoline! (vendor, libblas_path, liblapack_path)
476
+ BLAS. check ()
477
+ Threads. resize_nthreads! (Abuf)
478
+ Threads. resize_nthreads! (Bbuf)
479
+ Threads. resize_nthreads! (Cbuf)
480
+ catch ex
481
+ Base. showerror_nostdio (ex,
482
+ " WARNING: Error during initialization of module LinearAlgebra" )
483
+ end
484
+ # register a hook to disable BLAS threading
485
+ Base. at_disable_library_threading (() -> BLAS. set_num_threads (1 ))
451
486
end
452
487
453
488
end # module LinearAlgebra
0 commit comments