MATLAB Coder: How do I build the Intel MKL-DNN library for Deep Learning C++ code generation and deployment?

I see a few deep learning networks supported for code generation using MATLAB Coder:
I'm looking to generate code from my deep learning network (like AlexNet, GoogLeNet, ResNet, SqueezeNet, VGG-16/19, etc) to run on Intel CPUs using MATLAB Coder and the Intel MKL-DNN library. What are the steps to do this?

 Respuesta aceptada

Note: The following applies to R2021a and newer releases of MATLAB Coder and MKL-DNN v1.4 as described here. For older releases, see the next answer below.
Note: Intel recently renamed the library from MKL-DNN to oneDNN, so we use MKL-DNN and oneDNN interchangeably.
Background
To generate and run C++ code for Deep Learning, you must have the Intel Math Kernel Library for Deep Neural Networks (Intel MKL-DNN). Do not use a prebuilt library because some required files are missing. Instead, build the library from source code.
The following describes build instructions for MKL-DNN on Windows and Linux platforms.
To build the Intel MKL-DNN library from source code, you must have:
  • Operating system with Intel 64 architecture support
  • C++ compiler with C++11 standard support
  • CMake 2.8.11 or later version
Windows MKL-DNN build instructions
These MKL-DNN build steps have been validated by using Visual Studio 2017 version 15.0 on 64-bit Windows platform. If you want to use a newer version of Visual Studio to build a working MKL-DNN library, use it at your own discretion.
1. Download the MKL-DNN v1.4 source code from this link (https://github.com/oneapi-src/oneDNN/archive/v1.4.zip) and extract the source code. This action creates the folder oneDNN-1.4.
2. At the Windows command line, change the current directory to oneDNN-1.4. Generate a Microsoft Visual Studio solution “Intel(R) MKL-DNN.sln” by running these commands:
mkdir build
cd build
cmake -G "Visual Studio 15 2017 Win64" ..
3. Change the current directory to oneDNN-1.4\build. Run this command:
cmake --build . --config Release
This action creates these libraries in the folder oneDNN-1.4\build\src\Release:
  • dnnl.lib
  • dnnl.dll
Inside the folder C:\Program Files, create a folder named mkl-dnn. Then, inside the folder C:\Program Files\mkl-dnn, create a folder named lib. Copy the generated libraries to the folder C:\Program Files\mkl-dnn\lib.
On Windows operating systems, special characters and spaces are allowed in the path only if 8.3 file names are enabled. If they are not enabled, replace C:\Program Files\mkl-dnn\lib by a path that does not include spaces. For more information on 8.3 file names, refer to the Windows documentation.
Copy the include files from oneDNN-1.4\include and oneDNN-1.4\build\include to C:\Program Files\mkl-dnn\include.
4. Set the MATLAB environment variable INTEL_MKLDNN to C:\Program Files\mkl-dnn. At the MATLAB command prompt, enter:
setenv('INTEL_MKLDNN', 'C:\Program Files\mkl-dnn')
Add C:\Program Files\mkl-dnn\lib to the PATH variable by running:
setenv('PATH', [getenv('INTEL_MKLDNN') filesep 'lib' pathsep getenv('PATH')])
5. If you have not done so already, you must set the environment variable for Windows. At the Windows command line, enter:
set PATH=%PATH%; C:\Program Files\mkl-dnn\lib
Also, create and set the INTEL_MKLDNN environment variable in Windows that points to C:\Program Files\mkl-dnn.
Linux MKL-DNN build instructions
C++ Compiler requirements:
  • Install any one of the GNU compiler versions from GNU Compiler Collection. The versions include 4.8, 5.4, 6.1, 7.2, and 8.1.
1. Download the MKL-DNN v1.4 source code from this link (https://github.com/oneapi-src/oneDNN/archive/v1.4.tar.gz) and extract the source code by running this command at the Linux terminal:
tar -xvzf oneDNN-1.4.tar.gz
This action creates the folder oneDNN-1.4.
2. To generate the makefile for compilation, run these commands at the terminal from the oneDNN-1.4 folder:
mkdir -p build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
3. To build the library, run this command at the terminal from the oneDNN-1.4/build folder:
make -j
These commands creates these libraries in the folder oneDNN-1.4/build/src:
  • libdnnl.so
  • libdnnl.so.1
  • libdnnl.so.1.4
Copy these libraries to /usr/local/mkl-dnn/lib.
Copy the include files from oneDNN-1.4/include and oneDNN-1.4/build/include to /usr/local/mkl-dnn/include.
4. Set the MATLAB environment variable INTEL_MKLDNN to /usr/local/mkl-dnn. At the MATLAB command line, enter:
setenv('INTEL_MKLDNN', /usr/local/mkl-dnn')
5. Add /usr/local/mkl-dnn/lib to the PATH variable:
setenv('LD_LIBRARY_PATH', [getenv('INTEL_MKLDNN') filesep 'lib' pathsep getenv('LD_LIBRARY_PATH')]);
If you have not done so already, you must set the environment variables for Linux. Use Linux syntax at the Linux terminal to set the variable LD_LIBRARY_PATH to /usr/local/mkl-dnn/lib, and the environment variable INTEL_MKLDNN to /usr/local/mkl-dnn.
macOS MKL-DNN build instructions
C++ Compiler requirements:
1. Download the MKL-DNN v1.4 source code from this link (https://github.com/oneapi-src/oneDNN/archive/v1.4.tar.gz) and extract this source code by running this command at the terminal:
tar -xvzf oneDNN-1.4.tar
This action creates the folder oneDNN-1.4.
2. The macOS clang compiler does not ship with OpenMP. To get an OpenMP enabled mkldnn library, you must install brew and libomp:
a. Install home brew on host mac PC by running this command at the bash terminal
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
b. Install OpenMP by using brew with command:
$(BREW_INSTALL_PATH)/brew install libomp
3. To generate the makefile for compilation, run these commands at the terminal from the oneDNN-1.4 folder:
mkdir -p build
cd build
$(CMAKE_INSTALL_PATH)cmake .. -DOpenMP_CXX_FLAGS="-Xclang -fopenmp -I$(OMP_INSTALL_PATH)/include" -DOpenMP_C_FLAGS="-Xclang -fopenmp -I$(OMP_INSTALL_PATH)/include" -DOpenMP_CXX_LIB_NAMES=libomp -DOpenMP_C_LIB_NAMES=libomp -DOpenMP_libomp_LIBRARY=$(OMP_INSTALL_PATH)/lib/libomp.dylib -DCMAKE_SHARED_LINKER_FLAGS="-L$(OMP_INSTALL_PATH)/lib -lomp"
4. To build the library, run this command at the terminal from the oneDNN-1.4/build folder:
make -j
These commands create these libraries in the folder oneDNN-1.4/build/src:
  • libdnnl.dylib
  • libdnnl.1.dylib
  • libdnnl.1.4.dylib
Copy these libraries to /usr/local/mkl-dnn/lib.
Copy the include files from oneDNN-1.4/include to /usr/local/mkl-dnn/include.
5. Copy the OpenMP dependencies required by MKL-DNN:
  • OpenMP libraries from $(OMP_INSTALL_PATH)/lib to /usr/local/mkl-dnn/lib
  • OpenMP include files from $(OMP_INSTALL_PATH)/include to /usr/local/mkl-dnn/include
6. The OpenMP library path is hard bound to mkldnn library. To list this hard binding, run the below command:
otool -l libdnnl.dylib
7. This hard binding of the paths must be changed for portability to other mac machines. To do this, run:
install_name_tool -change /usr/local/opt/libomp/lib/libomp.dylib @rpath/libomp.dylib libdnnl.1.dylib
install_name_tool -id "@rpath/libomp.dylib" libomp.dylib
Changing to rpath enables portability of the mkldnn/OpenMP libraries to other mac machines. This avoids any runtime linking issues.
8. Set the MATLAB environment variable INTEL_MKLDNN to /usr/local/mkl-dnn. At the MATLAB command line, enter:
setenv('INTEL_MKLDNN', /usr/local/mkl-dnn')

11 comentarios

Hi,
I already downloaded Microsoft Visual C++ 14.0 (Visual Studio 2015 Update 3) and CMake but when I try to follow Windows MKL-DNN build instructions, already in the second step getting this error: CMake Error: The source directory "C:/Users/gulin/Desktop/VKA/oneDNN-1.4" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
How can I solve this problem?
Crosscheck if oneDNN folder is downloaded and extracted properly. Use the below command for doing the same.
Download the MKL-DNN v1.4 source code from this link (https://github.com/oneapi- src/oneDNN/archive/v1.4.zip) and extract the source code. This action creates the folder oneDNN-1.4.
I have seen CMakeLists.txt in the oneDNN-1.4 folder. This file can be seen as shown in below snapshot.
Make sure you are following the exact steps of running cmake. Create build directory and run cmake from build directory.
mkdir build
cd build
If you are not sure of the compiler/ visual studio you are using, Run
cmake ..
cmake --build . --config Release
If you are using "Visual Studio 15 2017 Win64" use,
cmake -G "Visual Studio 15 2017 Win64" ..
cmake --build . --config Release
Else, if you are using any other version such as "Visual Studio 16 2019" use,
cmake -G "Visual Studio 16 2019" ..
cmake --build . --config Release
I was able to reproduce the issue mentioned when i am running cmake without entering build directory.
Hi,Chou, Thanks for your anwser. However, I have some problems about it. I use MATLAB 2019b and download https://github.com/intel/mkl-dnn/archive/master.zip , But the first command could not run. It said that the ".\prepare_mkl.bat do not exsist".
And another question is, I installed MATLAB 2020b and 2019b both in my computer, I successfully run well in 2020b. Would that be a conflit of it?
Thank you
It seems you are facing issues while building the MKLDNN library for R2019b. We support MKLDNN library v0.14 in R2019b. Could you try downloading MKLDNN v0.14 from https://github.com/oneapi-src/oneDNN/tree/v0.14 instead of the master branch and follow the same build steps that are mentioned in the first answer by Chao.
Let me know if you face any problems while building the library.
Regarding "another question is, I installed MATLAB 2020b and 2019b both in my computer, I successfully run well in 2020b. Would that be a conflict of it?", please find my answer below:
No, Building the MKLDNN library is independent of the MATLAB version installed on your computer. But, We would suggest having one MKLDNN version library set in your windows environment and make sure that your environment is correct for the corresponding MATLAB version that you use.
Suppose if you use R2019b then set the environment variables for MKLDNN v0.14. If you use R2020b then set the environment variables for MKLDNN 1.0.
Let me know if you have any comments.
Hi Hari,
Thank you for your reply. For the first problem, I solve it for downlead v0.14. However, then I face the problem of cmake command do not exist. I wonder which cmake version you recommand(I installed the newest version).
Thanking you in advance.
Best regards,
Qiaohui
Could you try using Cmake 2.8.0 or later versions.
Hi Bill.
I followed your tutorial to complete all the operations,but there still have some errors.
and the p-code seems to be empty.....
Do you know why this happen?
By the way. At step4 and 5 the code seems not work,so I add the environment variable in system setting
Bill, this post is very important as without this trick nothing is working. please move it to a more accessable place or website. A string forwad link for this post would be very helpful as i and many others have to spend days digging a round fot the random compilation error that kept appearing
thanx
This was not expected from a company like MathWork, unfortunatley. Issues like these had to be much more simpler to be solved.
Hi,
Could you elaborate the issues that you are facing. Is this related to mkldnn mex codegen?
We simplified the workflow for mex codegen and you no longer have to download and build mkldnn for mex. We ship them along with MATLAB from R2020a .Codegen for mex should work out of the box
Thanks,
Praveen
I have an error
Code generation for FeatureInputLayer input is not supported for mkldnn target. See
documentation for a list of supported layers with each target.

Iniciar sesión para comentar.

Más respuestas (2)

Note: The following applies to R2018b, R2019a, and R2019b releases of MATLAB Coder and MKL-DNN v0.14 as described here. For newer releases, see the answer above and below.
Background
To generate and run C++ code for Deep Learning, you must have the Intel Math Kernel Library for Deep Neural Networks (Intel MKL-DNN). Do not use a prebuilt library because some required files are missing. Instead, build the library from source code.
The following describes build instructions for MKL-DNN on Windows and Linux platforms.
Windows MKL-DNN build instructions
To follow these instructions, obtain a recommended compiler and IDE:
  • Microsoft Visual Studio 2017
  • Intel C++ Compiler 18.0 from Intel Parallel Studio
These instructions assume the use of the Microsoft Visual Studio IDE and compiler. cmake is also required.
1. Download the MKL-DNN source code for version 0.14 (available at https://github.com/oneapi-src/oneDNN/archive/refs/tags/v0.14.zip) that is required by the MATLAB Coder release shown in the documentation (https://www.mathworks.com/help/releases/R2019b/coder/ug/prerequisites-for-deep-learning-with-matlab-coder.html).
2. Unzip the source code to a folder, MKLDNN. From the MKLDNN folder, from the Command Prompt, enter:
cd scripts
.\prepare_mkl.bat
cd ..
This creates these libraries at MKLDNN\external\mklml_win_*\lib:
  • libiomp5md.dll
  • libiomp5md.lib
  • mklml.dll
  • mklml.lib
3. Run these commands from the MKLDNN folder:
mkdir -p build
cd build
cmake -G “Visual Studio 15 2017 Win64” ..
This creates this Visual Studio solution file in /build:
  • Intel(R) MKL-DNN.sln
4. Open the solution file in Visual Studio. Set the Solution Configurations dropdown to Release. Click on Build > Build Solution. This creates these libraries in MKLDNN\build\src\Release:
  • mkldnn.dll
  • mkldnn.lib
Copy these libraries and the libraries generated in step 2 to C:\Program Files\mkl-dnn\lib.
Note that on Windows® operating systems, special characters and spaces are allowed in the path only if 8.3 file names are enabled. If they are not enabled, replace 'C:\Program Files\mkl-dnn\lib’ with a path that does not include a space. For more information on 8.3 file names, refer to the Windows documentation.
Copy the following files from MKLDNN\include to C:\Program Files\mkl-dnn\include:
  • mkldnn.h
  • mkldnn.hpp
  • mkldnn_debug.h
  • mkldnn_types.h
5. Set the MATLAB environmental variable INTEL_MKLDNN to C:\Program Files\mkl-dnn. From the MATLAB Command Window, enter:
setenv('INTEL_MKLDNN', 'C:\Program Files\mkl-dnn\')
Add C:\Program Files\mkl-dnn\lib to the PATH variable.
setenv('PATH', [getenv('INTEL_MKLDNN') filesep 'lib' pathsep getenv('PATH')])
6. If you have not done so already, you should also set the environment variable for Windows. From the Windows Command Prompt, enter:
set PATH=%PATH%; C:\Program Files\mkl-dnn\
Linux MKL-DNN build instructions
To follow these instructions, obtain a recommended compiler:
  • GNU g++ with C++11 support
cmake is also required.
1. Download the MKL-DNN source code for version 0.14 (available at https://github.com/oneapi-src/oneDNN/archive/refs/tags/v0.14.tar.gz) that is required by the MATLAB Coder release shown in the documentation (https://www.mathworks.com/help/releases/R2019b/coder/ug/prerequisites-for-deep-learning-with-matlab-coder.html).
2. Unzip the source code to a folder, MKLDNN. From the MKLDNN folder, from the Command Prompt, enter:
cd scripts
chmod +x prepare_mkl.sh
./prepare_mkl.sh
This creates these libraries at MKLDNN/external/mklml_lnx_*/lib:
libiomp5.so
libmklml_intel.so.
3. Run these commands from the MKLDNN folder:
mkdir -p build
cd build
cmake ..
make
4. This creates these libraries under MKLDNN/build/src:
  1. libmkldnn.so
  2. libmkldnn.so.0
  3. libmkldnn.so.0.14.0.
Copy these libraries and thelibraries generated in step 2 to /usr/local/mkl-dnn/lib.
Copy the following files from MKLDNN/include to /usr/local/mkl-dnn/include:
  • mkldnn.h
  • mkldnn.hpp
  • mkldnn_debug.h
  • mkldnn_types.h
5. Set the MATLAB environmental variable INTEL_MKLDNN to /usr/local/mkl-dnn. From the MATLAB Command Window, enter:
setenv('INTEL_MKLDNN', /usr/local/mkl-dnn')
Add /usr/local/mkl-dnn/lib to the PATH variable:
setenv('LD_LIBRARY_PATH', [getenv('INTEL_MKLDNN') filesep 'lib' pathsep getenv('LD_LIBRARY_PATH')]);
If you have not done so already, you should also set the environment variables for Linux. Use Linux syntax in the Linux terminal to set the variable LD_LIBRARY_PATH to /usr/local/mkl-dnn/lib, and the environment variable INTEL_MKLDNN to /usr/local/mkl-dnn.

21 comentarios

Hi, Bill
I believe your steps need to be updated, because the mkl-dnn library in the github is changed. I can not make it work by following your steps.
Thanks
Charlie
Hi Xiaoqi,
As per the R2019b pre-requisites documentation we use the mkldnn v0.14 . The above build steps will suffice for the mkldnn v0.14.
We will update the steps as you mentioned once we support latest mkldnn version.
Thank you,
Praveen.
I have such an error: Undefined function or variable 'IsAvx512Proc'.
I thought that if my Intel proc does not support Avx512 then it would just use Avx2. Does it make sense? Had someone try MKL-DNN with Intel i5-8265u?
Hi Sviatoslav,
We are sorry to hear that you are facing issues.
You are right that if Intel proc doesnot support Avx512 mkldnn should use Avx2.
And processor i5-8265u should be able to use mkldnn with out any issues.
There is a package installer issue from our end , where it didnot ship the 'IsAvx512Proc' method. Hence you are seeing this error . Could you let me know what is the MATLAB version you are using and did you do any recent upgrade to it.
Thank you,
Praveen.
Thank you for yout response.
Such issues were observed while using R2019a. I tried 2019b and it works there.
P.S. It would be nice if it would be possible to generate ScalingLayer using codegen. In addition, it would be nice if it would be possible to export TanhLayer and ScalingLayer to ONNX format.
Hi Sviatoslav,
Deep learning toolbox has a few scaling layer implementations. For instance , there is one implemented for inceptionV3 networks and there is a scaling layer for reinforcement learning toolbox. Can you clarify which one you are using ?
Note that codegen is supported for the scaling layer in inceptionV3 networks since 19a.
Thanks
Jaya
didn't work for me !
need help quick please
Hi ,
Error is not clear from this image. Could you share us Error report.
Could you also share the MATLAB release details and example link that you are trying out.
Thank you,
Praveen.
here is the report of the error in the attachment
i use Matlab R2019b
i also tried to this instructions to install mkl dnn
and your instruction but didn't work
i also tried all example in matlab website that related to YOLO code genrator.. all same error
all i want from this is to convert my code"which contain a yolo detector" to C so i can combine it with an android app.
The compilation errors are becuase of mkldnn.hpp file not found.
" c:\users\witch\documents\matlab\examples\r2019b\deeplearning_shared\yolov2objectdetectionusingintelmkldnnexample\codegen\mex\yolov2_detection\MWCNNLayerImpl.hpp(10): fatal error C1083: Cannot open include file: 'mkldnn.hpp': No such file or directory
"
Could you check if you setup the INTEL_MKLDNN path correctly as mentioned in step -
setenv('INTEL_MKLDNN', 'C:\Program Files\mkl-dnn\')
Also could you make sure that there are no spaces in the folders
  1. Where you are trying codegen.
  2. Where MKLDNN libraries reside.
Thank you,
Praveen.
the file is already exist
and there is no space in both paths
I FIX this bug by move this file into project folder
but another error happend : fatal error LNK1181: cannot open input file 'lib\mkldnn.lib'
ninja: build stopped: subcommand failed.
my CPU is intel core i7 7th Gen 2.7 GHz
now this error
compilation aborted for MWElementwiseAffineLayer.cpp (code 4)
.....
catastrophic error: cannot open source file "mkldnn.hpp"
...
compilation aborted for MWExponentialLayer.cpp (code 4)
ninja: build stopped: subcommand failed.
We tried the same example and found the same log as yours if we donot set the INTEL_MKLDNN path.
Currently you are seeing the log similar to log present in withOutMKLDNNPath.txt where the INTEL_MKLDNN is not set in the MATLAB. If you set it appropriately you should see log similar to withMKLDNNPATH
Thank you,
Praveen.
now i had this error in the attachment using matlab R2019b
and this error using matlab R2019a
??? Error generating code for network yoloV2CatDetector_0. Code generation for
YOLOv2TransformLayer yolov2Transform is not supported for mkldnn target. See documentation
for a list of supported layers with each target.
i use mkldnn V0.14
i also installed minGW v17 which i belive it supports openMP
We donot support the yolov2 for R2019a release.
Regarding the errors in R2019b ,we are unable to reproduce .
It would be great if you could forward the steps that you have used for codegen. This will help us to corner out if there are any steps that are missed out.
Than kyou,
Praveen.
I think you need to set up the C++ compiler before you build. Please try mex -setup c++. The following link explains for more details.
I have generated a source code for deep learning and found a lot of files in codegen folder. How do I go about integrating it and compile it in Linux.Do I need to make changes to the main.cpp? Because I saw some instructions within the main file asking me to change variable size function argument.
Please see the updated instructions for MKL-DNN v1.0 below.

Iniciar sesión para comentar.

Note: The following applies to R2020a and R2020b releases of MATLAB Coder and MKL-DNN v1.0 as described here. For newer and older releases, see the other answer above.
Note: Intel recently renamed the library from MKL-DNN to oneDNN, so we use MKL-DNN and oneDNN interchangeably.
Background
To generate and run C++ code for Deep Learning, you must have the Intel Math Kernel Library for Deep Neural Networks (Intel MKL-DNN). Do not use a prebuilt library because some required files are missing. Instead, build the library from source code.
The following describes build instructions for MKL-DNN on Windows and Linux platforms.
To build the Intel MKL-DNN library from source code, you must have:
  • Operating system with Intel 64 architecture support
  • C++ compiler with C++11 standard support
  • CMake 2.8.11 or later version
Windows MKL-DNN build instructions
C++ Compiler requirements :
  • Microsoft Visual C++ 14.0 (Visual Studio 2015 Update 3)
  • If you face compilation errors while building MKL-DNN, please use MSVC Compiler version 19.16.xx or newer
1. Download the mkldnn v1.0 source code from the link (https://github.com/oneapi-src/oneDNN/archive/v1.0.zip) and extract the source code. This action creates the folder oneDNN-1.0.
2. Generate a Microsoft Visual Studio solution “Intel(R) MKL-DNN.sln” by running these commands in command line at oneDNN-1.0 folder:
mkdir build
cd build
cmake -G "Visual Studio 15 2017 Win64" ..
3. Run below command in command line at oneDNN-1.0\build folder:
cmake --build . --config Release
This action creates these libraries in the folder oneDNN-1.0\build\src\Release:
  • mkldnn.lib
  • mkldnn.dll
Copy these generated libraries to C:\Program Files\mkl-dnn\lib.
Note that on Windows operating systems, special characters and spaces are allowed in the path only if 8.3 file names are enabled. If they are not enabled, replace C:\Program Files\mkl-dnn\lib with a path that does not include a space. For more information on 8.3 file names, refer to the Windows documentation.
Copy the include files from oneDNN-1.0\include and oneDNN-1.0\build\include to C:\Program Files\mkl-dnn\include.
4. Set the MATLAB environment variable INTEL_MKLDNN to C:\Program Files\mkl-dnn. At the MATLAB command prompt, enter:
setenv('INTEL_MKLDNN', 'C:\Program Files\mkl-dnn')
Add C:\Program Files\mkl-dnn\lib to the PATH variable.
setenv('PATH', [getenv('INTEL_MKLDNN') filesep 'lib' pathsep getenv('PATH')])
5. If you have not done so already, you must set the environment variable for Windows. At the Windows Command Prompt, enter:
set PATH=%PATH%; C:\Program Files\mkl-dnn\lib
Also create and set the INTEL_MKLDNN environment variable in windows that point to C:\Program Files\mkl-dnn
Linux MKL-DNN build instructions
C++ Compiler requirements :
  • Install any one of the GNU compiler versions from GNU Compiler Collection 4.8, 5.4, 6.1, 7.2, and 8.1
1. Download the mkldnn v1.0 source code from the link (https://github.com/oneapi-src/oneDNN/archive/v1.0.tar.gz) and extract source code by running this command at the terminal:
tar -xvzf oneDNN-1.0.tar.gz
This action creates the folder oneDNN-1.0.
2. To generate the makefile for compilation, run these commands at the terminal from the oneDNN-1.0 folder:
mkdir -p build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
3. To build the library, run this command at the terminal from the oneDNN-1.0/build folder:
make -j
These commands creates these libraries in the folder oneDNN-1.0/build/src:
  • libmkldnn.so
  • libmkldnn.so.0
  • libmkldnn.so.1.0.0.0
Copy these libraries to /usr/local/mkl-dnn/lib.
Copy the include files from oneDNN-1.0/include and oneDNN-1.0/build/include to /usr/local/mkl-dnn/include.
4. Set the MATLAB environment variable INTEL_MKLDNN to /usr/local/mkl-dnn. At the MATLAB command prompt, enter:
setenv('INTEL_MKLDNN', /usr/local/mkl-dnn')
5. Add /usr/local/mkl-dnn/lib to the PATH variable:
setenv('LD_LIBRARY_PATH', [getenv('INTEL_MKLDNN') filesep 'lib' pathsep getenv('LD_LIBRARY_PATH')]);
If you have not done so already, you must set the environment variables for Linux. Use Linux syntax in the Linux terminal to set the variable LD_LIBRARY_PATH to /usr/local/mkl-dnn/lib, and the environment variable INTEL_MKLDNN to /usr/local/mkl-dnn.
macOS MKL-DNN build instructions (for R2020b and newer)
C++ Compiler requirements:
  • Install supported Xcode versions mentioned in https://www.mathworks.com/support/requirements/supported-compilers.html
1. Download the mkldnn v1.0 source code from the link and extract source code by running this command at the terminal:
tar -xvzf mkl-dnn-1.0.tar.gz
This action creates the folder mkl-dnn-1.0.
2. macOS clang compiler does not ship with OpenMp. To have an OpenMp enabled mkldnn library, we need to install brew,libomp
a. Install home brew in host mac PC with below command using bash terminal
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
b. Install OpenMp using brew with command
$(BREW_INSTALL_PATH)/brew install libomp
3. To generate the makefile for compilation, run these commands in the terminal from the mkl-dnn-1.0 folder:
mkdir -p build
cd build
$(CMAKE_INSTALL_PATH)cmake .. -DOpenMP_CXX_FLAGS="-Xclang -fopenmp -I$(OMP_INSTALL_PATH)/include" -DOpenMP_C_FLAGS="-Xclang -fopenmp -I$(OMP_INSTALL_PATH)/include" -DOpenMP_CXX_LIB_NAMES=libomp -DOpenMP_C_LIB_NAMES=libomp -DOpenMP_libomp_LIBRARY=$(OMP_INSTALL_PATH)/lib/libomp.dylib -DCMAKE_SHARED_LINKER_FLAGS="-L$(OMP_INSTALL_PATH)/lib -lomp"
These commands creates these libraries in the folder mkl-dnn-1.0/build/src:
  • libmkldnn.dylib
  • libmkldnn.0.dylib
  • libmkldnn.1.0.0.0.dylib
Copy these libraries to /usr/local/mkl-dnn/lib.
Copy the include files from mkld-dnn-1.0/include to /usr/local/mkl-dnn/include.
4. Copy the OpenMp dependencies required by mkldnn
  • OpenMP libraries from $(OMP_INSTALL_PATH)/lib to /usr/local/mkl-dnn/lib
  • OpenMP include files from $(OMP_INSTALL_PATH)/include to /usr/local/mkl-dnn/include
5. The OpenMp library path is hardbinded to mkldnn library. Below command would list out this aspect
otool -l libmkldnn.dylib
6. This hard binding of the paths must be changed for portability to other mac machines. Use the below command
install_name_tool -change /usr/local/opt/libomp/lib/libomp.dylib @rpath/libomp.dylib libmkldnn.0.dylib
install_name_tool -id "@rpath/libomp.dylib" libomp.dylib
Changing to rpath would enable portability of mkldnn/OpenMP libraries to different mac machines. This avoids any runtime linking issues.
7. Set the MATLAB environment variable INTEL_MKLDNN to /usr/local/mkl-dnn. At the MATLAB command prompt, enter:
setenv('INTEL_MKLDNN', /usr/local/mkl-dnn')

9 comentarios

Hello, Bill Chou,
I am using the matlab 2020b, and I just installed the Visual Studio 2019 and Intel Parallel Studio XE.
With in the folder of oneDNN-1.0, when I run the commands, the "cmake" cannot be found, so I cannot start your process at all. What should I do?
mkdir build
cd build
cmake -G "Visual Studio 15 2017 Win64" ..
Thank you very much!
Hi JJ,
cmake needs to be run as a system command. Please run the cmake commands from your Windows terminal instead of running them within MATLAB.
Jaya
Is there a mistake? In C++ Compiler requirements you specified "Microsoft Visual C++ 14.0 (Visual Studio 2015 Update 3)", but in step two you wrote "cmake -G "Visual Studio 15 2017 Win64" ..".
Should be "cmake -G "Visual Studio 14 2015 Win64" .."
Hi oleg,
Please refer to this link for desired compiler. The minimum requirement that they are mentioning as per link.
Try out the msvs version mentioned in the 1st link above. Let us know if you face any issues with that.
Thanks,
Praveen
I have a question about the installation guide MATLAB 2020a in windows:
all built library files in fold oneDNN-1.0. should be copied to C:\Program Files\mkl-dnn
So what I supposed to do is to create mkl-dnn/lib and mkl-dnn/include files then copy the files built in oneDNN-1.0 seperately to mkl-dnn/lib and mkl-dnn/include? However it doesn't work (errors below, it seems like mkl-dnn wasn't correctly installed), maybe because I used MATLAB 2020b? I'm installing 2020a...
Making simulation target "deployment_C_2_sfun", ...
error: 'agentData1' does not name a type
agentData1.mat_policy_9_1_1_1_1_1_1_1_ anchor;
^~~~~~~~~~
gmake: *** [deployment_C_2_sfun.obj] Error -1
Component:Make | Category:Make error
Unable to create mex function 'deployment_C_2_sfun.mexw64' required for simulation.
Component:Simulink | Category:Model error
I also checked my mkl-dnn files installed in anaconda3, there are also bin flies and LICENCE! So is there something wrong in my installation???
--------------------------------------------------------------------------------------------------------------------------------------------------
mkl-dnn in Anaconda3
Thanks in advance !!!
Hi Bonan,
In 20a and 20b we use the same oneDNN1.0 version. There might be conflict of presence of 2 mkldnn libraries installed . Are these 2 paths set as part of environement vairiable. If so, then try to remove anaconda related path from environemnt vairiables and try out. That should solve your problem.
Thanks,
Praveen.
Hi Praveen
I have the same problem with Bonan. For"all built library files in fold oneDNN-1.0. should be copied to C:\Program Files\mkl-dnn" I find that I don't have the folder named mkl-dnn, dose it means I have error in installation? Or I should create the folder by my self?
Hi Junyu,
You need to create folders "mkl-dnn", "lib" and copy the libraries to C:\Program Files\mkl-dnn\lib.
Thanks,
Praveen

Iniciar sesión para comentar.

Categorías

Productos

Versión

R2018b

Preguntada:

el 27 de Feb. de 2019

Editada:

el 29 de Abr. de 2024

Community Treasure Hunt

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

Start Hunting!

Translated by