歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Ubuntu 14.04配置cuda-convnet

Ubuntu 14.04配置cuda-convnet

日期:2017/2/28 14:27:34   编辑:Linux教程

在這個鏈接中(http://www.linuxidc.com/Linux/2014-10/107501.htm),我配置了cuda,有強大的GPU,自然不能暴殄天物,讓資源白白空閒著,所以配置一下卷積神經網絡跑一下程序喽。至於卷積神經網絡的原理,容後再寫。打算先寫庫的用法,再寫原理,以行動帶動對理論的追求。

話不多說,步入正題。

1. 預說明

關於cuda-convnet,起源於一篇經典論文①,論文中針對ILSVRC-2010的數據進行實驗,然後公布了其實驗使用的代碼,鏈接為②。但是,事實往往跟論文是有差距的,鏈接②中的代碼根本不能重現論文中的結果。在下不才,在使用這個鏈接的庫很久之後才發現的,覺得很坑,希望後來者慎之。

之所以說它坑,首先,論文中提到特性中,multi-GPU和dropout就沒有實現,而且也沒有給出論文中8層卷積神經網絡的配置文件。總之不能直接拿來用,需要自己探索。

雖然如此,但有總比沒有好,畢竟這個庫實現的卷積神經網絡封裝的很好,論文中的大神的貢獻非我等小菜所能企及的。給大神點32個贊。

本文只對cuda-convnet和cuda-convnet2的配置進行說明,論文中的作者還公布了其他版本的庫,尚未用到,故且按下不提。

Ubuntu 12.04 下 CUDA 編程 http://www.linuxidc.com/linux/2014-06/103056.htm

Ubuntu 12.04 安裝 CUDA-5.5 http://www.linuxidc.com/Linux/2013-10/91101.htm

Ubuntu 11.10 上安裝CUDA開發環境 http://www.linuxidc.com/Linux/2012-04/58913.htm

Fedora 15系統下配置CUDA環境 http://www.linuxidc.com/Linux/2011-12/49874.htm

Ubuntu 11.04 安裝 NVIDIA CUDA 4.0 RC2 http://www.linuxidc.com/Linux/2011-10/46304.htm

Linux Mint 13/Ubuntu 12.04 配置CUDA 4.2 & OpenCV 2.4.2 方法 http://www.linuxidc.com/Linux/2013-10/91102.htm

CUDA入門教程 http://www.linuxidc.com/Linux/2014-07/104328.htm

2. Cuda-convnet配置

2.1. 源碼下載

參考鏈接②,先將源碼下載下來。

  1. svn checkout http://cuda-convnet.googlecode.com/svn/trunk/ cuda-convnet-read-only
svn checkout http://cuda-convnet.googlecode.com/svn/trunk/ cuda-convnet-read-only

取出的版本是562。

2.2. 安裝必要的庫

然後,安裝必須的庫,我使用的是ubuntu系統。所以命令為

  1. sudo apt-get install python-dev python-numpy python-magic python-matplotlib libatlas-base-dev
sudo apt-get install python-dev python-numpy python-magic python-matplotlib libatlas-base-dev

當然,還要確認你安裝了cuda,我安裝的是cuda6.5,在/usr/local/目錄下,如下所示:

  1. $ ls /usr/local
  2. bin cuda cuda-6.5 etc games include lib man sbin share src
$ ls /usr/local
bin  cuda  cuda-6.5  etc  games  include  lib  man  sbin  share  src

2.3. 更改build.sh

進入到剛才下載的cuda-convnet-read-only目錄,更改build.sh文件中的配置路徑。如下所示:

  1. # CUDA toolkit installation directory.
  2. export CUDA_INSTALL_PATH=/usr/local/cuda
  3. # CUDA SDK installation directory.
  4. export CUDA_SDK_PATH=/usr/local/cuda-6.5/samples/common/inc
  5. # Python include directory. This should contain the file Python.h, among others.
  6. export PYTHON_INCLUDE_PATH=/usr/include/python2.7
  7. # Numpy include directory. This should contain the file arrayobject.h, among others.
  8. export NUMPY_INCLUDE_PATH=/usr/lib/python2.7/dist-packages/numpy/core/include/numpy
  9. # ATLAS library directory. This should contain the file libcblas.so, among others.
  10. export ATLAS_LIB_PATH=/usr/lib/atlas-base
  11. make $*
# CUDA toolkit installation directory.
export CUDA_INSTALL_PATH=/usr/local/cuda
 
# CUDA SDK installation directory.
export CUDA_SDK_PATH=/usr/local/cuda-6.5/samples/common/inc
 
# 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
 
make $*

按照官網的教程,配置完build.sh後就可以進行編譯了。但是會發生錯誤,還需要改如下幾個地方才可以。

2.4. 頭文件添加

直接編譯會發生找不到cutil_inline.h頭文件的錯誤。分析原因可能是原來有這個頭文件,後來這個頭文件的功能被實現到其他頭文件中去了。

在include子文件夾下田間cutil_inline.h文件,並輸入內容。

  1. #include "helper_cuda.h"
  2. #define cutilCheckMsg(a) getLastCudaError(a)
  3. #define cutGetMaxGflopsDeviceId() gpuGetMaxGflopsDeviceId()
  4. #define MIN(a,b) (a) < (b) ? (a) : (b)
#include "helper_cuda.h"
#define cutilCheckMsg(a) getLastCudaError(a)
#define cutGetMaxGflopsDeviceId() gpuGetMaxGflopsDeviceId()
#define MIN(a,b) (a) < (b) ? (a) : (b)

2.5. MakeFile文件更改

MakeFile第3行,原文如下:

  1. INCLUDES := -I$(PYTHON_INCLUDE_PATH) -I$(NUMPY_INCLUDE_PATH) -I./include -I./include/common -I./include/cudaconv2 -I./include/nvmatrix
INCLUDES :=  -I$(PYTHON_INCLUDE_PATH) -I$(NUMPY_INCLUDE_PATH) -I./include -I./include/common -I./include/cudaconv2 -I./include/nvmatrix

添加cuda的路徑後如下:

  1. INCLUDES := -I$(PYTHON_INCLUDE_PATH) -I$(NUMPY_INCLUDE_PATH) -I$(CUDA_SDK_PATH) -I./include -I./include/common -I./include/cudaconv2 -I./include/nvmatrix
INCLUDES :=  -I$(PYTHON_INCLUDE_PATH) -I$(NUMPY_INCLUDE_PATH) -I$(CUDA_SDK_PATH) -I./include -I./include/common -I./include/cudaconv2 -I./include/nvmatrix

保存之。

2.6. 最後的庫鏈接錯誤

做完上述改動後,可以編譯了,但到最後會發生一個庫鏈接的錯誤,不用管,直接將那個庫注釋掉。

在common-gcc-cuda-4.0.mk文件的332行。直接用#號注釋。

  1. # LIB += -lcutil_$(LIB_ARCH) $(LIBSUFFIX) -lshrutil_$(LIB_ARCH) $(LIBSUFFIX)
# LIB += -lcutil_$(LIB_ARCH) $(LIBSUFFIX) -lshrutil_$(LIB_ARCH) $(LIBSUFFIX)

至此,就可以完成cuda-convnet的編譯了。

更多詳情見請繼續閱讀下一頁的精彩內容: http://www.linuxidc.com/Linux/2014-10/107500p2.htm

Copyright © Linux教程網 All Rights Reserved