JuliaLang / JuliaLang/LinearAlgebra.jl

BLAS call overhead when running multi-threaded

Open
#889 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

multithreading
Dominant language
Julia
Stars
77
Forks
65
Avg merge
3d 23h
Merged PRs (30d)
10

Description

For julia 1.7 (and 1.6.4) running on Rosetta on m1, the default BLAS.get_num_threads() is 8 (for m1 pro, or 4 for m1); some operations are noticeably slower than running single-threaded, example:

using BenchmarkTools, LinearAlgebra


function make_lu(n)
    m = zeros(n, n)
    for i = 1:n
        v = rand(n)
        m .+= (0.1 + rand()^2) .* (v * v')
    end
    Hermitian(m)
end


println(BLAS.get_num_threads())
@benchmark lu!(a) setup = (a = make_lu(100))

Default (8 threads on m1 pro)

julia> @benchmark lu(a) setup = (a = make_lu(100))
BenchmarkTools.Trial: 1973 samples with 1 evaluation.
 Range (min … max):  149.041 μs … 153.483 ms  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):       1.199 ms               ┊ GC (median):    0.00%
 Time  (mean ± σ):     1.684 ms ±   3.857 ms  ┊ GC (mean ± σ):  0.06% ± 1.45%

While

julia> BLAS.set_num_threads(1)

julia> @benchmark lu(a) setup = (a = make_lu(100))
BenchmarkTools.Trial: 6048 samples with 1 evaluation.
 Range (min … max):  67.375 μs … 309.958 μs  ┊ GC (min … max): 0.00% … 76.96%
 Time  (median):     69.417 μs               ┊ GC (median):    0.00%
 Time  (mean ± σ):   70.368 μs ±   8.857 μs  ┊ GC (mean ± σ):  0.46% ±  2.89%

Is it some issue with openblas, or something wth julia?

julia> versioninfo()
Julia Version 1.7.0
Commit 3bf9d17731 (2021-11-30 12:12 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin19.5.0)
  CPU: Apple M1 Pro
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, westmere)
Environment:
  JULIA_MATHLINK = /Applications/Mathematica.app/Contents/Frameworks/mathlink.framework
  JULIA_MATHKERNEL = /Applications/Mathematica.app/Contents/MacOS/MathKernel

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No repository file or test entry point is mentioned. Start by reproducing the supplied Julia benchmark on the stated Apple M1/Rosetta setup, comparing the default BLAS thread count with one thread. Done means identifying whether the overhead comes from BLAS/OpenBLAS or Julia and recording a confirmed explanation or actionable direction.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.