The goal here is to build mxnet.io on Windows. This was tested on Windows 10. Overall, the procedure is to compile mxnet to generate an up-to-date libmxnet.dll. Once we have that, we will build and install the R package containing all dependent libraries, including the newly-built libmxnet.dll.
This guide was adapted from the primary setup documentation http://mxnet.io/get_started/setup.html which seems out-of-date.
- Visual Studio 2013 (tested with Community Edition)
- cmake - from here
- OpenBLAS v0.2.19 - win64 binary package called
OpenBLAS-v0.2.19-Win64-int32.zipfrom here - OpenCV v3.1.0 -
opencv-3.1.0.exefrom here - CUDA v8 -
cuda_8.0.44_win10.exefrom here - CuDNN v5.1 -
cudnn-8.0-windows10-x64-v5.1.zipfrom here. Note you need to register with nVidia to download. - R and RTools - tested R v3.3.2 (
R-3.3.2-win.exefrom here) and RTools v3.4 (Rtools34.exefrom here)
Assume that packages will be saved to C:\Development\. Feel free to choose another place, but update the below paths accordingly.
-
Install Visual Studio 2013
-
Unzip cmake to
C:\Development\cmake\. You should now have:C:\Development\cmake\bin\cmake-gui.exe
-
Unzip OpenBlas to
C:\Development\OpenBLAS-v0.2.19-Win64-int32\. You should now have the following directories:C:\Development\OpenBLAS-v0.2.19-Win64-int32\bin C:\Development\OpenBLAS-v0.2.19-Win64-int32\lib C:\Development\OpenBLAS-v0.2.19-Win64-int32\include
-
Unzip OpenCV to
C:\Development\opencv-3.1.0\. You should now have the following directories:C:\Development\opencv-3.1.0\build C:\Development\opencv-3.1.0\sources
-
Run the CUDA v8 installation. You should now have the following directories:
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin
-
Unzip CuDNN v5.1 to
C:\Development\cudnn-8.0-windows10-x64-v5.1\. You should now have directories called:C:\Development\cudnn-8.0-windows10-x64-v5.1\cuda\bin C:\Development\cudnn-8.0-windows10-x64-v5.1\cuda\include C:\Development\cudnn-8.0-windows10-x64-v5.1\cuda\lib
-
Install R and RTools
To build mxnet, we'll need to use cmake to configure an appropriate Visual Studio solution (.sln) file. Once that is complete, we can open the solution file and build a release version of mxnet in Visual Studio 2013.
-
Download the latest mxnet.io source from Github or use git to clone to
C:\Development\mxnet\. You should have directories:C:\Development\mxnet\cmake C:\Development\mxnet\R-package
-
Run the cmake GUI (
cmake-gui.exefrom above)-
In the
Where is the source code:field, enter the mxnet source code directory which should beC:\Development\mxnet\. -
In the
Where to build the binaries:field, enterC:\Development\mxnet\build\. -
Make sure "Grouped" is checked, then click the configure button towards the bottom of the GUI.
-
A dialog will pop up and you should change the generator to be
Visual Studio 12 2013 Win64, then click Finish. -
After running for a bit, there will be some red lines in the cmake interface that need to be fixed. The general procedure is to update the RED lines and click configure again. Here are somethings that need to be checked/fixed:
- Make sure that under the USE, all of
USE_CUDA,USE_CUDNN,USE_MXNET_LIBNAMING,USE_OPENCV, andUSE_OPENMPare all checked and the remainder are unchecked. - OpenCV_DIR and OpenCV_CONFIG_PATH should be
C:/Development/opencv-3.1.0/build. - CUDNN_INCLUDE should be
C:/Development/cudnn-8.0-windows10-x64-v5.1/cuda/include. - CUDNN_LIBRARY should be
C:/Development/cudnn-8.0-windows10-x64-v5.1/cuda/lib/x64/cudnn.lib - CUDA_TOOLKIT_ROOT_DIR should be
C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0 - OpenBLAS_INCLUDE_DIR should be
C:/Development/OpenBLAS-v0.2.19/include - OpenBLAS_LIB should be
C:/Development/OpenBLAS-v0.2.19/lib/libopenblas.dll.a
- Make sure that under the USE, all of
-
Once the last Configure run completes with
Configuring donein th log window, click Generate. -
The log window should say
Generating done.
-
At this point we can proceed to build mxnet libraries in Visual studio.
-
Go to
C:\Development\mxnet\build\and double-click to open themxnet.slnfile. This will open Visual Studio 2013. -
Make sure the toggles on the toolbar read
Releaseandx64, then click to theBuild > Build Solution. -
Wait for the compilation and linking procedures to finish (took approximately 15 minutes on my laptop). When complete you should have the following file available:
C:\Development\mxnet\build\Release\libmxnet.dll
The mxnet source code contains a directory called C:\Development\mxnet\R-package\. This is the base directory used to compile and build an R package which can then be installed on any windows machine. This package will contain all necessary DLLs to run the mxnet libraries, so many DLLs will need to be copied to the right place.
Some of the DLLs will be the ones installed already (i.e. from CUDA, CuDNN, OpenBLAS, etc.) but there are some that we will copy from the primary mxnet R package that doesn't contain up-to-date GPU support.
-
Go to the main release page and download the latest windows build release for GPU:
20160531_win10_x64_gpu.7z. -
Unzip this to
C:\Development\20160531_win10_x64_gpu\and you should have the following directories:C:\Development\20160531_win10_x64_gpu\3rdparty C:\Development\20160531_win10_x64_gpu\include
-
Go to
C:\Development\mxnet\R-package\and make the following directories:C:\Development\mxnet\R-package\inst\include
C:\Development\mxnet\R-package\inst\libs\x64\ -
Copy the three directories named
dmlc,mshadow,mxnetinC:\Development\20160531_win10_x64_gpu\includetoC:\Development\mxnet\R-package\inst\include\. -
Copy
C:\Development\20160531_win10_x64_gpu\3rdparty\gnuwin\unzip32.dlltoC:\Development\mxnet\R-package\inst\libs\x64\. -
From the
C:\Development\20160531_win10_x64_gpu\3rdparty\openblas\bindirectory, copylibgcc_s_seh-1.dll,libgfortran-3.dll, andlibquadmath-0.dlltoC:\Development\mxnet\R-package\inst\libs\x64\. -
From the
C:\Users\flam\Downloads\20160531_win10_x64_gpu\3rdparty\vc\directory, copyvcomp120.dlltoC:\Development\mxnet\R-package\inst\libs\x64\. -
From the
C:\Development\OpenBLAS-v0.2.19-Win64-int32\bindirectory, copylibopenblas.dlltoC:\Development\mxnet\R-package\inst\libs\x64\. -
From the
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bindirectory, copycublas64_80.dll,cudart64_80.dll,curand64_80.dll,nvrtc64_80.dlltoC:\Development\mxnet\R-package\inst\libs\x64\. -
From the
C:\Development\cudnn-8.0-windows10-x64-v5.1\cuda\bindirectory, copycudnn64_5.dlltoC:\Development\mxnet\R-package\inst\libs\x64\. -
From the
C:\Development\opencv-3.1.0\build\x64\vc12\bindirectory, copyopencv_world310.dlltoC:\Development\mxnet\R-package\inst\libs\x64\. -
Finally copy the locally built mxnet library
C:\Development\mxnet\build\Release\libmxnet.dlltoC:\Development\mxnet\R-package\inst\libs\x64\. At this point there should be 13 dlls in that directory.
We're now ready to build and install the R package.
-
Open up a command prompt and cd to
C:\Development\mxnet\. -
If your R.exe isn't on the path, add it or just reference it directly and run:
"C:\Program Files\R\R-3.3.2\bin\R.exe" CMD INSTALL --build --no-multiarch R-package
-
Once it has completed building the package, you should have a file called
C:\Development\mxnet\mxnet_0.7.zipand the following message:packaged installation of 'mxnet' as mxnet_0.7.zip
- DONE (mxnet)
That mxnet_0.7.zip can now be distributed to any other Windows nodes that need the mxnet R package by just using install.packages() and referencing the mxnet_0.7.zip as the local package.
If you run require(mxnet), this should load properly, but you can also run a more complex test using instructions from the main page: http://mxnet.io/tutorials/r/mnistCompetition.html.