JuliaLinearAlgebra / BLIS.jl

This repo plans to provide a low-level Julia wrapper for BLIS typed interface.
BSD 3-Clause "New" or "Revised" License
26 stars 4 forks source link

Crashing on Windows with julia 1.8.4 or above #23

Closed jd-foster closed 1 year ago

jd-foster commented 1 year ago

Here is a MWE crash reproducer (fails at time of writing onJulia Version 1.10.0-DEV.1059) extracted from init_test_mmul.jl:

using LinearAlgebra

T = Float32
αr = 1.1
βr = 1.1
αu = T(αr)
βu = T(βr)

χlarge = 500
Alarge_base = rand(ComplexF64, χlarge, χlarge)
Blarge_base = rand(ComplexF64, χlarge, χlarge)
Clarge_base = rand(ComplexF64, χlarge, χlarge)

Alarge = zeros(T, χlarge, χlarge)
Blarge = zeros(T, χlarge, χlarge)

elconv = x -> real(x)

Alarge .= elconv.(Alarge_base)
Blarge .= elconv.(Blarge_base)

Clarge_gemm_cur  = T.(elconv.(Clarge_base))

BLAS.gemm!('N', 'N', αu, Alarge, Blarge, βu, Clarge_gemm_cur)

X_jl = deepcopy(Clarge_gemm_cur)

using BLIS

Clarge_gemm_cur  = T.(elconv.(Clarge_base))
BLAS.gemm!('N', 'N', αu, Alarge, Blarge, βu, Clarge_gemm_cur)

X_bl = deepcopy(Clarge_gemm_cur)

@assert all(X_jl .≈ X_bl)
jd-foster commented 1 year ago

Actually the above is too much too complicated. It's a basic failure when calling gemm!:

using LinearAlgebra
using BLIS
T = Float32
χlarge = 500
BLAS.gemm!('N', 'N', T(1.1), rand(T, χlarge, χlarge), rand(T, χlarge, χlarge), T(1.1),  rand(T, χlarge, χlarge))
jd-foster commented 1 year ago

Seems to be an issue with blis_jll and the library interaction since the same happens using just libblastrampoline:

using LinearAlgebra
using blis_jll

BLAS.lbt_forward(blis_jll.blis_path)

A = rand(1000,1000); B = rand(1000,1000);
A * B

crashes as well.

jd-foster commented 1 year ago

Ok, I've verified that this is the same issue as https://github.com/JuliaLang/julia/issues/48187 with the regression introduced in Julia 1.8.4

See also: https://discourse.julialang.org/t/issue-with-xgboost-jl-and-libsvm-jl-when-julia-1-8-4/92396/19

jd-foster commented 1 year ago

If this has anything to do with an incompatibility between GCC 12 and OpenMP (actually beyond my ability to figure out at this point), it may be worth compiling target *"x86_64"*"w64"* with -t single, that is setting BLI_THREAD=single (here: https://github.com/JuliaPackaging/Yggdrasil/blob/b7c92f501764d994e3c3accafeef14da37ea91f0/B/blis/build_tarballs.jl#L40)

cf. the blis configure docs for the description.

An interesting and very recent commit is the new feature Optionally disable thread-local storage

jd-foster commented 1 year ago

This is now solved on the nightly thanks to @giordano merging https://github.com/JuliaLang/julia/pull/50135 and will likely be back-ported to julia 1.9 soon.