With a lot of insight from gtrfxdso, I went down the rabbit hole of trying to get Matlab to work. I originally posted this in the old forum but I think it would probably be useful to have here so we can continue discussions and development on it, so I copied and updated it a bit for clarity.
A few notes first
Here's a the issues I've found that I haven't figure out how to resolve. I welcome any comments/suggestions.
Two Quick Notes
This will allow Matlab to launch and give you a lot of functionality, but not everything (no real "math functions" that require the MKL)
This will give you most of the remaining functionality as we are providing Matlab with some AMD compatible libraries for those functions.
Things I've changed in these instructions since originally posting them
A few notes first
- This solution is a bit messy but it seems to solve most issues that I've seen.
- I have tested this on 2020a (current release as of writing) and 2019b. The same instructions work for both.
- In my testing, this solution does survive incremental updates (from 2020a update 4 to 2020a update 5 for example) but if you do a major version change (from 2019b to 2020a for example) you will likely have to redo it, assuming that it will even work on the new version.
- I am happy to receive any comments and criticism. If you have any ideas to improve it or if you find any issues, please post a reply!
- Swap the libiomp5.dylib
- Download and compile openBLAS with the AMD ZEN flag (TARGET=ZEN, which the OpenBLAS developers note is pretty much the same as the Haswell optimization)
- Swap the compiled dylib with the default mkl.dylib in MATLAB/sys/os/maci64
- Modify the blas.spec and lapack.spec files to allow it to recognize an AMD processors instead of Intel
- Install gcc7 and change its link location in /usr/local/opt
- The install installs gcc7 to gcc@7 and openBLAS looks for it in gcc not gcc@7. I don't like this manually renaming because then you can't have newer gcc versions there but I don't have a better solution right now.
Here's a the issues I've found that I haven't figure out how to resolve. I welcome any comments/suggestions.
- I sometimes get an error that says
Cannot untransform a point, matrix may be invalid or singular
. It seems to when using math functions with super small numbers and in some GUI functions. - Some graphics libraries cause Matlab to crash. Seems there's some incompatibilty with the LAPCK portion of OpenBLAS. Ex: using "surf" and then trying to move the plot around.
- Potential Workaround: If you don't modify the lapack.spec file, Matlab will just spit out a bunch of warnings (stating that it can't find the mllapack.dylib) instead of fully crashing. These can be supressed with the command
warning('off')
. However certain functions (ex: imfilter) won't work at all.
- Potential Workaround: If you don't modify the lapack.spec file, Matlab will just spit out a bunch of warnings (stating that it can't find the mllapack.dylib) instead of fully crashing. These can be supressed with the command
Two Quick Notes
- The required precompiled libraries are in the attached zip.
- I use "(MATLAB)" in a few places below. This is a generic placeholder for the location of your Matlab installation. This will likely be "/Applications/MATLAB_R2020a" or "/Applications/MATLAB_R2019b" (depending on what Matlab version you have)
This will allow Matlab to launch and give you a lot of functionality, but not everything (no real "math functions" that require the MKL)
- Open the "(MATLAB)/sys/os/maci64" (to get here right click on the application and click "show contents" and then navigate to this folder)
- Rename "libiomp5.dylib" to "libiomp5.dylib.bak"
- Copy the included "libiomp5.dylib" to the same location
This will give you most of the remaining functionality as we are providing Matlab with some AMD compatible libraries for those functions.
- Install homebrew (See https://brew.sh/for installation details).
- This makes installing the required gcc 7 easier.
- You can start this and then do 2-3 below while it runs in the background.
- Note: it will also install the Xcode Command Line Tools, if you don't already have it.
- Add the AMD compatible OpenBLAS library (note: the included library is OpenBLAS v0.3.9)
- Navigate to "(MATLAB)/bin/maci64"
- Rename "mkl.dylib" that is already there to "mkl.dylib.bak"
- Copy the included "mkl.dylib" to the same location
- Tell Matlab to use the OpenBLAS library when it finds an AMD based system (instead of the default mkl.dylib, which is Intel only)
- Navigate to "(MATLAB)/bin/maci64" (same folder as above, so you can just stay there)
- Open the files "blas.spec" and "lapack.spec" in TextEdit (or your preferred text editor)
- Change
GenuineIntel
toAuthenticAMD
in both files- This tells Matlab what to do when it encounters an AMD processor (as it currently only knows how to handle Intel).
- Install gcc 7 (required by OpenBLAS)
- Once homebrew is finished installing (from step 1), in a terminal window (which you probably have open from installing homebrew) and type the command "brew install gcc@7" to install gcc version 7
- Go to /usr/local/opt (this is a system folder, not inside of the Matlab installation, so it's hidden and so I'd recommend you use Finder's "Go to Folder" command to get there)
- Rename the "gcc@7" folder there to "gcc".
- This "folder" is actually just a link to the actual location gcc 7 was installed in but OpenBLAS looks in "/usr/local/opt/gcc" instead of "/usr/local/opt/gcc@7" for the gcc 7 library it needs so we need to rename it.
Things I've changed in these instructions since originally posting them
- 1 Sept 2020: Modified the instructions and ZIP a bit to just replace the default (Intel) MKL entirely instead of having them both be present.
- I originally had you just copy the libopenblas.dylib library (what the compiler names it by default) and add lines to the .spec files to point to it but it seems some functions reference mkl.dylib directly (I assume those that aren't actually blas or lapack functions but do reference the mkl library), so this was not sufficient.
Attachments
Last edited: