carstenbauer / ThreadPinning.jl

Readily pin Julia threads to CPU-threads
https://carstenbauer.github.io/ThreadPinning.jl/
MIT License
106 stars 7 forks source link

Failed to precompile #26

Closed DatName closed 1 year ago

DatName commented 1 year ago

I am trying to update to version 0.6.0, but:

[ Info: Precompiling ThreadPinning [811555cd-349b-4f26-b7bc-1f208b848042]
ERROR: LoadError: BoundsError: attempt to access 14-element Vector{Int64} at index [1:20]
Stacktrace:
  [1] throw_boundserror(A::Vector{Int64}, I::Tuple{UnitRange{Int64}})
    @ Base ./abstractarray.jl:703
  [2] checkbounds
    @ ./abstractarray.jl:668 [inlined]
  [3] view
    @ ./subarray.jl:177 [inlined]
  [4] maybeview
    @ ./views.jl:146 [inlined]
  [5] pinthreads(pinning::ThreadPinning.CompactBind; places::ThreadPinning.Cores, nthreads::Int64, warn::Bool, force::Bool, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ ThreadPinning ~/.julia/packages/ThreadPinning/ChuwG/src/pinning.jl:158
  [6] pinthreads(pinning::ThreadPinning.CompactBind)
    @ ThreadPinning ~/.julia/packages/ThreadPinning/ChuwG/src/pinning.jl:150
  [7] pinthreads(pinning::Symbol; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ ThreadPinning ~/.julia/packages/ThreadPinning/ChuwG/src/pinning.jl:163
  [8] pinthreads
    @ ~/.julia/packages/ThreadPinning/ChuwG/src/pinning.jl:162 [inlined]
  [9] macro expansion
    @ ~/.julia/packages/ThreadPinning/ChuwG/src/ThreadPinning.jl:90 [inlined]
 [10] top-level scope
    @ ~/.julia/packages/SnoopPrecompile/UWvXF/src/SnoopPrecompile.jl:51
 [11] include
    @ ./Base.jl:419 [inlined]
 [12] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt64}}, source::Nothing)
    @ Base ./loading.jl:1554
 [13] top-level scope
    @ stdin:1
julia> versioninfo()
Julia Version 1.8.2
Commit 36034abf260 (2022-09-29 15:21 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 20 Γ— 12th Gen Intel(R) Core(TM) i9-12900H
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, goldmont)
  Threads: 20 on 20 virtual cores
Environment:
  JULIA_EXCLUSIVE = 1
  JULIA_NUM_THREADS = 20
  JULIA_EDITOR = code
carstenbauer commented 1 year ago

Thanks for opening an issue. Can you share the output of lscpu --all --extended?

DatName commented 1 year ago

Sure

:~ $ lscpu --all --extended
CPU NODE SOCKET CORE L1d:L1i:L2:L3 ONLINE    MAXMHZ   MINMHZ      MHZ
  0    0      0    0 0:0:0:0          yes 5000.0000 400.0000 2900.000
  1    0      0    0 0:0:0:0          yes 5000.0000 400.0000 2900.000
  2    0      0    1 4:4:1:0          yes 5000.0000 400.0000 2900.000
  3    0      0    1 4:4:1:0          yes 5000.0000 400.0000 2900.000
  4    0      0    2 8:8:2:0          yes 5000.0000 400.0000 2900.000
  5    0      0    2 8:8:2:0          yes 5000.0000 400.0000 2900.000
  6    0      0    3 12:12:3:0        yes 5000.0000 400.0000 2900.000
  7    0      0    3 12:12:3:0        yes 5000.0000 400.0000 2900.000
  8    0      0    4 16:16:4:0        yes 5000.0000 400.0000 2900.000
  9    0      0    4 16:16:4:0        yes 5000.0000 400.0000 2900.000
 10    0      0    5 20:20:5:0        yes 5000.0000 400.0000  495.484
 11    0      0    5 20:20:5:0        yes 5000.0000 400.0000 2900.000
 12    0      0    6 24:24:6:0        yes 3800.0000 400.0000 2900.000
 13    0      0    7 25:25:6:0        yes 3800.0000 400.0000 2900.000
 14    0      0    8 26:26:6:0        yes 3800.0000 400.0000 2900.000
 15    0      0    9 27:27:6:0        yes 3800.0000 400.0000 2900.000
 16    0      0   10 28:28:7:0        yes 3800.0000 400.0000 2900.000
 17    0      0   11 29:29:7:0        yes 3800.0000 400.0000 2900.000
 18    0      0   12 30:30:7:0        yes 3800.0000 400.0000 2900.000
 19    0      0   13 31:31:7:0        yes 3800.0000 400.0000 2900.000
carstenbauer commented 1 year ago

First of all, interesting CPU. (I've not fully arrived in the world of "efficiency" and "performance" cores yet πŸ˜„)

In my rewrite for 0.6.0 I forgot to handle the case where the number of Julia threads is larger than the number of available cpu ids for a given pinning scheme. That is what hit you here because you have JULIA_NUM_THREADS=20 but only 14 cores (which is the places default for :compact pinning). I've fixed it on the main branch and have included your lscpu output into the test suite as well.

@DatName, it would be great if you could ] add ThreadPinning#main and test if things are working. If so, I'll tag a new patch release soon after.

(BTW, the reason that this error appears already when precompiling is because we now use SnoopPrecompile to trigger some commands at precompile time to reduce runtime later.)

DatName commented 1 year ago

Here it is:

() pkg> add ThreadPinning#main
     Cloning git-repo `https://github.com/carstenbauer/ThreadPinning.jl.git`
    Updating git-repo `https://github.com/carstenbauer/ThreadPinning.jl.git`
    Updating registry at `~/.julia/registries/KRWRegistry`
    Updating git-repo `git@gitlab-kr:bender-ops/krwregistry.git`
    Updating registry at `~/.julia/registries/General.toml`
   Resolving package versions...
    Updating `~/Project.toml`
  [811555cd] + ThreadPinning v0.6.0 `https://github.com/carstenbauer/ThreadPinning.jl.git#main`
    Updating `~/Manifest.toml`
  [21216c6a] + Preferences v1.3.0
  [66db9d55] + SnoopPrecompile v1.0.1
  [811555cd] + ThreadPinning v0.6.0 `https://github.com/carstenbauer/ThreadPinning.jl.git#main`
  [56f22d72] + Artifacts
  [ade2ca70] + Dates
  [8bb1440f] + DelimitedFiles
  [8f399da3] + Libdl
  [37e2e46d] + LinearAlgebra
  [a63ad114] + Mmap
  [de0858da] + Printf
  [9a3f8284] + Random
  [ea8e919c] + SHA v0.7.0
  [9e88b42a] + Serialization
  [fa267f1f] + TOML v1.0.0
  [4ec0a83e] + Unicode
  [e66e0078] + CompilerSupportLibraries_jll v0.5.2+0
  [4536629a] + OpenBLAS_jll v0.3.20+0
  [8e850b90] + libblastrampoline_jll v5.1.1+0
Precompiling project...
  βœ— ThreadPinning
  0 dependencies successfully precompiled in 2 seconds. 5 already precompiled.
  1 dependency errored. To see a full report either run `import Pkg; Pkg.precompile()` or load the package

julia> using ThreadPinning
[ Info: Precompiling ThreadPinning [811555cd-349b-4f26-b7bc-1f208b848042]
ERROR: LoadError: ArgumentError: Only same length inputs supported.
Stacktrace:
  [1] interweave(::Vector{Int64}, ::Vararg{Vector{Int64}})
    @ ThreadPinning ~/.julia/packages/ThreadPinning/HVVtE/src/utility.jl:52
  [2] getplaces_cpuids
    @ ~/.julia/packages/ThreadPinning/HVVtE/src/pinning.jl:78 [inlined]
  [3] getcpuids_pinning(::ThreadPinning.RandomBind, places::ThreadPinning.CPUThreads; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ ThreadPinning ~/.julia/packages/ThreadPinning/HVVtE/src/pinning.jl:124
  [4] getcpuids_pinning
    @ ~/.julia/packages/ThreadPinning/HVVtE/src/pinning.jl:123 [inlined]
  [5] pinthreads(pinning::ThreadPinning.RandomBind; places::ThreadPinning.CPUThreads, nthreads::Int64, warn::Bool, force::Bool, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ ThreadPinning ~/.julia/packages/ThreadPinning/HVVtE/src/pinning.jl:157
  [6] pinthreads(pinning::Symbol; kwargs::Base.Pairs{Symbol, Int64, Tuple{Symbol}, NamedTuple{(:nthreads,), Tuple{Int64}}})
    @ ThreadPinning ~/.julia/packages/ThreadPinning/HVVtE/src/pinning.jl:169
  [7] macro expansion
    @ ~/.julia/packages/ThreadPinning/HVVtE/src/ThreadPinning.jl:92 [inlined]
  [8] top-level scope
    @ ~/.julia/packages/SnoopPrecompile/UWvXF/src/SnoopPrecompile.jl:51
  [9] include
    @ ./Base.jl:419 [inlined]
 [10] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt64}}, source::Nothing)
    @ Base ./loading.jl:1554
 [11] top-level scope
    @ stdin:1
in expression starting at /home//.julia/packages/ThreadPinning/HVVtE/src/ThreadPinning.jl:1
in expression starting at stdin:1
carstenbauer commented 1 year ago

@DatName, please try again (with the updated main branch).

DatName commented 1 year ago

Success. Thank you.

But FYI some tests are failing now:

Test Summary:                   | Pass  Fail  Error  Broken  Total  Time
Package                         |  165     4      1       8    178  7.8s
  test/runtests.jl              |  165     4      1       8    178  7.8s
    Helper                      |    6                           6  0.9s
    System Info                 |   73                          73  0.2s
    Pinning                     |   38     4      1             43  5.6s
      Thread Pinning (explicit) |   16                          16  0.1s
      Thread Pinning (compact)  |    4     4                     8  0.7s
      Thread Pinning (spread)   |    4                           4  0.0s
      Thread Pinning (numa)     |    4                           4  0.0s
      Thread Pinning (current)  |    2                           2  0.0s
      Environment variables     |    2            1              3  4.4s
      First pin attempt         |    6                           6  0.1s
    Querying                    |   14                          14  0.1s
    threadinfo                  |    2                           2  0.3s
    OMP                         |   15                    8     23  0.4s
    Preferences                 |   17                          17  0.3s
ERROR: LoadError: Some tests did not pass: 165 passed, 4 failed, 1 errored, 8 broken
     Testing Running tests...
β”Œ Warning: Could read `lscpu --all --extended` but number of online CPUs (128) doesn't match Sys.CPU_THREADS (20).
β”” @ ThreadPinning ~/.julia/packages/ThreadPinning/tgIiu/src/sysinfo.jl:79
β”Œ Warning: Could read `lscpu --all --extended` but number of online CPUs (128) doesn't match Sys.CPU_THREADS (20).
β”” @ ThreadPinning ~/.julia/packages/ThreadPinning/tgIiu/src/sysinfo.jl:79
β”Œ Warning: Could read `lscpu --all --extended` but number of online CPUs (40) doesn't match Sys.CPU_THREADS (20).
β”” @ ThreadPinning ~/.julia/packages/ThreadPinning/tgIiu/src/sysinfo.jl:79
β”Œ Warning: Could read `lscpu --all --extended` but number of online CPUs (50) doesn't match Sys.CPU_THREADS (20).
β”” @ ThreadPinning ~/.julia/packages/ThreadPinning/tgIiu/src/sysinfo.jl:79
Thread Pinning (compact): Test Failed at /home//.julia/packages/ThreadPinning/tgIiu/test/pinning_test.jl:53
  Expression: (getcpuids())[1:2] == 0:1
   Evaluated: [0, 2] == 0:1
Stacktrace:
 [1] macro expansion
   @ ~/work/julia/julia-1.8.2/share/julia/stdlib/v1.8/Test/src/Test.jl:464 [inlined]
 [2] macro expansion
   @ ~/.julia/packages/ThreadPinning/tgIiu/test/pinning_test.jl:53 [inlined]
 [3] macro expansion
   @ ~/work/julia/julia-1.8.2/share/julia/stdlib/v1.8/Test/src/Test.jl:1357 [inlined]
 [4] top-level scope
   @ ~/.julia/packages/ThreadPinning/tgIiu/test/pinning_test.jl:50
β”Œ Warning: More Julia threads than CPU IDs to bind to. Some CPU threads will host multiple Julia threads!
β”” @ ThreadPinning ~/.julia/packages/ThreadPinning/tgIiu/src/pinning.jl:162
Thread Pinning (compact): Test Failed at /home//.julia/packages/ThreadPinning/tgIiu/test/pinning_test.jl:55
  Expression: getcpuids() == 0:nthreads() - 1
   Evaluated: [0, 2, 4, 6, 8, 10, 12, 13, 14, 15, 16, 17, 18, 19, 0, 2, 4, 6, 8, 10] == 0:19
Stacktrace:
 [1] macro expansion
   @ ~/work/julia/julia-1.8.2/share/julia/stdlib/v1.8/Test/src/Test.jl:464 [inlined]
 [2] macro expansion
   @ ~/.julia/packages/ThreadPinning/tgIiu/test/pinning_test.jl:55 [inlined]
 [3] macro expansion
   @ ~/work/julia/julia-1.8.2/share/julia/stdlib/v1.8/Test/src/Test.jl:1357 [inlined]
 [4] top-level scope
   @ ~/.julia/packages/ThreadPinning/tgIiu/test/pinning_test.jl:50
Thread Pinning (compact): Test Failed at /home//.julia/packages/ThreadPinning/tgIiu/test/pinning_test.jl:53
  Expression: (getcpuids())[1:2] == 0:1
   Evaluated: [0, 2] == 0:1
Stacktrace:
 [1] macro expansion
   @ ~/work/julia/julia-1.8.2/share/julia/stdlib/v1.8/Test/src/Test.jl:464 [inlined]
 [2] macro expansion
   @ ~/.julia/packages/ThreadPinning/tgIiu/test/pinning_test.jl:53 [inlined]
 [3] macro expansion
   @ ~/work/julia/julia-1.8.2/share/julia/stdlib/v1.8/Test/src/Test.jl:1357 [inlined]
 [4] top-level scope
   @ ~/.julia/packages/ThreadPinning/tgIiu/test/pinning_test.jl:50
β”Œ Warning: More Julia threads than CPU IDs to bind to. Some CPU threads will host multiple Julia threads!
β”” @ ThreadPinning ~/.julia/packages/ThreadPinning/tgIiu/src/pinning.jl:162
Thread Pinning (compact): Test Failed at /home//.julia/packages/ThreadPinning/tgIiu/test/pinning_test.jl:55
  Expression: getcpuids() == 0:nthreads() - 1
   Evaluated: [0, 2, 4, 6, 8, 10, 12, 13, 14, 15, 16, 17, 18, 19, 0, 2, 4, 6, 8, 10] == 0:19
Stacktrace:
 [1] macro expansion
   @ ~/work/julia/julia-1.8.2/share/julia/stdlib/v1.8/Test/src/Test.jl:464 [inlined]
 [2] macro expansion
   @ ~/.julia/packages/ThreadPinning/tgIiu/test/pinning_test.jl:55 [inlined]
 [3] macro expansion
   @ ~/work/julia/julia-1.8.2/share/julia/stdlib/v1.8/Test/src/Test.jl:1357 [inlined]
 [4] top-level scope
   @ ~/.julia/packages/ThreadPinning/tgIiu/test/pinning_test.jl:50
Test Failed at none:2
  Expression: getcpuids() == (cpuids_all())[1:Threads.nthreads()]
   Evaluated: [0, 2, 4] == [0, 1, 2]
ERROR: There was an error during testing
Environment variables: Error During Test at /home//.julia/packages/ThreadPinning/tgIiu/test/pinning_test.jl:86
  Test threw exception
  Expression: exec(`'using ThreadPinning, Test;
            @test getcpuids() == cpuids_all()[1:Threads.nthreads()]'`)
  failed process: Process(`/home//work/julia/julia-1.8.2/bin/julia -Cnative -J/home//work/julia/julia-1.8.2/lib/julia/sys.so --depwarn=yes --check-bounds=yes -g1 --color=yes --startup-file=no --project=/home//.julia/packages/ThreadPinning/tgIiu/test/.. -t 3 -e 'using ThreadPinning, Test;
              @test getcpuids() == cpuids_all()[1:Threads.nthreads()]'`, ProcessExited(1)) [1]

  Stacktrace:
   [1] pipeline_error
     @ ./process.jl:565 [inlined]
   [2] run(::Cmd; wait::Bool)
     @ Base ./process.jl:480
   [3] run
     @ ./process.jl:477 [inlined]
   [4] exec
     @ ~/.julia/packages/ThreadPinning/tgIiu/test/pinning_test.jl:84 [inlined]
   [5] macro expansion
     @ ~/work/julia/julia-1.8.2/share/julia/stdlib/v1.8/Test/src/Test.jl:464 [inlined]
   [6] (::Main.var"##314".var"#5#9"{Main.var"##314".var"#exec#8"{String, Cmd}})()
     @ Main.var"##314" ~/.julia/packages/ThreadPinning/tgIiu/test/pinning_test.jl:86
carstenbauer commented 1 year ago

Success. Thank you.

Great.

But FYI some tests are failing now:

Can you update and try again? As soon as this works I'll tag a new patch release.

DatName commented 1 year ago

passes with two types of warning:

β”Œ Warning: Could read `lscpu --all --extended` but number of online CPUs (50) doesn't match Sys.CPU_THREADS (20).
β”” @ ThreadPinning ~/.julia/packages/ThreadPinning/ljr8h/src/sysinfo.jl:79
β”Œ Warning: More Julia threads than CPU IDs to bind to. Some CPU threads will host multiple Julia threads!
β”” @ ThreadPinning ~/.julia/packages/ThreadPinning/ljr8h/src/pinning.jl:162
Test Summary: | Pass  Broken  Total  Time
Package       |  170       8    178  7.2s
carstenbauer commented 1 year ago

Second warning is fine/expected. First warning is a bit strange: I don't understand the "online CPUs (50)" part because your lscpu output only shows 20 and that number should come directly from there... (UPDATE: Nevermind, the first warning is also expected)

In any case, thanks for the input and sorry for the inconvenience. I'll tag a new patch release in a few minutes.