-
Couldn't load subscription status.
- Fork 146
Fix MKL BLAS detection with renamed libiomp5md.lib #1667
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
Conversation
It seems that libiomp5.lib has been renamed to libiomp5md.lib, so the detection was failing. Add another search step with the new library name. TODO: is there a more modern approach? Co-authored-by: Luciano Paz <luciano.paz.neuro@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes MKL BLAS detection by adding support for a renamed Intel OpenMP library. Intel has renamed libiomp5.lib to libiomp5md.lib, causing the existing MKL detection to fail.
- Adds a new fallback detection step for MKL with the renamed
iomp5mdlibrary - Updates comments to distinguish between the original and new detection attempts
- Maintains backward compatibility by keeping the original detection logic
|
@ricardoV94, I managed to do a debug session with @lucianopaz, so we came up with this workaround. If we get this in a release, then we expect to be able to make Windows builds again on conda-forge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm. Thanks @maresb
|
I managed to successfully cherry-pick this into the |
Can you get it to 2.35.0 (if it's not yet). That's the one we're trying against now |
|
Awesome work guys! Failing test is flaky and def shouldn't be related |
|
Would you guys mind leaving a short comment how you debugged this? Could be useful for future devs |
I meant to write v2.35.0, there's no Windows build for v2.34.0.
Ya, good call @ricardoV94. Also for myself one month from now. 😂 To debug, we used a Windows VM, and ran import logging
logger = logging.getLogger("pytensor.link.c.cmodule")
logger.setLevel(logging.DEBUG)
import pytensor
pytensor.config.blas__ldflagsThis produced output like >>> pytensor.config.blas__ldflags
DEBUG (pytensor.link.c.cmodule): Will search for BLAS libraries in the following directories:
C:\Users\Ben\micromamba\envs\pytensor-blas-test\Library\x86_64-w64-mingw32\sysroot\usr\lib
C:\Users\Ben\micromamba\envs\pytensor-blas-test\libs
C:\Users\Ben\micromamba\envs\pytensor-blas-test
C:\Users\Ben\micromamba\envs\pytensor-blas-test\Library\bin
C:\Users\Ben\micromamba\envs\pytensor-blas-test\Library\lib
DEBUG (pytensor.link.c.cmodule): Checking MKL flags with intel threading
INFO (pytensor.link.c.cmodule): g++ -march=native selected lines: ['C:/Users/Ben/micromamba/envs/pytensor-blas-test/Library/bin/../libexec/gcc/x86_64-w64-mingw32/14.3.0/cc1.exe -E -quiet -v -iprefix C:/Users/Ben/micromamba/envs/pytensor-blas-test/Library/bin/../lib/gcc/x86_64-w64-mingw32/14.3.0/ -isysroot C:/Users/Ben/micromamba/envs/pytensor-blas-test/Library/bin/../x86_64-w64-mingw32/sysroot -U_REENTRANT - -march=x86-64 -mmmx -mno-popcnt -msse -msse2 -msse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -mno-avx -mno-avx2 -mno-sse4a -mno-fma4 -mno-xop -mno-fma -mno-avx512f -mno-bmi -mno-bmi2 -mno-aes -mno-pclmul -mno-avx512vl -mno-avx512bw -mno-avx512dq -mno-avx512cd -mno-avx512vbmi -mno-avx512ifma -mno-avx512vpopcntdq -mno-avx512vbmi2 -mno-gfni -mno-vpclmulqdq -mno-avx512vnni -mno-avx512bitalg -mno-avx512bf16 -mno-avx512vp2intersect -mno-3dnow -mno-adx -mno-abm -mno-cldemote -mno-clflushopt -mno-clwb -mno-clzero -mcx16 -mno-enqcmd -mno-f16c -mno-fsgsbase -mfxsr -mno-hle -msahf -mno-lwp -mno-lzcnt -mno-movbe -mno-movdir64b -mno-movdiri -mno-mwaitx -mno-pconfig -mno-pku -mno-prfchw -mno-ptwrite -mno-rdpid -mno-rdrnd -mno-rdseed -mno-rtm -mno-serialize -mno-sgx -mno-sha -mno-shstk -mno-tbm -mno-tsxldtrk -mno-vaes -mno-waitpkg -mno-wbnoinvd -mno-xsave -mno-xsavec -mno-xsaveopt -mno-xsaves -mno-amx-tile -mno-amx-int8 -mno-amx-bf16 -mno-uintr -mno-hreset -mno-kl -mno-widekl -mno-avxvnni -mno-avx512fp16 -mno-avxifma -mno-avxvnniint8 -mno-avxneconvert -mno-cmpccxadd -mno-amx-fp16 -mno-prefetchi -mno-raoint -mno-amx-complex -mno-avxvnniint16 -mno-sm3 -mno-sha512 -mno-sm4 -mno-apxf -mno-usermsr --param l1-cache-size=32 --param l1-cache-line-size=64 --param l2-cache-size=16384 -mtune=generic -idirafter C:/Users/Ben/micromamba/envs/pytensor-blas-test/Library/include -dumpbase -']
INFO (pytensor.link.c.cmodule): g++ default lines: ['C:/Users/Ben/micromamba/envs/pytensor-blas-test/Library/bin/../libexec/gcc/x86_64-w64-mingw32/14.3.0/cc1.exe -E -quiet -v -iprefix C:/Users/Ben/micromamba/envs/pytensor-blas-test/Library/bin/../lib/gcc/x86_64-w64-mingw32/14.3.0/ -isysroot C:/Users/Ben/micromamba/envs/pytensor-blas-test/Library/bin/../x86_64-w64-mingw32/sysroot -U_REENTRANT - -mtune=generic -march=x86-64 -idirafter C:/Users/Ben/micromamba/envs/pytensor-blas-test/Library/include -dumpbase -']
INFO (pytensor.link.c.cmodule): g++ -march=native equivalent flags: ['-march=x86-64', '-mmmx', '-mno-popcnt', '-msse', '-msse2', '-msse3', '-mno-ssse3', '-mno-sse4.1', '-mno-sse4.2', '-mno-avx', '-mno-avx2', '-mno-sse4a', '-mno-fma4', '-mno-xop', '-mno-fma', '-mno-avx512f', '-mno-bmi', '-mno-bmi2', '-mno-aes', '-mno-pclmul', '-mno-avx512vl', '-mno-avx512bw', '-mno-avx512dq', '-mno-avx512cd', '-mno-avx512vbmi', '-mno-avx512ifma', '-mno-avx512vpopcntdq', '-mno-avx512vbmi2', '-mno-gfni', '-mno-vpclmulqdq', '-mno-avx512vnni', '-mno-avx512bitalg', '-mno-avx512bf16', '-mno-avx512vp2intersect', '-mno-3dnow', '-mno-adx', '-mno-abm', '-mno-cldemote', '-mno-clflushopt', '-mno-clwb', '-mno-clzero', '-mcx16', '-mno-enqcmd', '-mno-f16c', '-mno-fsgsbase', '-mfxsr', '-mno-hle', '-msahf', '-mno-lwp', '-mno-lzcnt', '-mno-movbe', '-mno-movdir64b', '-mno-movdiri', '-mno-mwaitx', '-mno-pconfig', '-mno-pku', '-mno-prfchw', '-mno-ptwrite', '-mno-rdpid', '-mno-rdrnd', '-mno-rdseed', '-mno-rtm', '-mno-serialize', '-mno-sgx', '-mno-sha', '-mno-shstk', '-mno-tbm', '-mno-tsxldtrk', '-mno-vaes', '-mno-waitpkg', '-mno-wbnoinvd', '-mno-xsave', '-mno-xsavec', '-mno-xsaveopt', '-mno-xsaves', '-mno-amx-tile', '-mno-amx-int8', '-mno-amx-bf16', '-mno-uintr', '-mno-hreset', '-mno-kl', '-mno-widekl', '-mno-avxvnni', '-mno-avx512fp16', '-mno-avxifma', '-mno-avxvnniint8', '-mno-avxneconvert', '-mno-cmpccxadd', '-mno-amx-fp16', '-mno-prefetchi', '-mno-raoint', '-mno-amx-complex', '-mno-avxvnniint16', '-mno-sm3', '-mno-sha512', '-mno-sm4', '-mno-apxf', '-mno-usermsr', '--param', 'l1-cache-size=32', '--param', 'l1-cache-line-size=64', '--param', 'l2-cache-size=16384', '-mtune=generic']
DEBUG (pytensor.link.c.cmodule): Compiling for 64 bit architecture
DEBUG (pytensor.link.c.cmodule): Compiling for 64 bit architecture
DEBUG (pytensor.link.c.cmodule): try_blas_flags of flags: ['-L"C:\\Users\\Ben\\micromamba\\envs\\pytensor-blas-test\\Library\\bin"', '-lmkl_core', '-lmkl_rt', '-lmkl_intel_thread', '-liomp5', '-lpthread', '-Wl,-rpath,C:\\Users\\Ben\\micromamba\\envs\\pytensor-blas-test\\libs']
failed with error message b'C:/Users/Ben/micromamba/envs/pytensor-blas-test/Library/bin/../lib/gcc/x86_64-w64-mingw32/14.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -liomp5: No such file or directory\r\ncollect2.exe: error: ld returned 1 exit status\n'
DEBUG (pytensor.link.c.cmodule): Supplied flags '' failed to compile
DEBUG (pytensor.link.c.cmodule): Supplied flags ['-L"C:\\Users\\Ben\\micromamba\\envs\\pytensor-blas-test\\Library\\bin"', '-lmkl_core', '-lmkl_rt', '-lmkl_intel_thread', '-liomp5', '-lpthread', '-Wl,-rpath,C:\\Users\\Ben\\micromamba\\envs\\pytensor-blas-test\\libs'] failed to compile
DEBUG (pytensor.link.c.cmodule): Checking MKL flags with GNU OpenMP threading
DEBUG (pytensor.link.c.cmodule): Required file 'mkl_gnu_thread' not found
DEBUG (pytensor.link.c.cmodule): Required file mkl_gnu_thread not found
DEBUG (pytensor.link.c.cmodule): Checking Accelerate framework
DEBUG (pytensor.link.c.cmodule): Compiling for 64 bit architecture
DEBUG (pytensor.link.c.cmodule): try_blas_flags of flags: ['-framework', 'Accelerate', '-Wl,-rpath,C:\\Users\\Ben\\micromamba\\envs\\pytensor-blas-test\\libs']
failed with error message b"g++.EXE: error: unrecognized command-line option '-framework'\n"
DEBUG (pytensor.link.c.cmodule): Accelerate framework flag failed
DEBUG (pytensor.link.c.cmodule): Checking Lapack + blas
DEBUG (pytensor.link.c.cmodule): Compiling for 64 bit architecture
DEBUG (pytensor.link.c.cmodule): try_blas_flags of flags: ['-L"C:\\Users\\Ben\\micromamba\\envs\\pytensor-blas-test\\Library\\bin"', '-L"C:\\Users\\Ben\\micromamba\\envs\\pytensor-blas-test"', '-llapack', '-lblas', '-lcblas', '-lm', '-Wl,-rpath,C:\\Users\\Ben\\micromamba\\envs\\pytensor-blas-test\\libs']
failed with error message b'Mingw-w64 runtime failure:\r\n32 bit pseudo relocation at 00007FF6E32314BC out of range, targeting 00007FF985A31600, yielding the value 00000002A2800140.\r\n'
DEBUG (pytensor.link.c.cmodule): Supplied flags '' failed to compile
DEBUG (pytensor.link.c.cmodule): Supplied flags ['-L"C:\\Users\\Ben\\micromamba\\envs\\pytensor-blas-test\\Library\\bin"', '-L"C:\\Users\\Ben\\micromamba\\envs\\pytensor-blas-test"', '-llapack', '-lblas', '-lcblas', '-lm', '-Wl,-rpath,C:\\Users\\Ben\\micromamba\\envs\\pytensor-blas-test\\libs'] failed to compile
DEBUG (pytensor.link.c.cmodule): Checking blas alone
DEBUG (pytensor.link.c.cmodule): Compiling for 64 bit architecture
DEBUG (pytensor.link.c.cmodule): try_blas_flags of flags: ['-L"C:\\Users\\Ben\\micromamba\\envs\\pytensor-blas-test\\Library\\bin"', '-lblas', '-lcblas', '-Wl,-rpath,C:\\Users\\Ben\\micromamba\\envs\\pytensor-blas-test\\libs']
failed with error message b'Mingw-w64 runtime failure:\r\n32 bit pseudo relocation at 00007FF7A52314BC out of range, targeting 00007FF985A31600, yielding the value 00000001E0800140.\r\n'
DEBUG (pytensor.link.c.cmodule): Supplied flags '' failed to compile
DEBUG (pytensor.link.c.cmodule): Supplied flags ['-L"C:\\Users\\Ben\\micromamba\\envs\\pytensor-blas-test\\Library\\bin"', '-lblas', '-lcblas', '-Wl,-rpath,C:\\Users\\Ben\\micromamba\\envs\\pytensor-blas-test\\libs'] failed to compile
DEBUG (pytensor.link.c.cmodule): Checking openblas
DEBUG (pytensor.link.c.cmodule): Required file 'openblas' not found
DEBUG (pytensor.link.c.cmodule): Required file openblas not found
DEBUG (pytensor.link.c.cmodule): Failed to identify blas ldflags. Will leave them empty.
C:\Users\Ben\micromamba\envs\pytensor-blas-test\Lib\site-packages\pytensor\link\c\cmodule.py:2968: UserWarning: PyTensor could not link to a BLAS installation. Operations that might benefit from BLAS will be severely degraded.
This usually happens when PyTensor is installed via pip. We recommend it be installed via conda/mamba/pixi instead.
Alternatively, you can use an experimental backend such as Numba or JAX that perform their own BLAS optimizations, by setting `pytensor.config.mode == 'NUMBA'` or passing `mode='NUMBA'` when compiling a PyTensor function.
For more options and details see https://pytensor.readthedocs.io/en/latest/troubleshooting.html#how-do-i-configure-test-my-blas-library
warnings.warn(
''The key message here is: DEBUG (pytensor.link.c.cmodule): try_blas_flags of flags: ['-L"C:\\Users\\Ben\\micromamba\\envs\\pytensor-blas-test\\Library\\bin"', '-lmkl_core', '-lmkl_rt', '-lmkl_intel_thread', '-liomp5', '-lpthread', '-Wl,-rpath,C:\\Users\\Ben\\micromamba\\envs\\pytensor-blas-test\\libs']
failed with error message b'C:/Users/Ben/micromamba/envs/pytensor-blas-test/Library/bin/../lib/gcc/x86_64-w64-mingw32/14.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -liomp5: No such file or directory\r\ncollect2.exe: error: ld returned 1 exit status\n'indicating that it can't find (base) C:\Users\Ben\micromamba\envs\pytensor-blas-test\Library\lib>dir
Datenträger in Laufwerk C: ist Windows
Volumeseriennummer: 2A9B-C2DD
Verzeichnis von C:\Users\Ben\micromamba\envs\pytensor-blas-test\Library\lib
13.09.2025 11:21 <DIR> .
13.09.2025 11:21 <DIR> ..
13.09.2025 11:21 2.486 -gdb.py
13.09.2025 11:20 <DIR> bfd-plugins
09.09.2025 19:03 6.328 bzip2.lib
09.09.2025 19:03 102.272 bzip2_static.lib
11.08.2025 12:45 2.810 charset.lib
13.09.2025 11:20 <DIR> clang
13.09.2025 11:20 <DIR> cmake
13.09.2025 11:20 <DIR> dde1.4
31.03.2025 17:25 10.772 ffi.lib
13.09.2025 11:20 <DIR> gcc
11.09.2025 22:56 71.844 hwloc.lib
11.08.2025 12:45 3.480 iconv.lib
13.09.2025 11:20 <DIR> itcl4.2.3
09.07.2025 05:48 1.532.048 libbfd.a
09.09.2025 19:03 6.328 libbz2.lib
09.09.2025 19:03 102.272 libbz2_static.lib
06.08.2025 10:06 1.377.216 libcrypto.lib
09.07.2025 05:48 241.742 libctf-nobfd.a
09.07.2025 05:48 247.914 libctf.a
31.03.2025 17:25 10.772 libffi.lib
25.08.2025 20:02 182.330 libiomp5md.lib
25.08.2025 20:00 182.330 libomp.lib
09.07.2025 05:48 867.254 libopcodes.a
09.07.2025 05:48 20.538 libsframe.a
06.08.2025 10:06 147.386 libssl.lib
30.08.2024 12:09 83.702 mkl_blacs_ilp64_dll.lib
30.08.2024 12:09 83.184 mkl_blacs_lp64_dll.lib
30.08.2024 12:09 7.626 mkl_cdft_core_dll.lib
30.08.2024 12:09 3.270.402 mkl_core_dll.lib
30.08.2024 12:09 36.841.216 mkl_intel_ilp64_dll.lib
30.08.2024 12:09 40.280.554 mkl_intel_lp64_dll.lib
30.08.2024 12:09 1.663.392 mkl_intel_thread_dll.lib
30.08.2024 12:09 1.647.772 mkl_pgi_thread_dll.lib
30.08.2024 12:09 11.081.388 mkl_rt.lib
30.08.2024 12:09 638.248 mkl_scalapack_ilp64_dll.lib
30.08.2024 12:09 634.670 mkl_scalapack_lp64_dll.lib
30.08.2024 12:09 1.650.370 mkl_sequential_dll.lib
30.08.2024 12:09 1.650.370 mkl_tbb_thread_dll.lib
13.09.2025 11:20 <DIR> nmake
13.09.2025 11:20 <DIR> pkgconfig
13.09.2025 11:20 <DIR> reg1.3
13.09.2025 11:20 <DIR> sqlite3.40.0
31.07.2025 09:57 81.676 sqlite3.lib
13.09.2025 11:20 <DIR> tcl8
13.09.2025 11:20 <DIR> tcl8.6
28.05.2025 01:13 185.936 tcl86t.lib
13.09.2025 11:20 8.009 tclConfig.sh
06.06.2022 17:58 773 tclooConfig.sh
28.05.2025 01:13 10.100 tclstub86.lib
13.09.2025 11:20 <DIR> tdbc1.1.5
13.09.2025 11:20 <DIR> tdbcmysql1.1.5
13.09.2025 11:20 <DIR> tdbcodbc1.1.5
13.09.2025 11:20 <DIR> tdbcpostgres1.1.5
13.09.2025 11:20 <DIR> tdbcsqlite31.1.5
13.09.2025 11:20 <DIR> tk8.6
28.05.2025 01:15 125.062 tk86t.lib
28.05.2025 01:15 8.298 tkstub86.lib
39 Datei(en), 105.070.870 Bytes
20 Verzeichnis(se), 29.540.212.736 Bytes freiHere we observe that the library file is now called To maintain backwards compatibility, one possibility is to intelligently try and discover the name ourselves. But we decided to keep the fix super simple and just add another try-except. |
|
Nice. And how did you get a hold of a Windows VM? |
|
@lucianopaz, I just tried on the VM with an older environment I set up. I see the same error on the MKL detection, but then later it succeeds on the OpenBLAS detection, perhaps mistaking MKL as OpenBLAS? https://conda-metadata-app.streamlit.app/Search_by_file_path |
I don’t know, but I’ve seen some libraries add symbolic links from standard libblas, liblapack, and the standard stack library names, pointing to their specific libraries. I’ve seen this with Mac and vecLib.dylib. Maybe it happened as well here? As far as I can tell libblas and the rest are not in the folder you searched, so the linker must have found them in another standard library directory |
|
Sorry, my last message was a bit off. To be clear, it looks like The actual new error seems to be:
This comes from "Checking Lapack + blas" and "Checking blas alone": DEBUG (pytensor.link.c.cmodule): Checking Lapack + blas
DEBUG (pytensor.link.c.cmodule): Compiling for 64 bit architecture
DEBUG (pytensor.link.c.cmodule): try_blas_flags of flags: ['-L"C:\\Users\\Ben\\micromamba\\envs\\pytensor-blas-test\\Library\\bin"', '-L"C:\\Users\\Ben\\micromamba\\envs\\pytensor-blas-test"', '-llapack', '-lblas', '-lcblas', '-lm', '-Wl,-rpath,C:\\Users\\Ben\\micromamba\\envs\\pytensor-blas-test\\libs']
failed with error message b'Mingw-w64 runtime failure:\r\n32 bit pseudo relocation at 00007FF6E32314BC out of range, targeting 00007FF985A31600, yielding the value 00000002A2800140.\r\n'
DEBUG (pytensor.link.c.cmodule): Supplied flags '' failed to compile
DEBUG (pytensor.link.c.cmodule): Supplied flags ['-L"C:\\Users\\Ben\\micromamba\\envs\\pytensor-blas-test\\Library\\bin"', '-L"C:\\Users\\Ben\\micromamba\\envs\\pytensor-blas-test"', '-llapack', '-lblas', '-lcblas', '-lm', '-Wl,-rpath,C:\\Users\\Ben\\micromamba\\envs\\pytensor-blas-test\\libs'] failed to compile
DEBUG (pytensor.link.c.cmodule): Checking blas alone
DEBUG (pytensor.link.c.cmodule): Compiling for 64 bit architecture
DEBUG (pytensor.link.c.cmodule): try_blas_flags of flags: ['-L"C:\\Users\\Ben\\micromamba\\envs\\pytensor-blas-test\\Library\\bin"', '-lblas', '-lcblas', '-Wl,-rpath,C:\\Users\\Ben\\micromamba\\envs\\pytensor-blas-test\\libs']
failed with error message b'Mingw-w64 runtime failure:\r\n32 bit pseudo relocation at 00007FF7A52314BC out of range, targeting 00007FF985A31600, yielding the value 00000001E0800140.\r\n'
DEBUG (pytensor.link.c.cmodule): Supplied flags '' failed to compile
DEBUG (pytensor.link.c.cmodule): Supplied flags ['-L"C:\\Users\\Ben\\micromamba\\envs\\pytensor-blas-test\\Library\\bin"', '-lblas', '-lcblas', '-Wl,-rpath,C:\\Users\\Ben\\micromamba\\envs\\pytensor-blas-test\\libs'] failed to compile |
|
I opened #1695 as a fresh issue. |
Description
It seems that libiomp5.lib has been renamed to libiomp5md.lib, so the detection was failing. Add another search step with the new library name.
TODO: is there a more modern approach?
Related Issue
Checklist
Type of change
📚 Documentation preview 📚: https://pytensor--1667.org.readthedocs.build/en/1667/