# Linking to MKL 2019 with AMD CPUs?

**URL:** <https://discourse.julialang.org/t/linking-to-mkl-2019-with-amd-cpus/71508>\
**Category:** Performance\
**Tags:** question\
**Created:** [November 15, 2021, 4:40pm UTC](https://discourse.julialang.org/t/linking-to-mkl-2019-with-amd-cpus/71508 "2021-11-15T16:40:28Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![pablosanjose](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pablosanjose/32/7006_2.png) [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)\
**Post date:** [November 15, 2021, 4:40pm UTC](https://discourse.julialang.org/t/linking-to-mkl-2019-with-amd-cpus/71508/1 "2021-11-15T16:40:28Z")

</div>

## Question

Does BinaryBuilder allow Ryzen/Threadripper owners to choose MKL 2019 as the binary to use for MKL.jl and MKLSparse.jl?

## Context

Back in 2019 the MKL libraries had a “loophole” that allowed AMD CPUs to take advantage of all the nifty engineering done by Intel by setting the env variable `MKL_DEBUG_CPU_TYPE = 5`. (In other words, the high MKL performance, it turned out, was not due to Intel hardware, but to their talented software team). That loophole was unfortunately closed by Intel with the 2020 version. It was argued that the reason was that they were adding actual support for AMD. Not so fast…

The great IT guys at my institute recently did a benchmark comparison of different MKL versions on different AMD (Threadripper and Ryzen) and Intel CPUs (i7, i9, Xeon), and found that (1) AMD often smokes Intel CPUs if they can make use of the loophole, and (2) after version 2020 they lost this advantage. Here are the results (an asterisk corresponds to _not_ using `MKL_DEBUG_CPU_TYPE = 5`).

 ![cbbfgagoaohagipe](https://global.discourse-cdn.com/julialang/original/3X/1/8/18bf3013d0193341d7655fda3c7d78e2ba2c8e38.png)  
 ![cgdjmhjchlomnlae](https://global.discourse-cdn.com/julialang/original/3X/c/5/c5e491c9774eac75d37b0a6e78576133d390e3a2.png)  
 ![bjdkgkkjomeoldha](https://global.discourse-cdn.com/julialang/original/3X/4/9/49d0f5073a6c668552d62ee334f705c846717d66.png)  
 ![cjkojnimojabadap](https://global.discourse-cdn.com/julialang/original/3X/c/c/cc67e802b07a5f77b7321a0bc4c4044c7419907f.png)

Hence my question above.

CC: @Bruno_Amorim, @jamblejoe

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [November 15, 2021, 4:50pm UTC](https://discourse.julialang.org/t/linking-to-mkl-2019-with-amd-cpus/71508/2 "2021-11-15T16:50:20Z")

</div>

> [@pablosanjose](#):
>
> Does BinaryBuilder allow Ryzen/Threadripper owners to choose MKL 2019 as the binary to use for MKL.jl and MKLSparse.jl?

[Release MKL-v2019.0.117+2 · JuliaBinaryWrappers/MKL\_jll.jl · GitHub](https://github.com/JuliaBinaryWrappers/MKL_jll.jl/releases/tag/MKL-v2019.0.117%2B2), but it may be incompatible with other packages, it’s _old_

---

<div class="post-metadata">

**Author:** ![jamblejoe](https://avatars.discourse-cdn.com/v4/letter/j/ee7513/32.png) [@jamblejoe](https://discourse.julialang.org/u/jamblejoe)\
**Post date:** [November 15, 2021, 5:37pm UTC](https://discourse.julialang.org/t/linking-to-mkl-2019-with-amd-cpus/71508/3 "2021-11-15T17:37:05Z")

</div>

I cannot answer your question, but maybe it will be possible to use AMDs optimized libraries in the near future with libblastrampoline and Julia v1.7? Did your IT guys test against BLIS/libflame ([Basic Linear Algebra Subprograms (BLAS) Libraries - AMD](https://developer.amd.com/amd-aocl/blas-library/)) as well?  
Maybe @staticfloat @viralbshah ?

---

<div class="post-metadata">

**Author:** ![pablosanjose](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pablosanjose/32/7006_2.png) [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)\
**Post date:** [November 15, 2021, 5:41pm UTC](https://discourse.julialang.org/t/linking-to-mkl-2019-with-amd-cpus/71508/4 "2021-11-15T17:41:16Z")

</div>

I just asked, will report back with what they tell me

---

<div class="post-metadata">

**Author:** ![pablosanjose](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pablosanjose/32/7006_2.png) [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)\
**Post date:** [November 15, 2021, 5:42pm UTC](https://discourse.julialang.org/t/linking-to-mkl-2019-with-amd-cpus/71508/5 "2021-11-15T17:42:08Z")

</div>

> [@giordano](#):
>
> [Release MKL-v2019.0.117+2 · JuliaBinaryWrappers/MKL\_jll.jl · GitHub](https://github.com/JuliaBinaryWrappers/MKL_jll.jl/releases/tag/MKL-v2019.0.117%2B2), but it may be incompatible with other packages, it’s _old_

Uhm, nice, but how can we use that in combination with the libblastranpoline and MKL.jl? (sorry if this is a dumb question)

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [November 15, 2021, 5:44pm UTC](https://discourse.julialang.org/t/linking-to-mkl-2019-with-amd-cpus/71508/6 "2021-11-15T17:44:04Z")

</div>

> [@pablosanjose](#):
>
> but how can we use that in combination with the libblastranpoline and MKL.jl?

Manually installing `MKL_jll.jl` directly with this version (and pinning it, to be safe) and then installing MKL.jl should work I guess.

I.e.

```julia
] add MKL_jll@2019.0.117
] pin MKL_jll
] add MKL

```

**UPDATE:**

Hm, it fails for me on macOS in a quick test but maybe you have more luck 🙂

---

<div class="post-metadata">

**Author:** ![pablosanjose](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pablosanjose/32/7006_2.png) [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)\
**Post date:** [November 15, 2021, 5:51pm UTC](https://discourse.julialang.org/t/linking-to-mkl-2019-with-amd-cpus/71508/7 "2021-11-15T17:51:57Z")

</div>

Yes, it fails for me too. It seems to try to inject itself into the sysimg, like in old times (à la 1.6)

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [November 15, 2021, 6:11pm UTC](https://discourse.julialang.org/t/linking-to-mkl-2019-with-amd-cpus/71508/8 "2021-11-15T18:11:35Z")

</div>

[https://github.com/JuliaLinearAlgebra/MKL.jl/blob/238a4bb8d65037657d1e697f14655834249f309d/Project.toml#L13](https://github.com/JuliaLinearAlgebra/MKL.jl/blob/238a4bb8d65037657d1e697f14655834249f309d/Project.toml#L13)

---

<div class="post-metadata">

**Author:** ![pablosanjose](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pablosanjose/32/7006_2.png) [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)\
**Post date:** [November 15, 2021, 6:25pm UTC](https://discourse.julialang.org/t/linking-to-mkl-2019-with-amd-cpus/71508/9 "2021-11-15T18:25:00Z")

</div>

No luck, I tried with `MKL_jll = "2019.0.117"` in Project.toml and got the following:

```julia
(@v1.7) pkg> build MKL
    Building MKL → `~/.julia/dev/MKL/deps/build.log`
┌ Warning: Could not use exact versions of packages in manifest, re-resolving
└ @ Pkg.Operations /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.7/Pkg/src/Operations.jl:1488
ERROR: Error building `MKL`: 
ERROR: LoadError: InitError: UndefVarError: is_available not defined
Stacktrace:
 [1] getproperty
   @ ./Base.jl:35 [inlined]
 [2] __init__ ()
   @ MKL ~/.julia/dev/MKL/src/MKL.jl:41
 [3] _include_from_serialized(path::String, depmods::Vector{Any})
   @ Base ./loading.jl:768
 [4] _require_from_serialized(path::String)
   @ Base ./loading.jl:821
 [5] _require(pkg::Base.PkgId)
   @ Base ./loading.jl:1130
 [6] require(uuidkey::Base.PkgId)
   @ Base ./loading.jl:1013
 [7] require(into::Module, mod::Symbol)
   @ Base ./loading.jl:997
 [8] include(fname::String)
   @ Base.MainInclude ./client.jl:451
 [9] top-level scope
   @ none:5
during initialization of module MKL
in expression starting at /Users/pablo/.julia/dev/MKL/deps/build.jl:1

```

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [November 15, 2021, 6:30pm UTC](https://discourse.julialang.org/t/linking-to-mkl-2019-with-amd-cpus/71508/10 "2021-11-15T18:30:59Z")

</div>

Which is precisely the reason why the compat is there in the first place:

> <https://github.com/JuliaLinearAlgebra/MKL.jl/pull/63#issuecomment-787204283>
>
> An out-of-date version of \`MKL\_jll\`? \[Latest\](https://github.com/JuliaBinaryWra…ppers/MKL\_jll.jl/releases/tag/MKL-v2021.1.1%2B1) is \`v2021.1.1+1\`

Don’t say I didn’t warn you

> [@giordano](#):
>
> but it may be incompatible with other packages, it’s _old_

---

<div class="post-metadata">

**Author:** ![pablosanjose](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pablosanjose/32/7006_2.png) [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)\
**Post date:** [November 15, 2021, 7:40pm UTC](https://discourse.julialang.org/t/linking-to-mkl-2019-with-amd-cpus/71508/11 "2021-11-15T19:40:22Z")

</div>

Thanks @giordano. Although that’s a no, I’ll mark it as the solution, as I guess the situation is unlikely to change. It’s a pity, but I do understand. The real way forward would be to have Intel open its hand or to have AMD up their game on the software side with BLIS/FLAME. It would be great to have BLIS.jl working with libblastrampoline, though. I think @viralbshah looked into that at some point.

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [November 15, 2021, 7:43pm UTC](https://discourse.julialang.org/t/linking-to-mkl-2019-with-amd-cpus/71508/12 "2021-11-15T19:43:27Z")

</div>

I mean, if you want to use `MKL_jll.jl` 2019 and you’re ok with messing with a `dev`’ed `MKL.jl` (which you’re already doing) you have also to remove this line:  
[https://github.com/JuliaLinearAlgebra/MKL.jl/blob/238a4bb8d65037657d1e697f14655834249f309d/src/MKL.jl#L41](https://github.com/JuliaLinearAlgebra/MKL.jl/blob/238a4bb8d65037657d1e697f14655834249f309d/src/MKL.jl#L41)  
for your system (`x86_64`) `MKL_jll.is_available()` would be `true` anyway. I thought that was clear, but probably not.

---

<div class="post-metadata">

**Author:** ![pablosanjose](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pablosanjose/32/7006_2.png) [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)\
**Post date:** [November 15, 2021, 8:47pm UTC](https://discourse.julialang.org/t/linking-to-mkl-2019-with-amd-cpus/71508/13 "2021-11-15T20:47:59Z")

</div>

I’m afraid that doesn’t seem to be enough. `] build MKL` gets stuck at

```julia
(@v1.7) pkg> build MKL
    Building MKL → `~/.julia/dev/MKL/deps/build.log`
┌ Warning: Could not use exact versions of packages in manifest, re-resolving
└ @ Pkg.Operations /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.7/Pkg/src/Operations.jl:1488

```

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [November 15, 2021, 9:11pm UTC](https://discourse.julialang.org/t/linking-to-mkl-2019-with-amd-cpus/71508/14 "2021-11-15T21:11:12Z")

</div>

I don’t see any errors? Also, in Julia v1.7 building `MKL.jl` doesn’t do much:  
[https://github.com/JuliaLinearAlgebra/MKL.jl/blob/238a4bb8d65037657d1e697f14655834249f309d/deps/build.jl#L3-L5](https://github.com/JuliaLinearAlgebra/MKL.jl/blob/238a4bb8d65037657d1e697f14655834249f309d/deps/build.jl#L3-L5)  
so I’m not sure what you’re expecting exactly.

---

<div class="post-metadata">

**Author:** ![pablosanjose](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pablosanjose/32/7006_2.png) [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)\
**Post date:** [November 15, 2021, 10:02pm UTC](https://discourse.julialang.org/t/linking-to-mkl-2019-with-amd-cpus/71508/15 "2021-11-15T22:02:20Z")

</div>

Well, a `dev`ed MKL.jl does neither `precompile` nor `build` after the recommended changes. It’s not that it gives me a simple warning and finish when I try to build. It just hangs. If I try `using MKL` without building, it tries to precompile but never finishes either, and actually the REPL crashes if I try to ^C out of precompilation.

Since there is no error, I don’t know what to try next… Thanks in advance for any further ideas!

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [November 15, 2021, 10:10pm UTC](https://discourse.julialang.org/t/linking-to-mkl-2019-with-amd-cpus/71508/16 "2021-11-15T22:10:10Z")

</div>

I don’t know, that package is so old that it isn’t even worth the effort trying to make it work if it doesn’t.

As a completely different approach, you can un`dev` `MKL.jl`, install `MKL_jll.jl` 2021 regularly and override its artifact, to point to the directory where the artifact for `MKL_jll` 2019 is: [JLL packages · BinaryBuilder.jl](https://docs.binarybuilder.org/stable/jll/#Non-dev'ed-JLL-packages)

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [December 9, 2021, 5:03pm UTC](https://discourse.julialang.org/t/linking-to-mkl-2019-with-amd-cpus/71508/17 "2021-12-09T17:03:43Z")

</div>

> [@pablosanjose](#):
>
> That loophole was unfortunately closed by Intel with the 2020 version. It was argued that the reason was that they were adding actual support for AMD.

Have a look at [COSMA : Using MKL - Durham University](https://www.dur.ac.uk/icc/cosma/support/cosma8/mkl/)

---

<div class="post-metadata">

**Author:** ![pablosanjose](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pablosanjose/32/7006_2.png) [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)\
**Post date:** [December 9, 2021, 5:20pm UTC](https://discourse.julialang.org/t/linking-to-mkl-2019-with-amd-cpus/71508/18 "2021-12-09T17:20:12Z")

</div>

Thanks!
