Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add BLAS.get_num_threads #36360

Merged
merged 30 commits into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
bea54cc
add BLAS.get_num_threads
jw3126 Jun 19, 2020
2de23cd
fix
jw3126 Jun 19, 2020
0e6f8fb
fix
jw3126 Jun 19, 2020
9f396c2
fix
jw3126 Jun 19, 2020
e84c258
fix
jw3126 Jun 19, 2020
9a0edcb
warn if get/set of num_bals_threads fails
jw3126 Jun 19, 2020
f6daa79
Update stdlib/LinearAlgebra/src/blas.jl
jw3126 Jun 20, 2020
8b2c8c4
Update stdlib/LinearAlgebra/src/blas.jl
jw3126 Jun 20, 2020
a15f851
Update stdlib/LinearAlgebra/src/blas.jl
jw3126 Jun 20, 2020
826d8ff
fix
jw3126 Jun 20, 2020
ce61636
Update stdlib/LinearAlgebra/src/blas.jl
jw3126 Jun 20, 2020
b38afaa
Update stdlib/LinearAlgebra/src/blas.jl
jw3126 Jun 20, 2020
0ee0efa
Update stdlib/LinearAlgebra/src/blas.jl
jw3126 Jun 20, 2020
8e4fedd
fix
jw3126 Jun 20, 2020
33a95d5
Update stdlib/LinearAlgebra/src/blas.jl
jw3126 Jun 20, 2020
35cf5a6
Update stdlib/LinearAlgebra/src/blas.jl
jw3126 Jun 20, 2020
bc370b4
Update stdlib/LinearAlgebra/src/blas.jl
jw3126 Jun 20, 2020
dd455b5
Update stdlib/LinearAlgebra/src/blas.jl
jw3126 Jun 20, 2020
abd2084
fix
jw3126 Jun 22, 2020
b8e9055
fix
jw3126 Jun 22, 2020
9eabcb6
Update stdlib/LinearAlgebra/src/blas.jl
jw3126 Jun 23, 2020
920b90b
Update stdlib/LinearAlgebra/src/blas.jl
jw3126 Jun 23, 2020
b011dc6
Update stdlib/LinearAlgebra/src/blas.jl
jw3126 Jun 23, 2020
95ccdf9
Update stdlib/LinearAlgebra/test/blas.jl
jw3126 Jun 23, 2020
72ef30e
Update stdlib/LinearAlgebra/src/blas.jl
jw3126 Jun 23, 2020
4cf2628
Update stdlib/LinearAlgebra/test/blas.jl
jw3126 Jun 23, 2020
bb69931
Update stdlib/LinearAlgebra/test/blas.jl
jw3126 Jun 23, 2020
06550d6
Update stdlib/LinearAlgebra/src/blas.jl
jw3126 Jun 23, 2020
b6aa076
improve docstrings
jw3126 Jun 23, 2020
c524c53
add to NEWS.md
jw3126 Jun 23, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions stdlib/LinearAlgebra/src/blas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,8 @@ Set the number of threads the BLAS library should use.
"""
function set_num_threads(n::Integer)
jw3126 marked this conversation as resolved.
Show resolved Hide resolved
blas = vendor()
if blas === :openblas
return ccall((:openblas_set_num_threads, libblas), Cvoid, (Int32,), n)
elseif blas === :openblas64
return ccall((:openblas_set_num_threads64_, libblas), Cvoid, (Int32,), n)
if blas === :openblas || blas == :openblas64
return ccall((@blasfunc(openblas_set_num_threads), libblas), Cvoid, (Int32,), n)
elseif blas === :mkl
# MKL may let us set the number of threads in several ways
return ccall((:MKL_Set_Num_Threads, libblas), Cvoid, (Cint,), n)
Expand All @@ -130,6 +128,24 @@ function set_num_threads(n::Integer)
return nothing
end

"""
get_num_threads()

Get the number of threads the BLAS library is using.
"""
function get_num_threads()
blas = LinearAlgebra.BLAS.vendor()
jw3126 marked this conversation as resolved.
Show resolved Hide resolved
if blas === :openblas || blas === :openblas64
jw3126 marked this conversation as resolved.
Show resolved Hide resolved
return ccall((@blasfunc(openblas_get_num_threads), libblas), Cint, ())
elseif blas == :mkl
return ccall((:mkl_get_max_threads, libblas), Cint, ())
elseif Sys.isapple()
tkf marked this conversation as resolved.
Show resolved Hide resolved
return Base.parse(Cint, ENV["VECLIB_MAXIMUM_THREADS"])
jw3126 marked this conversation as resolved.
Show resolved Hide resolved
else
error("Unknown BLAS") # better error? return nothing
jw3126 marked this conversation as resolved.
Show resolved Hide resolved
jw3126 marked this conversation as resolved.
Show resolved Hide resolved
end
end

const _testmat = [1.0 0.0; 0.0 -1.0]
function check()
blas = vendor()
Expand Down
11 changes: 11 additions & 0 deletions stdlib/LinearAlgebra/test/blas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -553,4 +553,15 @@ Base.stride(A::WrappedArray, i::Int) = stride(A.A, i)
end
end

@testset "get_set_num_threads" begin
default = BLAS.get_num_threads()
@test default isa Integer
@test default > 0
new = rand(1:10)
jw3126 marked this conversation as resolved.
Show resolved Hide resolved
BLAS.set_num_threads(new)
@test BLAS.get_num_threads() == new
BLAS.set_num_threads(default)
@test BLAS.get_num_threads() == default
end

end # module TestBLAS