mkl compatible with pytorch

20 visualizaciones (últimos 30 días)
Mehdi Koochak
Mehdi Koochak el 6 de Jul. de 2022
Respondida: Abhas el 28 de Oct. de 2024 a las 9:34
I'm trying to use build a mex function in cpp which use pytorch for doing some matrix multiplication, all part of converting an arry to torch tensor works fine. But when try to multiply two torch tensors matlab carshes and from trace I get that's because of different mkl.so that pytorch and matlab are using.
how Can I either change the matlab mkl to compatible with pytorch or vice versa.
I've no problem with building pytorch from source.
Thanks in advance
Mehdi
  2 comentarios
Oliver Malki
Oliver Malki el 21 de Jul. de 2022
Hi Mehdi,
we are somehow facing the same issues with LibTorch <=> MATLAB DLLs.
For us it works, when we start MATLAB from a command line, where we have already set the correct environment variables. Under Windows this means to set "SET PATH=%MY_WAY_TO_LIBTORCH%;%PATH%". Under Linux you can additionally set the LD_PRELOAD environment variable to enforce loading a specific DLL.
Oliver
Surya
Surya el 20 de Mzo. de 2023
Hi,
To make Matlab use a specific version of MKL, you can set the environment variable MKLROOT to the path of the desired MKL version before starting Matlab. For example, if you want Matlab to use the MKL version installed with PyTorch, you can set MKLROOT to the path of the PyTorch installation directory (e.g., /path/to/pytorch/lib).
Alternatively, you can try using the MKL-DNN library instead of MKL for PyTorch, as it is designed to be compatible with different versions of MKL used by other applications. You can build PyTorch with MKL-DNN support by specifying the USE_MKLDNN flag during the build process.

Iniciar sesión para comentar.

Respuestas (1)

Abhas
Abhas el 28 de Oct. de 2024 a las 9:34
To resolve the compatibility issue between MATLAB and PyTorch due to different versions of the MKL library you can follow the below steps:
  • Set MKLROOT for MATLAB: You can try setting the "MKLROOT" environment variable to point to the MKL version that PyTorch uses. This might help MATLAB to pick up the same version. You can do this by exporting the MKLROOT path in your shell before starting MATLAB. For example:
export MKLROOT=/path/to/pytorch/lib
matlab
  • Build PyTorch with MKL-DNN: Alternatively, you can build PyTorch with MKL-DNN (now known as oneDNN), which is designed to be more flexible with different MKL versions. When building PyTorch from source, you can enable MKL-DNN by setting the "USE_MKLDNN" flag. Here’s a basic outline of how you might do this:
git clone --recursive https://github.com/pytorch/pytorch
cd pytorch
export USE_MKLDNN=1
python setup.py install
  • Ensure Consistent Environment: Make sure that any environment variables related to MKL (like "LD_LIBRARY_PATH" or "DYLD_LIBRARY_PATH" on macOS) are consistent across both MATLAB and your PyTorch environment.
You may refer to the below MathWorks documentation links that might be helpful for resolving the MKL compatibility issue:
  1. https://www.mathworks.com/help/matlab/external-language-interfaces.html
  2. https://www.mathworks.com/help/matlab/ref/setenv.html
I hope this helps!

Categorías

Más información sobre Python with MATLAB en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by