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 next answer 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:
- libmkldnn.so
- libmkldnn.so.0
- 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.