3. Cuda-convnet2配置
顾名思义,这是cuda-convnet的2.0版本,支持多GPU运行。
3.1. 源码下载
git clone https://code.google.com/p/cuda-convnet2/
3.2. 必要的库
- sudo apt-get install Python-dev python-numpy python-scipy python-magic python-matplotlib libatlas-base-dev libjpeg-dev libopencv-dev
3.3. 配置
我只能说,这个版本的比上个版本人性化多了,这个版本的build.sh直接如此。
- # CUDA toolkit installation directory.
- export CUDA_INSTALL_PATH=/usr/local/cuda
- # Python include directory. This should contain the file Python.h, among others.
- export PYTHON_INCLUDE_PATH=/usr/include/python2.7
- # Numpy include directory. This should contain the file arrayobject.h, among others.
- export NUMPY_INCLUDE_PATH=/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/
- # ATLAS library directory. This should contain the file libcblas.so, among others.
- export ATLAS_LIB_PATH=/usr/lib/atlas-base
- # You don't have to change these:
- export LD_LIBRARY_PATH=$CUDA_INSTALL_PATH/lib64:$LD_LIBRARY_PATH
- export CUDA_SDK_PATH=$CUDA_INSTALL_PATH/samples
- export PATH=$PATH:$CUDA_INSTALL_PATH/bin
如果是在Ubuntu下的话,这样就直接已经基本把路径都配置对了。
3.4. 链接错误
但是直接编译的话还是会遇到错误,如下所示:
- cd ./bin/ && g++ -O3 -DNUMPY_INTERFACE -shared -Wl,-no-undefined -o libutilpy.so src/matrix.o -L/usr/lib/atlas-base -latlas -lcblas -lpython2.7
- /usr/bin/ld: cannot find -latlas
- /usr/bin/ld: cannot find -lcblas
- collect2: error: ld returned 1 exit status
主要是因为atlas库中没有libatlas.so和libctlas.so。查看atlas的目录发现结构如此:
- :/usr/lib/atlas-base$ ls -l
- 总用量 4292
- drwxr-xr-x 2 root root 4096 9月 22 11:41 atlas
- lrwxrwxrwx 1 root root 15 2月 4 2014 libatlas.so.3 -> libatlas.so.3.0
- -rw-r--r-- 1 root root 3746968 2月 4 2014 libatlas.so.3.0
- lrwxrwxrwx 1 root root 15 2月 4 2014 libcblas.so.3 -> libcblas.so.3.0
- -rw-r--r-- 1 root root 135376 2月 4 2014 libcblas.so.3.0
- lrwxrwxrwx 1 root root 17 2月 4 2014 libf77blas.so.3 -> libf77blas.so.3.0
- -rw-r--r-- 1 root root 131000 2月 4 2014 libf77blas.so.3.0
- lrwxrwxrwx 1 root root 22 2月 4 2014 liblapack_atlas.so.3 -> liblapack_atlas.so.3.0
- -rw-r--r-- 1 root root 369472 2月 4 2014 liblapack_atlas.so.3.0
添加两个软链接,执行命令:
- sudo ln -s libatlas.so.3.0 libatlas.so
- sudo ln -s libcblas.so.3.0 libcblas.so
目录结构变为如此:
- /usr/lib/atlas-base$ ls -l
- 总用量 4292
- drwxr-xr-x 2 root root 4096 9月 22 11:41 atlas
- lrwxrwxrwx 1 root root 15 10月 1 22:35 libatlas.so -> libatlas.so.3.0
- lrwxrwxrwx 1 root root 15 2月 4 2014 libatlas.so.3 -> libatlas.so.3.0
- -rw-r--r-- 1 root root 3746968 2月 4 2014 libatlas.so.3.0
- lrwxrwxrwx 1 root root 15 10月 1 22:36 libcblas.so -> libcblas.so.3.0
- lrwxrwxrwx 1 root root 15 2月 4 2014 libcblas.so.3 -> libcblas.so.3.0
- -rw-r--r-- 1 root root 135376 2月 4 2014 libcblas.so.3.0
- lrwxrwxrwx 1 root root 17 2月 4 2014 libf77blas.so.3 -> libf77blas.so.3.0
- -rw-r--r-- 1 root root 131000 2月 4 2014 libf77blas.so.3.0
- lrwxrwxrwx 1 root root 22 2月 4 2014 liblapack_atlas.so.3 -> liblapack_atlas.so.3.0
- -rw-r--r-- 1 root root 369472 2月 4 2014 liblapack_atlas.so.3.0
然后就可以正常编译了。
参考文献
① ImageNet Classification with Deep Convolutional Neural Networks
② https://code.google.com/p/cuda-convnet
③ https://code.google.com/p/cuda-convnet2
更多Ubuntu相关信息见Ubuntu 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=2
本文永久更新链接地址:http://www.linuxidc.com/Linux/2014-10/107500.htm
