今天运行一个UCLA的光流程序,非常耗时间。看到作者在网站上提供了GPU版的,所以希望能使用CUDA加速的版本。今天晚上按照NVidia论坛上的一个教程,成功的配置好了ubuntu 12.04 64bit版的CUDA 4.2. 现将原文分享如下:
http://forums.nvidia.com/index.php?showtopic=231150
Posted 06 June 2012 - 10:40 PM
This post is to give a complete picture on how to install and test CUDA 4.2 on Ubuntu 12.04 64 bit. I have found that everything that needs to be done is quite scattered and needs bringing together to make CUDA more accessible to more novice users such as my self. So if this doesn't work for you please post and let us know and if you know a quicker or better way please enlighten us!!!
Thanks,
CDS
I hope you find this useful and I would like to credit my sources:
FCNS
sn0v
The NVIDIA CUDA Getting Started Guide (Linux)
Note one must have a nVidia GPU which is CUDA capable http://developer.nvidia.com/cuda-gpus
Check is the OS is 32 or 64 bit by running
uname -m
in a terminal. i686 denotes a 32-bit system, and x86_64 denotes a 64-bit one.
Proceed to CUDA Downloads page: http://developer.nvidia.com/cu
For the toolkit, I chose the one titled Ubuntu 11.04, and save all three files in an easy to access location, like your Home folder.
Make sure the requisite tools are installed using the following command :
sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libgl1-mesa-glx libglu1-mesa libglu1-mesa-dev
Next, blacklist the required modules (so that they don’t interfere with the driver installation)
gksu gedit /etc/modprobe.d/blacklist.conf
Add the following lines to the end of the file, one per line:
blacklist amd76x_edac
blacklist vga16fb
blacklist nouveau
blacklist rivafb
blacklist nvidiafb
blacklist rivatv
Save the file and exit gedit.
In order to get rid of any nVidia residuals, run the following command in a terminal:
sudo apt-get remove --purge nvidia*
Once it’s done, reboot your machine. At the login screen, don’t login just yet. Press Ctrl+Alt+F1 to switch to a text-based login. Login and switch to the directory which contains the downloaded drivers, toolkit and SDK. Run the following commands:
sudo service lightdm stop chmod +x devdriver*.run
Follow the onscreen instructions. If the installer throws up an error about nouveau kernel still running, allow it to create a blacklist for nouveau, quit the installation and reboot. In that case, run the following commands again:
sudo service lightdm stop
sudo ./devdriver*.run
The installation should now proceed smoothly. When it asks you if you want the 32-bit libraries and if you want it to edit xorg.conf to use these drivers by default, allow both.
Reboot once the installation completes.
Next, enter the following in a terminal window (in the directory where the files are stored):
sudo chmod +x cudatoolkit*.run
sudo ./cudatoolkit*.run
where cudatoolkit*.run is the full name of the toolkit installer. I recommend leaving the installation path to its default setting (/usr/local/cuda) unless you have a specific reason for not doing so.
The following lines must be added into the .bashrc file in your home directory:
export PATH=/usr/local/cuda/bin:$PATH export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH export LD_LIBRARY_PATH=/usr/lib/nvidia-current:$LD_LIBRARY_PATH export CUDA_ROOT=/usr/local/cuda/bin
SDK must be installed as a regular user (and not as root) to prevent access issues with the SDK files.
Once the toolkit is installed, enter the following in a terminal:
sudo chmod +x gpucomputingsdk*.run
sudo ./gpucomputingsdk*.run
where gpucomputingsdk*.run is the full name of the SDK installer. Again, follow the instructions onscreen to complete the installation.
Since there are several linking errors in this compilation several modifications must be make. You are made aware of this when you change your working directory to NVIDIA_GPU_Computing_SDK in your home directory and then run:
sudo make
This will result in the following error:
../../lib/librendercheckgl_x86_64.a(rendercheck_gl. cpp.o): In function `CheckBackBuffer::checkStatus(char const*, int, bool)': rendercheck_gl.cpp:(.text+0xfbb): undefined reference to `gluErrorString'
The fix is contained in the following three steps.
1) change the order for all occurrences of RENDERCHECKLIB in BOTH /C/common/common.mk and /CUDALibraries/common/common_cudalib.mk like this:
OLD:
LIB += ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) ${LIB} -ldl -rdynamic
NEW:
LIB += $(RENDERCHECKGLLIB) ${OPENGLLIB} $(PARAMGLLIB) ${LIB} -ldl –rdynamic
and add -L../../../C/lib in common_cudalib.mk RENDERCHECKGLLIB definition line:
OLD:
RENDERCHECKGLLIB := -lrendercheckgl_$(LIB_ARCH)$(LIBSUFFIX)
NEW:
RENDERCHECKGLLIB := -L../../../C/lib -lrendercheckgl_$(LIB_ARCH)$(LIBSUFFIX)
2) In all files that use UtilNPP (boxFilterNPP, imageSegmentationNPP, freeImageInteropNPP, histEqualizationNPP), the makefiles have the wrong order of library linking ($LIB is before the source/out files), so go to the /CUDALibraries/src/*NPP/Makefile and change the order like (note this is an example of the freeImageInteropNPP file modification, all others are done similarly):
OLD:
$(CXX) $(INC) $(LIB) -o freeImageInteropNPP freeImageInteropNPP.cpp -lUtilNPP_$(LIB_ARCH) -lfreeimage$(FREEIMAGELIBARCH)
NEW:
$(CXX) $(INC) -o freeImageInteropNPP freeImageInteropNPP.cpp $(LIB) -lUtilNPP_$(LIB_ARCH) -lfreeimage$(FREEIMAGELIBARCH)
3) For randomFog, you also need to add
USERENDERCHECKGL := 1
to the Makefile.
Now go back to the working directory NVIDIA_GPU_Computing_SDKand run
make
, this will take some time to fully compile to be patient. Also the compiler will throw several warning but these should be ignored.
The version of the CUDA Toolkit can be checked by running
nvcc -V
in a terminal window. The nvcc command runs the compiler driver that compiles CUDA programs. It calls the gcc compiler for C code and the NVIDIA PTX compiler for the CUDA code.
NVIDIA includes sample programs in source form in the GPU Computing SDK. You should compile them all by changing to ~/NVIDIA_GPU_Computing_SDK/Cand running
sudo make
. The resulting binaries will be installed in ~/NVIDIA_GPU_Computing_SDK/C/bin/linux/release.
After compilation, go to ~/NVIDIA_GPU_Computing_SDK/C/bin/linux/release and run
deviceQuery
. If the CUDA software is installed and configured correctly, the output for deviceQuery should look similar to that shown in Figure 1 of the reference guide provided by NVIDIA. The exact appearance and the output lines might be different on your system. The important outcomes are that a device was found (the first highlighted line), that the device matches the one on your system (the second highlighted line), and that the test passed (the final highlighted line). If a CUDA-enabled device and the CUDA Driver are installed but deviceQuery reports that no CUDA-capable devices are present, this likely means that the /dev/nvidia* files are missing or have the wrong permissions.
http://www.bfcat.com/index.php/2012/06/ubuntu-12-04-cuda-4-2/