Installing MXNet froum source on OS X (Mac)¶
NOTE: For prebuild MXNet with Python installation, please refer to the new install guide.
Installing MXNet is a two-step process:
- Build the shared library from the MXNet C++ source code.
- Install the supported language-specific packages for MXNet.
Note: To change the compilation options for your build, edit the make/config.mk
file and submit a build request with the make
command.
Prepare Environment for GPU Installation¶
This section is optional. Skip to next section if you don’t plan to use GPUs. If you plan to build with GPU, you need to set up the environment for CUDA and cuDNN.
First, download and install CUDA 8 toolkit.
Once you have the CUDA Toolkit installed you will need to set up the required environment variables by adding the following to your ~/.bash_profile file:
export CUDA_HOME=/usr/local/cuda
export DYLD_LIBRARY_PATH="$CUDA_HOME/lib:$DYLD_LIBRARY_PATH"
export PATH="$CUDA_HOME/bin:$PATH"
Reload ~/.bash_profile file and install dependencies:
. ~/.bash_profile
brew install coreutils
brew tap caskroom/cask
Then download cuDNN 5.
Unzip the file and change to the cudnn root directory. Move the header files and libraries to your local CUDA Toolkit folder:
$ sudo mv include/cudnn.h /Developer/NVIDIA/CUDA-8.0/include/
$ sudo mv lib/libcudnn* /Developer/NVIDIA/CUDA-8.0/lib
$ sudo ln -s /Developer/NVIDIA/CUDA-8.0/lib/libcudnn* /usr/local/cuda/lib/
Now we can start to build MXNet.
Install the MXNet Package for R¶
You have 2 options:
- Building MXNet with the Prebuilt Binary Package
- Building MXNet from Source Code
Building MXNet with the Prebuilt Binary Package¶
For OS X (Mac) users, MXNet provides a prebuilt binary package for CPUs. The prebuilt package is updated weekly. You can install the package directly in the R console using the following commands:
cran <- getOption("repos")
cran["dmlc"] <- "https://s3-us-west-2.amazonaws.com/apache-mxnet/R/CRAN/"
options(repos = cran)
install.packages("mxnet")
Building MXNet from Source Code¶
Run the following commands to install the MXNet dependencies and build the MXNet R package.
Rscript -e "install.packages('devtools', repo = 'https://cran.rstudio.com')"
cd R-package
Rscript -e "library(devtools); library(methods); options(repos=c(CRAN='https://cran.rstudio.com')); install_deps(dependencies = TRUE)"
cd ..
make rpkg
Note: R-package is a folder in the MXNet source.
These commands create the MXNet R package as a tar.gz file that you can install as an R package. To install the R package, run the following command, use your MXNet version number:
R CMD INSTALL mxnet_current_r.tar.gz
Install the MXNet Package for Julia¶
The MXNet package for Julia is hosted in a separate repository, MXNet.jl, which is available on GitHub. To use Julia binding it with an existing libmxnet installation, set the MXNET_HOME
environment variable by running the following command:
export MXNET_HOME=//libmxnet
The path to the existing libmxnet installation should be the root directory of libmxnet. In other words, you should be able to find the libmxnet.so
file at $MXNET_HOME/lib
. For example, if the root directory of libmxnet is ~
, you would run the following command:
export MXNET_HOME=/~/libmxnet
You might want to add this command to your ~/.bashrc
file. If you do, you can install the Julia package in the Julia console using the following command:
Pkg.add("MXNet")
For more details about installing and using MXNet with Julia, see the MXNet Julia documentation.
Install the MXNet Package for Scala¶
Before you build MXNet for Scala from source code, you must complete building the shared library. After you build the shared library, run the following command from the MXNet source root directory to build the MXNet Scala package:
make scalapkg
This command creates the JAR files for the assembly, core, and example modules. It also creates the native library in the native/{your-architecture}/target directory
, which you can use to cooperate with the core module.
To install the MXNet Scala package into your local Maven repository, run the following command from the MXNet source root directory:
make scalainstall
Install the MXNet Package for Perl¶
Before you build MXNet for Perl from source code, you must complete building the shared library. After you build the shared library, run the following command from the MXNet source root directory to build the MXNet Perl package:
brew install swig
sudo sh -c 'curl -L https://cpanmin.us | perl - App::cpanminus'
sudo cpanm -q -n PDL Mouse Function::Parameters
MXNET_HOME=${PWD}
export PERL5LIB=${HOME}/perl5/lib/perl5
cd ${MXNET_HOME}/perl-package/AI-MXNetCAPI/
perl Makefile.PL INSTALL_BASE=${HOME}/perl5
make
install_name_tool -change lib/libmxnet.so \
${MXNET_HOME}/lib/libmxnet.so \
blib/arch/auto/AI/MXNetCAPI/MXNetCAPI.bundle
make install
cd ${MXNET_HOME}/perl-package/AI-NNVMCAPI/
perl Makefile.PL INSTALL_BASE=${HOME}/perl5
make
install_name_tool -change lib/libmxnet.so \
${MXNET_HOME}/lib/libmxnet.so \
blib/arch/auto/AI/NNVMCAPI/NNVMCAPI.bundle
make install
cd ${MXNET_HOME}/perl-package/AI-MXNet/
perl Makefile.PL INSTALL_BASE=${HOME}/perl5
make install