Skip to content

Commit

Permalink
BLAS: avoid calling dlclose (#27509)
Browse files Browse the repository at this point in the history
We do not want libblas to get unloaded again here,
but we call this early enough, this is potentially
the only reference to it. That may lead to race
conditions where we try to teardown the library
while it is trying to spawn threads
(spawning threads is not generally permitted on Windows,
but is down anyways by libopenblas.dll).

So instead, we just cache our single reference to it,
and thereby avoid the need to call `dlclose`
to maintain the proper refcount.
  • Loading branch information
vtjnash authored and Keno committed Jun 10, 2018
1 parent 9224445 commit 2ba3fbb
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions stdlib/LinearAlgebra/src/blas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ import LinearAlgebra: BlasReal, BlasComplex, BlasFloat, BlasInt, DimensionMismat
import Libdl

# utility routines
function vendor()
lib = Libdl.dlopen_e(Base.libblas_name)
let lib = C_NULL
global function vendor()
lib == C_NULL && (lib = Libdl.dlopen_e(Base.libblas_name))
vend = :unknown
if lib != C_NULL
if Libdl.dlsym_e(lib, :openblas_set_num_threads) != C_NULL
Expand All @@ -80,23 +81,23 @@ function vendor()
elseif Libdl.dlsym_e(lib, :MKL_Set_Num_Threads) != C_NULL
vend = :mkl
end
Libdl.dlclose(lib)
end
return vend
end
end

if vendor() == :openblas64
macro blasfunc(x)
return Expr(:quote, Symbol(x, "64_"))
end
openblas_get_config() = strip(unsafe_string(ccall((:openblas_get_config64_, Base.libblas_name), Ptr{UInt8}, () )))
else
macro blasfunc(x)
return Expr(:quote, x)
end
openblas_get_config() = strip(unsafe_string(ccall((:openblas_get_config, Base.libblas_name), Ptr{UInt8}, () )))
end

openblas_get_config() = strip(unsafe_string(ccall((@blasfunc(openblas_get_config), Base.libblas_name), Ptr{UInt8}, () )))

"""
set_num_threads(n)
Expand Down

3 comments on commit 2ba3fbb

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily benchmark build, I will reply here when finished:

@nanosoldier runbenchmarks(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan

@vtjnash
Copy link
Member Author

@vtjnash vtjnash commented on 2ba3fbb Jun 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the test for atan2 needs to be updated (now deprecated to atan) and the following were broken sometime since it last ran (vs = daily_2018_5_23):

  • sumlinear_view
  • collection iteration (Dict, Set, Vector)
  • lufact Tridiagonal factorization
  • problems: go_game, parse_json, grigoriadis_khachiyan, laplacian, spellcheck, stockcorr, ziggurat
  • simd: conditional_loop, loop_fields!, manual_example!, sum_reduce, two_reductions
  • string join

79486b3...2ba3fbb [173 commits]

Please sign in to comment.