Skip to content

Instantly share code, notes, and snippets.

@thirdwing
Last active April 6, 2018 02:03
Show Gist options
  • Save thirdwing/89aa9bfc588ade138496e6932072152c to your computer and use it in GitHub Desktop.
Save thirdwing/89aa9bfc588ade138496e6932072152c to your computer and use it in GitHub Desktop.
MXNet R installation with GPU support on Windows

MXNet R installation with GPU support on Windows

Clone the MXNet github repo

git clone --recursive https://github.com/dmlc/mxnet

The --recursive is to clone all the submodules used by MXNet.

Download prebuilt shared libraries for Windows.

Please download mxnet_x64_vc14_gpu.7z and prebuildbase_win10_x64_vc14.7z from https://github.com/yajiedesign/mxnet/releases

Download cuDNN from NVIDIA website

Please download cuDNN from https://developer.nvidia.com/cudnn

Add necessary dlls into the R-package folder

  1. Please mkdir the folder structure: ./R-package/inst/libs/x64;

  2. Copy the following dlls into ./R-package/inst/libs/x64:

cublas64_80.dll
cudart64_80.dll
cudnn64_5.dll
curand64_80.dll
libgcc_s_seh-1.dll
libgfortran-3.dll
libmxnet.dll
libmxnet.lib
libopenblas.dll
libquadmath-0.dll
nvrtc64_80.dll

These dlls can be found in prebuildbase_win10_x64_vc14/3rdparty/cudart, prebuildbase_win10_x64_vc14/3rdparty/openblas/bin, mxnet_x64_vc14_gpu/build, mxnet_x64_vc14_gpu/lib and the cuDNN downloaded from NVIDIA.

Add necessary header files into the R-package folder

  1. Please mkdir the folder structure: ./R-package/inst/include;

  2. Copy the header files from dmlc, mxnet and nnvm into ./R-package/inst/include. It should look like:

./R-package/inst
└── include
    ├── dmlc
    ├── mxnet
    └── nnvm

Build the R package using Rtools

Now please open the Windows CMD and change the directory to the mxnet folder. Then use the following commands to build R package:

echo import(Rcpp) > R-package\NAMESPACE
echo import(methods) >> R-package\NAMESPACE
Rscript -e "install.packages('devtools', repos = 'https://cloud.r-project.org')"
cd R-package
Rscript -e "library(devtools); library(methods); options(repos=c(CRAN='https://cran.rstudio.com')); install_deps(dependencies = TRUE)"
cd ..

R CMD INSTALL --no-multiarch R-package

Rscript -e "require(mxnet); mxnet:::mxnet.export('R-package')"
rm R-package/NAMESPACE
Rscript -e "require(devtools); install_version('roxygen2', version = '5.0.1', repos = 'https://cloud.r-project.org/', quiet = TRUE)"
Rscript -e "require(roxygen2); roxygen2::roxygenise('R-package')"

R CMD INSTALL --build --no-multiarch R-package
@haimeh
Copy link

haimeh commented Apr 6, 2018

If you are looking for a specific cuda version for your installation you might have some luck copying the *.dll and *.lib files from a python installation.
For instance, if you wanted the cuda 9.1 build (which is not available from https://github.com/yajiedesign/mxnet/releases upon writing this) you could:

pip install mxnet-cu91

If you don't know where pip installs packages you can:

pip show mxnet-cu91

You would then go to the directory indicated by "Location:" and find the "mxnet" dir.
In my case it was: "C:\Python\Python36\Lib\site-packages\mxnet"
You would then follow the steps from the guide, but using the *.dll and *.lib from the python installation when possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment