blob: eca0a0226cfc21807e0a5e6239561f191fb760c6 [file] [log] [blame]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta content="IE=edge" http-equiv="X-UA-Compatible"/>
<meta content="width=device-width, initial-scale=1" name="viewport"/>
<title>Build MXNet from Source — mxnet documentation</title>
<link crossorigin="anonymous" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet"/>
<link href="../_static/basic.css" rel="stylesheet" type="text/css">
<link href="../_static/pygments.css" rel="stylesheet" type="text/css">
<link href="../_static/mxnet.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: ''
};
</script>
<script src="../_static/jquery-1.11.1.js" type="text/javascript"></script>
<script src="../_static/underscore.js" type="text/javascript"></script>
<script src="../_static/searchtools_custom.js" type="text/javascript"></script>
<script src="../_static/doctools.js" type="text/javascript"></script>
<script src="../_static/selectlang.js" type="text/javascript"></script>
<script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"></script>
<script type="text/javascript"> jQuery(function() { Search.loadIndex("/searchindex.js"); Search.init();}); </script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new
Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-96378503-1', 'auto');
ga('send', 'pageview');
</script>
<!-- -->
<!-- <script type="text/javascript" src="../_static/jquery.js"></script> -->
<!-- -->
<!-- <script type="text/javascript" src="../_static/underscore.js"></script> -->
<!-- -->
<!-- <script type="text/javascript" src="../_static/doctools.js"></script> -->
<!-- -->
<!-- <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> -->
<!-- -->
<link href="https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/image/mxnet-icon.png" rel="icon" type="image/png"/>
</link></link></head>
<body role="document"><!-- Previous Navbar Layout
<div class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="../" class="navbar-brand">
<img src="http://data.mxnet.io/theme/mxnet.png">
</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul id="navbar" class="navbar navbar-left">
<li> <a href="../get_started/index.html">Get Started</a> </li>
<li> <a href="../tutorials/index.html">Tutorials</a> </li>
<li> <a href="../how_to/index.html">How To</a> </li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="true">Packages <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="../packages/python/index.html">
Python
</a></li>
<li><a href="../packages/r/index.html">
R
</a></li>
<li><a href="../packages/julia/index.html">
Julia
</a></li>
<li><a href="../packages/c++/index.html">
C++
</a></li>
<li><a href="../packages/scala/index.html">
Scala
</a></li>
<li><a href="../packages/perl/index.html">
Perl
</a></li>
</ul>
</li>
<li> <a href="../system/index.html">System</a> </li>
<li>
<form class="" role="search" action="../search.html" method="get" autocomplete="off">
<div class="form-group inner-addon left-addon">
<i class="glyphicon glyphicon-search"></i>
<input type="text" name="q" class="form-control" placeholder="Search">
</div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form> </li>
</ul>
<ul id="navbar" class="navbar navbar-right">
<li> <a href="../index.html"><span class="flag-icon flag-icon-us"></span></a> </li>
<li> <a href="..//zh/index.html"><span class="flag-icon flag-icon-cn"></span></a> </li>
</ul>
</div>
</div>
</div>
Previous Navbar Layout End -->
<div class="navbar navbar-fixed-top">
<div class="container" id="navContainer">
<div class="innder" id="header-inner">
<h1 id="logo-wrap">
<a href="../" id="logo"><img src="http://data.mxnet.io/theme/mxnet.png"/></a>
</h1>
<nav class="nav-bar" id="main-nav">
<a class="main-nav-link" href="../get_started/install.html">Install</a>
<a class="main-nav-link" href="../tutorials/index.html">Tutorials</a>
<a class="main-nav-link" href="../how_to/index.html">How To</a>
<span id="dropdown-menu-position-anchor">
<a aria-expanded="true" aria-haspopup="true" class="main-nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button">API <span class="caret"></span></a>
<ul class="dropdown-menu" id="package-dropdown-menu">
<li><a class="main-nav-link" href="../api/python/index.html">Python</a></li>
<li><a class="main-nav-link" href="../api/scala/index.html">Scala</a></li>
<li><a class="main-nav-link" href="../api/r/index.html">R</a></li>
<li><a class="main-nav-link" href="../api/julia/index.html">Julia</a></li>
<li><a class="main-nav-link" href="../api/c++/index.html">C++</a></li>
<li><a class="main-nav-link" href="../api/perl/index.html">Perl</a></li>
</ul>
</span>
<a class="main-nav-link" href="../architecture/index.html">Architecture</a>
<!-- <a class="main-nav-link" href="../community/index.html">Community</a> -->
<a class="main-nav-link" href="https://github.com/dmlc/mxnet">Github</a>
<span id="dropdown-menu-position-anchor-version" style="position: relative"><a href="#" class="main-nav-link dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="true">Versions(master)<span class="caret"></span></a><ul id="package-dropdown-menu" class="dropdown-menu"><li><a class="main-nav-link" href=http://mxnet.incubator.apache.org/test/>v0.10.14</a></li><li><a class="main-nav-link" href=http://mxnet.incubator.apache.org/test/versions/0.10/index.html>0.10</a></li><li><a class="main-nav-link" href=http://mxnet.incubator.apache.org/test/versions/master/index.html>master</a></li></ul></span></nav>
<script> function getRootPath(){ return "../" } </script>
<div class="burgerIcon dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button"></a>
<ul class="dropdown-menu dropdown-menu-right" id="burgerMenu">
<li><a href="../get_started/install.html">Install</a></li>
<li><a href="../tutorials/index.html">Tutorials</a></li>
<li><a href="../how_to/index.html">How To</a></li>
<li class="dropdown-submenu">
<a href="#" tabindex="-1">API</a>
<ul class="dropdown-menu">
<li><a href="../api/python/index.html" tabindex="-1">Python</a>
</li>
<li><a href="../api/scala/index.html" tabindex="-1">Scala</a>
</li>
<li><a href="../api/r/index.html" tabindex="-1">R</a>
</li>
<li><a href="../api/julia/index.html" tabindex="-1">Julia</a>
</li>
<li><a href="../api/c++/index.html" tabindex="-1">C++</a>
</li>
<li><a href="../api/perl/index.html" tabindex="-1">Perl</a>
</li>
</ul>
</li>
<li><a href="../architecture/index.html">Architecture</a></li>
<li><a class="main-nav-link" href="https://github.com/dmlc/mxnet">Github</a></li>
<li id="dropdown-menu-position-anchor-version-mobile" class="dropdown-submenu" style="position: relative"><a href="#" tabindex="-1">Versions(master)</a><ul class="dropdown-menu"><li><a tabindex="-1" href=http://mxnet.incubator.apache.org/test/>v0.10.14</a></li><li><a tabindex="-1" href=http://mxnet.incubator.apache.org/test/versions/0.10/index.html>0.10</a></li><li><a tabindex="-1" href=http://mxnet.incubator.apache.org/test/versions/master/index.html>master</a></li></ul></li></ul>
</div>
<div class="plusIcon dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button"><span aria-hidden="true" class="glyphicon glyphicon-plus"></span></a>
<ul class="dropdown-menu dropdown-menu-right" id="plusMenu"></ul>
</div>
<div id="search-input-wrap">
<form action="../search.html" autocomplete="off" class="" method="get" role="search">
<div class="form-group inner-addon left-addon">
<i class="glyphicon glyphicon-search"></i>
<input class="form-control" name="q" placeholder="Search" type="text"/>
</div>
<input name="check_keywords" type="hidden" value="yes">
<input name="area" type="hidden" value="default"/>
</input></form>
<div id="search-preview"></div>
</div>
<div id="searchIcon">
<span aria-hidden="true" class="glyphicon glyphicon-search"></span>
</div>
<!-- <div id="lang-select-wrap"> -->
<!-- <label id="lang-select-label"> -->
<!-- <\!-- <i class="fa fa-globe"></i> -\-> -->
<!-- <span></span> -->
<!-- </label> -->
<!-- <select id="lang-select"> -->
<!-- <option value="en">Eng</option> -->
<!-- <option value="zh">中文</option> -->
<!-- </select> -->
<!-- </div> -->
<!-- <a id="mobile-nav-toggle">
<span class="mobile-nav-toggle-bar"></span>
<span class="mobile-nav-toggle-bar"></span>
<span class="mobile-nav-toggle-bar"></span>
</a> -->
</div>
</div>
</div>
<div class="container">
<div class="row">
<div aria-label="main navigation" class="sphinxsidebar leftsidebar" role="navigation">
<div class="sphinxsidebarwrapper">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../api/python/index.html">Python Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../api/r/index.html">R Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../api/julia/index.html">Julia Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../api/c++/index.html">C++ Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../api/scala/index.html">Scala Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../api/perl/index.html">Perl Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../how_to/index.html">HowTo Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../architecture/index.html">System Documents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tutorials/index.html">Tutorials</a></li>
</ul>
</div>
</div>
<div class="content">
<div class="section" id="build-mxnet-from-source">
<span id="build-mxnet-from-source"></span><h1>Build MXNet from Source<a class="headerlink" href="#build-mxnet-from-source" title="Permalink to this headline"></a></h1>
<p><strong>NOTE:</strong> For MXNet with Python installation, please refer to the <a class="reference external" href="http://mxnet.io/get_started/install.html">new install guide</a>.</p>
<p>This document explains how to build MXNet from sources. Building MXNet from sources is a 2 step process.</p>
<ol class="simple">
<li>Build the MXNet shared library, <code class="docutils literal"><span class="pre">libmxnet.so</span></code>, from <a class="reference external" href="#build-the-shared-library">C++ source files</a></li>
<li>Install the language binding for MXNet. MXNet supports -
<a class="reference external" href="#build-the-c-package">C++</a>,
<a class="reference external" href="#build-the-scala-package">Scala</a>, <a class="reference external" href="#build-the-r-package">R</a>, and
<a class="reference external" href="#build-the-julia-package">Julia</a>.</li>
</ol>
<div class="section" id="build-the-shared-library">
<span id="build-the-shared-library"></span><h2>Build the shared library<a class="headerlink" href="#build-the-shared-library" title="Permalink to this headline"></a></h2>
<div class="section" id="prerequisites">
<span id="prerequisites"></span><h3>Prerequisites<a class="headerlink" href="#prerequisites" title="Permalink to this headline"></a></h3>
<p>You need C++ build tools and BLAS library to build MXNet shared library. If you want to run MXNet on GPUs, you need to install CUDA and CuDNN.</p>
<div class="section" id="c-build-tools">
<span id="c-build-tools"></span><h4>C++ build tools<a class="headerlink" href="#c-build-tools" title="Permalink to this headline"></a></h4>
<ol class="simple">
<li>A C++ compiler that supports C++ 11.
<a class="reference external" href="https://gcc.gnu.org/gcc-4.8/">G++ (4.8 or later)</a> or
<a class="reference external" href="http://clang.llvm.org/">Clang</a> is required.</li>
<li><a class="reference external" href="https://git-scm.com/downloads">Git</a> for downloading the sources from Github repository.</li>
<li><a class="reference external" href="https://www.gnu.org/software/make/">GNU Make</a> (<a class="reference external" href="https://cmake.org/">cmake</a>
for Windows) to build the library.</li>
</ol>
<p>Select your preferences and follow the instructions to install MXNet from sources.</p>
<div class="btn-group opt-group" role="group">
<button class="btn btn-default opt active" type="button">Linux</button>
<button class="btn btn-default opt" type="button">macOS</button>
<button class="btn btn-default opt" type="button">Windows</button>
</div>
<script src="../../_static/js/options.js" type="text/javascript"></script><div class="linux"><p>Then select the Linux distribution:</p>
<div class="btn-group opt-group" role="group">
<button class="btn btn-default opt active" type="button">Ubuntu</button>
<button class="btn btn-default opt" type="button">CentOS</button>
<button class="btn btn-default opt" type="button">Others</button>
</div><ul class="simple">
<li><strong>Ubuntu</strong> for systems supporting the <code class="docutils literal"><span class="pre">apt-get</span></code>
package management program</li>
<li><strong>CentOS</strong> for systems supporting the <code class="docutils literal"><span class="pre">yum</span></code> package
management program</li>
<li><strong>Others</strong> for general Linux-like systems building dependencies from scratch.</li>
</ul>
<div class="ubuntu"><p>Install build tools and git on <code class="docutils literal"><span class="pre">Ubuntu</span> <span class="pre">>=</span> <span class="pre">13.10</span></code> and <code class="docutils literal"><span class="pre">Debian</span> <span class="pre">>=</span> <span class="pre">8</span></code>.</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>sudo apt-get update <span class="o">&amp;&amp;</span> sudo apt-get install build-essential git
</pre></div>
</div>
</div><div class="centos"><p>Install build tools and git on <code class="docutils literal"><span class="pre">CentOS</span> <span class="pre">>=</span> <span class="pre">7</span></code> and <code class="docutils literal"><span class="pre">Fedora</span> <span class="pre">>=</span> <span class="pre">19</span></code>.</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>sudo yum groupinstall -y <span class="s2">"Development Tools"</span> <span class="o">&amp;&amp;</span> sudo yum install -y git
</pre></div>
</div>
</div><div class="others"><p>Installing both <code class="docutils literal"><span class="pre">git</span></code> and <code class="docutils literal"><span class="pre">make</span></code> by following instructions on the websites is
straightforward. Here we provide the instructions to build <code class="docutils literal"><span class="pre">gcc-4.8</span></code> from source codes.</p>
<ol>
<li><p class="first">Install the 32-bit <code class="docutils literal"><span class="pre">libc</span></code> with one of the following system-specific commands:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>sudo apt-get install libc6-dev-i386 <span class="c1"># In Ubuntu</span>
sudo yum install glibc-devel.i686 <span class="c1"># In RHEL (Red Hat Linux)</span>
sudo yum install glibc-devel.i386 <span class="c1"># In CentOS 5.8</span>
sudo yum install glibc-devel.i686 <span class="c1"># In CentOS 6/7</span>
</pre></div>
</div>
</li>
<li><p class="first">Download and extract the <code class="docutils literal"><span class="pre">gcc</span></code> source code with the prerequisites:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>wget http://mirrors.concertpass.com/gcc/releases/gcc-4.8.5/gcc-4.8.5.tar.gz
tar -zxf gcc-4.8.5.tar.gz
<span class="nb">cd</span> gcc-4.8.5
./contrib/download_prerequisites
</pre></div>
</div>
</li>
<li><p class="first">Build <code class="docutils literal"><span class="pre">gcc</span></code> by using 10 threads and then install to <code class="docutils literal"><span class="pre">/usr/local</span></code></p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>mkdir release <span class="o">&amp;&amp;</span> <span class="nb">cd</span> release
../configure --prefix<span class="o">=</span>/usr/local --enable-languages<span class="o">=</span>c,c++
make -j10
sudo make install
</pre></div>
</div>
</li>
<li><p class="first">Add the lib path to your configure file such as <code class="docutils literal"><span class="pre">~/.bashrc</span></code>:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span><span class="nb">export</span> <span class="nv">LD_LIBRARY_PATH</span><span class="o">=</span><span class="si">${</span><span class="nv">LD_LIBRARY_PATH</span><span class="si">}</span>:/usr/local/lib64
</pre></div>
</div>
</li>
</ol>
</div>
</div> <!-- linux --><div class="windows"><ol class="simple">
<li>If <a class="reference external" href="https://www.visualstudio.com/downloads/">Microsoft Visual Studio 2015</a> is not already installed, download and install it. You can download and install the free community edition.</li>
<li>Download and Install <a class="reference external" href="https://cmake.org/">CMake</a> if it is not already installed.</li>
</ol>
</div><div class="macos"><p>Install <a class="reference external" href="https://developer.apple.com/xcode/">Xcode</a>.</p>
</div></div>
<div class="section" id="blas-library">
<span id="blas-library"></span><h4>BLAS library<a class="headerlink" href="#blas-library" title="Permalink to this headline"></a></h4>
<p>MXNet relies on the
<a class="reference external" href="https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms">BLAS</a> (Basic
Linear Algebra Subprograms) library for numerical computations. You can install
any one among <a class="reference external" href="http://math-atlas.sourceforge.net/">ATLAS</a>,
<a class="reference external" href="http://www.openblas.net/">OpenBLAS</a> and
<a class="reference external" href="https://software.intel.com/en-us/intel-mkl">MKL</a>.</p>
<div class="linux">
<div class="ubuntu"><div class="highlight-bash"><div class="highlight"><pre><span></span>sudo apt-get install libatlas-base-dev
</pre></div>
</div>
</div><div class="centos"><div class="highlight-bash"><div class="highlight"><pre><span></span>sudo yum install atlas-devel
</pre></div>
</div>
</div><div class="linux"><p>You can follow this link to build
<a class="reference external" href="https://github.com/xianyi/OpenBLAS#installation-from-source">OpenBlas from source</a>.</p>
</div>
</div><div class="macos"><p>macOS users can skip this step as <code class="docutils literal"><span class="pre">xcode</span></code> ships with a BLAS library.</p>
</div><div class="windows"><ol class="simple">
<li>Download pre-built binaries for <a class="reference external" href="https://sourceforge.net/projects/openblas/files/">OpenBLAS</a></li>
<li>Set the environment variable <code class="docutils literal"><span class="pre">OpenBLAS_HOME</span></code> to point to the OpenBLAS
directory that contains the <code class="docutils literal"><span class="pre">include/</span></code> and <code class="docutils literal"><span class="pre">lib/</span></code> directories. Typically, you
can find the directory in <code class="docutils literal"><span class="pre">C:\Program</span> <span class="pre">files</span> <span class="pre">(x86)\OpenBLAS\</span></code>.</li>
</ol>
</div></div>
<div class="section" id="optional-opencv-for-image-loading-and-augmentation">
<span id="optional-opencv-for-image-loading-and-augmentation"></span><h4>Optional: <a class="reference external" href="http://opencv.org/">OpenCV</a> for Image Loading and Augmentation<a class="headerlink" href="#optional-opencv-for-image-loading-and-augmentation" title="Permalink to this headline"></a></h4>
<div class="linux">
<div class="ubuntu"><div class="highlight-bash"><div class="highlight"><pre><span></span>sudo apt-get install libopencv-dev
</pre></div>
</div>
</div><div class="centos"><div class="highlight-bash"><div class="highlight"><pre><span></span>sudo apt-get install opencv-devel
</pre></div>
</div>
</div><div class="others"><p>To build OpenCV from source code, you need the <a class="reference external" href="https://cmake.org">cmake</a> library.</p>
<ol>
<li><p class="first">If you don’t have cmake or if your version of cmake is earlier than 3.6.1, run the following commands to install a newer version of cmake:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>wget https://cmake.org/files/v3.6/cmake-3.6.1-Linux-x86_64.tar.gz
tar -zxvf cmake-3.6.1-Linux-x86_64.tar.gz
<span class="nb">alias</span> <span class="nv">cmake</span><span class="o">=</span><span class="s2">"cmake-3.6.1-Linux-x86_64/bin/cmake"</span>
</pre></div>
</div>
</li>
<li><p class="first">To download and extract the OpenCV source code, run the following commands:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>wget https://codeload.github.com/opencv/opencv/zip/2.4.13
unzip <span class="m">2</span>.4.13
<span class="nb">cd</span> opencv-2.4.13
mkdir release
<span class="nb">cd</span> release/
</pre></div>
</div>
</li>
<li><p class="first">Build OpenCV. The following commands build OpenCV with 10 threads. We
disabled GPU support, which might significantly slow down an MXNet program
running on a GPU processor. It also disables 1394 which might generate a
warning. Then install it on <code class="docutils literal"><span class="pre">/usr/local</span></code>.</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>cmake -D <span class="nv">BUILD_opencv_gpu</span><span class="o">=</span>OFF -D <span class="nv">WITH_CUDA</span><span class="o">=</span>OFF -D <span class="nv">WITH_1394</span><span class="o">=</span>OFF -D <span class="nv">CMAKE_BUILD_TYPE</span><span class="o">=</span>RELEASE -D <span class="nv">CMAKE_INSTALL_PREFIX</span><span class="o">=</span>/usr/local ..
make -j10
sudo make install
</pre></div>
</div>
</li>
<li><p class="first">Add the lib path to your configuration such as <code class="docutils literal"><span class="pre">~/.bashrc</span></code>.</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span><span class="nb">export</span> <span class="nv">PKG_CONFIG_PATH</span><span class="o">=</span><span class="nv">$PKG_CONFIG_PATH</span>:/usr/local/lib/pkgconfig/
</pre></div>
</div>
</li>
</ol>
</div>
</div><div class="windows"><p>First download and install <a class="reference external" href="http://opencv.org/releases.html">OpenCV</a>, then set
the environment variable <code class="docutils literal"><span class="pre">OpenCV_DIR</span></code> to point to the OpenCV build directory.</p>
</div></div>
<div class="section" id="optional-cuda-cudnn-for-nvidia-gpus">
<span id="optional-cuda-cudnn-for-nvidia-gpus"></span><h4>Optional: <a class="reference external" href="https://developer.nvidia.com/cuda-downloads">CUDA</a>/<a class="reference external" href="https://developer.nvidia.com/cudnn">cuDNN</a> for Nvidia GPUs<a class="headerlink" href="#optional-cuda-cudnn-for-nvidia-gpus" title="Permalink to this headline"></a></h4>
<p>MXNet is compatible with both CUDA 7.5 and 8.0. It is recommended to use cuDNN 5.</p>
<div class="linux">
<div class="ubuntu"><p>Install CUDA 7.5 and cuDNN 5 on Ubuntu 14.04</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1404/x86_64/cuda-repo-ubuntu1404_7.5-18_amd64.deb
sudo dpkg -i cuda-repo-ubuntu1404_7.5-18_amd64.deb
<span class="nb">echo</span> <span class="s2">"deb http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1404/x86_64 /"</span> <span class="p">|</span> sudo tee /etc/apt/sources.list.d/nvidia-ml.list
sudo apt-get update
sudo apt-get install -y linux-image-extra-<span class="sb">`</span>uname -r<span class="sb">`</span> linux-headers-<span class="sb">`</span>uname -r<span class="sb">`</span> linux-image-<span class="sb">`</span>uname -r<span class="sb">`</span>
sudo apt-get install -y cuda libcudnn5-dev<span class="o">=</span><span class="m">5</span>.0.5-1+cuda7.5
</pre></div>
</div>
</div>
</div></div>
</div>
<div class="section" id="build">
<span id="build"></span><h3>Build<a class="headerlink" href="#build" title="Permalink to this headline"></a></h3>
<div class="linux macos"><p>First clone the recent codes</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>git clone --recursive https://github.com/dmlc/mxnet
<span class="nb">cd</span> mxnet
</pre></div>
</div>
<p>File
<a class="reference external" href="https://github.com/dmlc/mxnet/blob/master/make/config.mk"><code class="docutils literal"><span class="pre">make/config.mk</span></code></a>
contains all the compilation options. You can edit it and then <code class="docutils literal"><span class="pre">make</span></code>. There are
some example build options</p>
<p>If you want to build MXNet with C++ language binding, please make sure you read <a class="reference external" href="#build-the-c-package">Build the C++ package</a> first.</p>
</div><div class="linux"><ul>
<li><p class="first">Build without using OpenCV. <code class="docutils literal"><span class="pre">-j</span></code> runs multiple jobs against multi-core CPUs.</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>make -j <span class="nv">USE_OPENCV</span><span class="o">=</span><span class="m">0</span>
</pre></div>
</div>
</li>
<li><p class="first">Build with both GPU and OpenCV support</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>make -j <span class="nv">USE_BLAS</span><span class="o">=</span>openblas <span class="nv">USE_CUDA</span><span class="o">=</span><span class="m">1</span> <span class="nv">USE_CUDA_PATH</span><span class="o">=</span>/usr/local/cuda <span class="nv">USE_CUDNN</span><span class="o">=</span><span class="m">1</span>
</pre></div>
</div>
</li>
</ul>
</div><div class="macos"><ul>
<li><p class="first">Build with the default BLAS library and clang installed with <code class="docutils literal"><span class="pre">xcode</span></code> (OPENMP
is disabled because it is not supported in default by clang).</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>make -j <span class="nv">USE_BLAS</span><span class="o">=</span>apple <span class="nv">USE_OPENCV</span><span class="o">=</span><span class="m">0</span> <span class="nv">USE_OPENMP</span><span class="o">=</span><span class="m">0</span>
</pre></div>
</div>
</li>
</ul>
</div><div class="windows"><p>Use <a class="reference external" href="https://cmake.org/">CMake</a> to create a Visual Studio solution in <code class="docutils literal"><span class="pre">./build</span></code>.</p>
<p>In Visual Studio, open the solution file,<code class="docutils literal"><span class="pre">.sln</span></code>, and compile it.
These commands produce a library called <code class="docutils literal"><span class="pre">mxnet.dll</span></code> in the <code class="docutils literal"><span class="pre">./build/Release/</span></code> or <code class="docutils literal"><span class="pre">./build/Debug</span></code> folder.</p>
</div></div>
</div>
<div class="section" id="build-the-c-package">
<span id="build-the-c-package"></span><h2>Build the C++ package<a class="headerlink" href="#build-the-c-package" title="Permalink to this headline"></a></h2>
<p>The C++ package has the same prerequisites as the MXNet library, you should also have <code class="docutils literal"><span class="pre">python</span></code> installed. (Both <code class="docutils literal"><span class="pre">python</span></code> 2 and 3 are supported)</p>
<p>To enable C++ package, just add <code class="docutils literal"><span class="pre">USE_CPP_PACKAGE=1</span></code> in the build options when building the MXNet shared library.</p>
</div>
<div class="section" id="build-the-r-package">
<span id="build-the-r-package"></span><h2>Build the R package<a class="headerlink" href="#build-the-r-package" title="Permalink to this headline"></a></h2>
<p>The R package requires <code class="docutils literal"><span class="pre">R</span></code> to be installed.</p>
<div class="ubuntu"><p>Follow the below instructions to install the latest R on Ubuntu 14.04 (trusty) and also the libraries used
to build other R package dependencies.</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span><span class="nb">echo</span> <span class="s2">"deb http://cran.rstudio.com/bin/linux/ubuntu trusty/"</span> >> /etc/apt/sources.list
gpg --keyserver keyserver.ubuntu.com --recv-key E084DAB9
gpg -a --export E084DAB9 <span class="p">|</span> apt-key add -
apt-get update
apt-get install -y r-base r-base-dev libxml2-dev libxt-dev libssl-dev
</pre></div>
</div>
</div><p>Install the required R package dependencies:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span><span class="nb">cd</span> R-package
Rscript -e <span class="s2">"install.packages('devtools', repo = 'https://cran.rstudio.com')"</span>
Rscript -e <span class="s2">"library(devtools); library(methods); options(repos=c(CRAN='https://cran.rstudio.com')); install_deps(dependencies = TRUE)"</span>
</pre></div>
</div>
<p>Next, build and install the MXNet R package:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span><span class="nb">cd</span> ..
make rpkg
R CMD INSTALL mxnet_current_r.tar.gz
</pre></div>
</div>
</div>
<div class="section" id="build-the-scala-package">
<span id="build-the-scala-package"></span><h2>Build the Scala package<a class="headerlink" href="#build-the-scala-package" title="Permalink to this headline"></a></h2>
<p>Both JDK and Maven are required to build the Scala package.</p>
<div class="ubuntu"><div class="highlight-bash"><div class="highlight"><pre><span></span>sudo apt-get install -y maven default-jdk
</pre></div>
</div>
</div><p>The following command builds the <code class="docutils literal"><span class="pre">.jar</span></code> package:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>make scalapkg
</pre></div>
</div>
<p>which can be found by <code class="docutils literal"><span class="pre">ls</span> <span class="pre">scala-package/assembly/*/target/*SNAPSHOT.jar</span></code>.</p>
<p>Optionally, we can install Scala for the interactive interface.</p>
<div class="ubuntu"><div class="highlight-bash"><div class="highlight"><pre><span></span>wget http://downloads.lightbend.com/scala/2.11.8/scala-2.11.8.deb
dpkg -i scala-2.11.8.deb
rm scala-2.11.8.deb
</pre></div>
</div>
</div><p>Then we can start <code class="docutils literal"><span class="pre">scala</span></code> with <code class="docutils literal"><span class="pre">mxnet</span></code> imported by</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>scala -cp scala-package/assembly/*/target/*SNAPSHOT.jar
</pre></div>
</div>
</div>
<div class="section" id="build-the-julia-package">
<span id="build-the-julia-package"></span><h2>Build the Julia package<a class="headerlink" href="#build-the-julia-package" title="Permalink to this headline"></a></h2>
<p>We need to first install Julia.</p>
<div class="ubuntu centos linux"><p>The following commands install Julia 0.5.1</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>wget -q https://julialang.s3.amazonaws.com/bin/linux/x64/0.5/julia-0.5.1-linux-x86_64.tar.gz
tar -zxf julia-0.5.1-linux-x86_64.tar.gz
rm julia-0.5.1-linux-x86_64.tar.gz
ln -s <span class="k">$(</span><span class="nb">pwd</span><span class="k">)</span>/julia-6445c82d00/bin/julia /usr/bin/julia
</pre></div>
</div>
</div><p>Next set the environment variable <code class="docutils literal"><span class="pre">MXNET_HOME=/path/to/mxnet</span></code> so that Julia
can find the pre-built library.</p>
<p>Install the Julia package for MXNet with:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>julia -e <span class="s1">'Pkg.add("MXNet")'</span>
</pre></div>
</div>
<div class="section" id="build-the-perl-package">
<span id="build-the-perl-package"></span><h3>Build the Perl package<a class="headerlink" href="#build-the-perl-package" title="Permalink to this headline"></a></h3>
<p>Run the following command from the MXNet source root directory to build the MXNet Perl package:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span> sudo apt-get install libmouse-perl pdl cpanminus swig libgraphviz-perl
cpanm -q -L <span class="s2">"</span><span class="si">${</span><span class="nv">HOME</span><span class="si">}</span><span class="s2">/perl5"</span> Function::Parameters
<span class="nv">MXNET_HOME</span><span class="o">=</span><span class="si">${</span><span class="nv">PWD</span><span class="si">}</span>
<span class="nb">export</span> <span class="nv">LD_LIBRARY_PATH</span><span class="o">=</span><span class="si">${</span><span class="nv">MXNET_HOME</span><span class="si">}</span>/lib
<span class="nb">export</span> <span class="nv">PERL5LIB</span><span class="o">=</span><span class="si">${</span><span class="nv">HOME</span><span class="si">}</span>/perl5/lib/perl5
<span class="nb">cd</span> <span class="si">${</span><span class="nv">MXNET_HOME</span><span class="si">}</span>/perl-package/AI-MXNetCAPI/
perl Makefile.PL <span class="nv">INSTALL_BASE</span><span class="o">=</span><span class="si">${</span><span class="nv">HOME</span><span class="si">}</span>/perl5
make install
<span class="nb">cd</span> <span class="si">${</span><span class="nv">MXNET_HOME</span><span class="si">}</span>/perl-package/AI-NNVMCAPI/
perl Makefile.PL <span class="nv">INSTALL_BASE</span><span class="o">=</span><span class="si">${</span><span class="nv">HOME</span><span class="si">}</span>/perl5
make install
<span class="nb">cd</span> <span class="si">${</span><span class="nv">MXNET_HOME</span><span class="si">}</span>/perl-package/AI-MXNet/
perl Makefile.PL <span class="nv">INSTALL_BASE</span><span class="o">=</span><span class="si">${</span><span class="nv">HOME</span><span class="si">}</span>/perl5
make install
</pre></div>
</div>
</div>
</div>
</div>
<div class="container">
<div class="footer">
<p> © 2015-2017 DMLC. All rights reserved. </p>
</div>
</div>
</div>
<div aria-label="main navigation" class="sphinxsidebar rightsidebar" role="navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="../index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Build MXNet from Source</a><ul>
<li><a class="reference internal" href="#build-the-shared-library">Build the shared library</a><ul>
<li><a class="reference internal" href="#prerequisites">Prerequisites</a><ul>
<li><a class="reference internal" href="#c-build-tools">C++ build tools</a></li>
<li><a class="reference internal" href="#blas-library">BLAS library</a></li>
<li><a class="reference internal" href="#optional-opencv-for-image-loading-and-augmentation">Optional: OpenCV for Image Loading and Augmentation</a></li>
<li><a class="reference internal" href="#optional-cuda-cudnn-for-nvidia-gpus">Optional: CUDA/cuDNN for Nvidia GPUs</a></li>
</ul>
</li>
<li><a class="reference internal" href="#build">Build</a></li>
</ul>
</li>
<li><a class="reference internal" href="#build-the-c-package">Build the C++ package</a></li>
<li><a class="reference internal" href="#build-the-r-package">Build the R package</a></li>
<li><a class="reference internal" href="#build-the-scala-package">Build the Scala package</a></li>
<li><a class="reference internal" href="#build-the-julia-package">Build the Julia package</a><ul>
<li><a class="reference internal" href="#build-the-perl-package">Build the Perl package</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- pagename != index -->
<script crossorigin="anonymous" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="../_static/js/sidebar.js" type="text/javascript"></script>
<script src="../_static/js/search.js" type="text/javascript"></script>
<script src="../_static/js/navbar.js" type="text/javascript"></script>
<script src="../_static/js/clipboard.min.js" type="text/javascript"></script>
<script src="../_static/js/copycode.js" type="text/javascript"></script>
<script type="text/javascript">
$('body').ready(function () {
$('body').css('visibility', 'visible');
});
</script>
</div></body>
</html>