ubuntu14.04+cuda8.0+cudnn6.0+mxnet源碼安裝

mxnet的github地址:https://github.com/apache/incubator-mxnet

mxnet的gpu版的源碼安裝(https://mxnet.incubator.apache.org/install/index.html):

1. install cuda8.0和cudnn6.0(http://blog.csdn.net/disen10/article/details/79279969)

2. Build the MXNet core shared library

Step 1 Install build tools and git.

$ sudo apt-get update
$ sudo apt-get install -y build-essential git

Step 2 Install OpenBLAS.

MXNet uses BLAS and LAPACK libraries for accelerated numerical computations on CPU machine. There are several flavors of BLAS/LAPACK libraries - OpenBLASATLAS and MKL. In this step we install OpenBLAS. You can choose to install ATLAS or MKL.

$ sudo apt-get install -y libopenblas-dev liblapack-dev

Step 3 Install OpenCV.

MXNet uses OpenCV for efficient image loading and augmentation operations.

$ sudo apt-get install -y libopencv-dev

Step 4 Download MXNet sources and build MXNet core shared library.

$ git clone --recursive https://github.com/apache/incubator-mxnet
$ cd incubator-mxnet
$ make -j $(nproc) USE_OPENCV=1 USE_BLAS=openblas USE_CUDA=1 USE_CUDA_PATH=/usr/local/cuda USE_CUDNN=1

Note - USE_OPENCV, USE_BLAS, USE_CUDA, USE_CUDA_PATH AND USE_CUDNN are make file flags to set compilation options to use OpenCV, OpenBLAS, CUDA and cuDNN libraries. You can explore and use more compilation options in make/config.mk. Make sure to set USE_CUDA_PATH to right CUDA installation path. In most cases it is - /usr/local/cuda.


3. Install the MXNet Python binding

Step 1 Install prerequisites - python, setup-tools, python-pip and numpy.

$ sudo apt-get install -y python-dev python-setuptools python-numpy python-pip

Step 2 Install the MXNet Python binding.

$ cd python
$ pip install --upgrade pip
$ pip install -e .

Note that the -e flag is optional. It is equivalent to --editable and means that if you edit the source files, these changes will be reflected in the package installed.

Step 3 Install Graphviz. (Optional, needed for graph visualization using mxnet.viz package).

sudo apt-get install graphviz
pip install graphviz

Step 4 Validate the installation by running simple MXNet code described here.


4. Validate MXNet Installation

Start the python terminal.

$ python

Run a short MXNet python program to create a 2X3 matrix of ones a on a GPU, multiply each element in the matrix by 2 followed by adding 1. We expect the output to be a 2X3 matrix with all elements being 3. We use mx.gpu(), to set MXNet context to be GPUs.

>>> import mxnet as mx
>>> a = mx.nd.ones((2, 3), mx.gpu())
>>> b = a * 2 + 1
>>> b.asnumpy()
array([[ 3.,  3.,  3.],
       [ 3.,  3.,  3.]], dtype=float32)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章