Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1758958
  • 博文数量: 290
  • 博客积分: 10653
  • 博客等级: 上将
  • 技术积分: 3178
  • 用 户 组: 普通用户
  • 注册时间: 2007-10-24 23:08
文章存档

2013年(6)

2012年(15)

2011年(25)

2010年(86)

2009年(52)

2008年(66)

2007年(40)

分类: LINUX

2009-12-30 11:57:32

sudo echo -e "deb jaunty main\ndeb-src jaunty main" >> /etc/apt/sources.list.d/nvidia-vdpau_ppa.list
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys CEC06767

 Howto install CUDA 2.3 on Ubuntu 9.04
Okay after spending a few days on doing this myself I figured I would share my findings with other people who might be getting a few grey hairs themselves over this process.

Another reason why is that while searching while there are a few guides around the web, they are for older versions of CUDA and/or Ubuntu, and all lacked some package etc. So this is mainly suming up a lot of that work into one place.

I run on a 64bit Ubuntu 9.04, so if someone finds out that something else is needed to make it work on 32bit please feel free to correct me.

Furthermore my machine runs with a single GTX 260 card there may be some complications if you are running a SLI setup.

I did this on a freshly installed Ubuntu 9.04 only thing I did prior was running update manager to get up to speed and the following first reboot.

Computer is rebooted, so let us begin.
First we need to get the CUDA 2.3 files from Nvidia.
http://www.nvidia.com/object/cuda_get.html
Fill in the correct OS and get the 190 driver, toolkit and SDK

(All the stuff that I do here is for getting all three to work, some steps may not be needed if you are not interested in the SDK.)

Putting the Nvidia files in your home dir for the time being. First we need a bunch of packages in order to make the SDK compile properly.

open a terminal and put in

Code:

sudo apt-get install build-essential libglut3-dev

Furthermore we also need to get 3 more packages namely

libxmu-dev
libxmu-headers
libxi-dev

These can be installed with sudo apt-get in a terminal or by finding them in synaptic.

With these downloaded and installed we can continue and install the Nvidia driver. Note that this is on a fresh install and there are more steps to be taken if you are doing it with an older Nvidia driver already installed. There are already posts on the forum about that so I wont go into that here.

To install the 190 driver on a freshly installed box first open a terminal and put in

Code:

chmod +x ./cudadriver_2.3_linux_64_190.18.run

Press Ctrl + Alt + F1 and log in.

shut down gdm.

Code:

sudo /etc/init.d/gdm stop

sudo ./cudadriver_2.3_linux_64_190.18.run

Run the installer by and accepting the OpenGL Compatibility, and xconf file question when prompted.
(You may get a warning when it is searching for conflicting X and OpenGL files, you can only continue and I have not yet had any issues because of it.)
Once it is done start gdm again by typing in

Code:

sudo /etc/init.d/gdm start

That should be it for installing the driver.
Next we need to install the toolkit. To do this we open a terminal and type in

Code:

chmod +x ./cudatoolkit_2.3_linux_64_ubuntu9.04.run

sudo ./cudatoolkit_2.3_linux_64_ubuntu9.04.run

You get to pick your install directory, here I will assume its in the default.

The next step is to add the necessary environment variables. In a terminal type in this. (Just type or copy it in one line at a time!)

Code:

echo "# CUDA stuff
PATH=\$PATH:/usr/local/cuda/bin
LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:/usr/local/cuda/lib64
export PATH
export LD_LIBRARY_PATH" >> ~/.bashrc

Like the toolkit installer says, if you run a 32 bit version you must leave out the 64 part.

Next we install the SDK. In a terminal type in the following.

Code:

chmod +x ./cudasdk_2.3_linux.run
./cudasdk_2.3_linux.run

You dont need to be a superuser to install this.
First you get asked where you want to put the files, and where the CUDA toolkit was installed. (Check that this dir is the same as the one you installed it in, even if it says it located it. The dir need to be the same and not have additions of nvcc or the like!)

Last we need to compile the SDK files. In a terminal type (I assume default install dir)

Code:

cd NVIDIA_GPU_Computing_SDK/C
make

Now it should unpack everything succesfully. You may get a lot of warnings during the process, but these can safely be ignored.
Once it is done you can test that everything does in fact work by going into

Code:

cd NVIDIA_GPU_Computing_SDK/C/bin/linux/release/

and try to run some of the examples in here. Like mentioned in the Nvidia documentation it is a good idead to at least run deviceQuery to verify your CUDA compatible GPU.

I hope that this may help some aspiring CUDA coders out there, and that I have not typed in a whole lot of nonsense since most of Ubuntu is still new to me. If anyone spots some obvious errors please do correct them


sudo aptitude install libxi-dev

 Getting Started

CUDA support includes three main components:

    * Nvidia driver with CUDA support
    * CUDA Toolkit
    * CUDA SDK with code samples

We now provide support for these tools for lab, research group and grad desktop machines, under both Windows and Linux. We administer CUDA differently depending on the machine - please find the case that matches yours below. If you have CUDA support questions that aren't addressed here, please email root.
[edit]
002a Lab
[edit]
Windows

You should find CUDA installed under C:\CUDA. If that directory doesn't exist, or it doesn't contain a subdirectory called NVIDIA_CUDA_SDK, check under C:\Program Files\CUDA and copy the appropriate files/directories to C:\. This is needed because you are not allowed to modify any files in Program Files.

Once you've passed that step, open up C:\CUDA\NVIDIA_CUDA_SDK\projects in Windows Explorer. Go into any of the project directories, and double-click the Visual Studio solution file, which should open up that project in Visual Studio. Try to compile the project. The output at the bottom of the screen will tell you whether the compile was successful or not.

Any of the SDK example projects should compile out of the box. If not, contact your TA; the machine is either not setup correctly, or you did something wrong along the way.

If you get a successful compile, try to run your binary in debug mode (which is the default for Visual Studio). For most projects, a window will pop up with some output (hopefully telling you that everything is fine) and prompting you to hit ENTER to exit. Do so.

Now you can start your own project. Close the example project that you've been working on. Create another directory with a new name under projects. Copy all the files in the project directory you have been working in up to now to that new directory.

Open up the project in the new directory. You should probably rename the project inside Visual Studio to the same name you gave to the directory to avoid future confusion.

Now you can start modifying the code, and see if anything still works after you have done so. :-)
[edit]
Linux

The Nvidia driver and CUDA toolkit are already installed; the toolkit is available at /usr/local/cuda. Follow the instructions for installing a 32-bit copy of the SDK in your home directory at #Installing the CUDA SDK and code samples - the same procedure applies to the 002a machines.
[edit]
Grad desktops

To run CUDA programs on the GPU, you will need a CUDA-capable Nvidia graphics card - a G8X series or greater. These are still relatively rare within the department, so if you're not sure whether your machine is CUDA-ready, it probably isn't. When in doubt, feel free to send mail to root, and we'll take a look at your card and let you know whether it'll work.

Regardless of whether your card supports CUDA, you may install the CUDA Toolkit and SDK on your machine and do development work there. You can even run your programs on the emulator that comes with the CUDA Toolkit, but the emulator is incredibly slow by comparison, so we don't recommend it for anything but lightweight testing.
[edit]
Windows

If you are an administrator on your machine, you can download and install the driver (if applicable; see note above about supported cards), Toolkit and SDK.
[edit]
Linux

If you have a card that supports CUDA, send email to root with your hostname, and we'll give you sudo access for installing and configuring the NVIDIA driver and CUDA Toolkit. Otherwise, you can download the Toolkit and SDK and install them into /usr/local or your home directory.
[edit]
Professor Skadron's research machines
[edit]
Installation Instructions

To set up CUDA tools on a departmental Linux machine, first send mail to root@cs.virginia.edu requesting that the host be added to the CUDA Cfengine group and the main departmental /etc/sudoers file. If you are new to the group, you will also need to request to be added to the CUDA_USERS group of /etc/sudoers.

Once those changes are made on the server, the host will pick up CUDA-related configuration within an hour of being up on the network and booted into Linux. A /cuda directory will be automatically created on the host, which contains the installers for the driver, toolkit and SDK (Note: due to version changes, your /cuda directory may not be identical to this listing).

root@skadrondell3:~# ls /cuda
NVIDIA_CUDA_sdk_2.0beta2_linux.run
NVIDIA_CUDA_Toolkit_2.0beta2_Ubuntu7.10_x86_64.run
NVIDIA_CUDA_Toolkit_2.0_ubuntu7.10_x86.run
NVIDIA-Linux-x86-177.67-pkg1.run
NVIDIA-Linux-x86_64-177.13-pkg2.run
NVIDIA-Linux-x86_64-177.67-pkg2.run

Members of the CUDA_USERS sudo group have the permission to run everything in /cuda, along with several system utilities required for the driver installation.
[edit]
Installing the Nvidia CUDA driver

First, shut down the X server; the Nvidia driver installer requires that X not be running.

sudo killall gdm

Next, find within the /cuda directory the driver installer that matches the architecture of your host - they start with "NVIDIA-Linux". Run "uname -a" if you're unsure of the architecture; x86 machines will list "i686" and x86_64 machines will list "x86_64". As of September 2008, the current version of the Nvidia driver is 177.67. Via sudo, run the installer that matches the host architecture.

i386 example:

sudo /cuda/NVIDIA-Linux-x86-177.67-pkg1.run  

x86_64 example:

sudo /cuda/NVIDIA-Linux-x86_64-177.67-pkg1.run

Select the defaults, and answer yes to the question "Install NVIDIA's 32-bit compatibility OpenGL libraries?" At the end of the installer, you will be asked whether to overwrite your X server settings file (xorg.conf); do so.

Once the driver installer completes, restart the X server:

sudo /etc/init.d/gdm start

[edit]
Installing the CUDA Toolkit

Within the /cuda directory, find the toolkit installer that matches the architecture of your host, and invoke it with sudo. Versions 2.0 and earlier start with "NVIDIA_CUDA_Toolkit"; later versions start with "cudatoolkit".

i386 example:

sudo /cuda/cudatoolkit_2.1_linux32_ubuntu8.04.run

x86_64 example:

sudo /cuda/cudatoolkit_2.1_linux64_ubuntu8.04.run

Accept the defaults. At the end of the installation, you'll see the following notices:

* Please make sure your PATH includes /usr/local/cuda/bin
* Please make sure your LD_LIBRARY_PATH includes /usr/local/cuda/lib

Do so - to change them permanently, edit your .profile to include the following lines:

PATH=/usr/local/cuda/bin:$PATH
LD_LIBRARY_PATH=/usr/local/cuda/lib:$LD_LIBRARY_PATH
export PATH LD_LIBRARY_PATH

[edit]
Installing the CUDA SDK and code samples

In order to give each user the ability to build into and modify code samples provided by the SDK, we recommend installing a copy in each user's home directory for each architecture used for CUDA work. Run it as yourself (without using sudo):

cd ~
/cuda/NVIDIA_CUDA_sdk_2.0beta2_linux.run

The installer will prompt for the toolkit location: /usr/local/cuda. It will also what you want the path to be for the SDK you're setting up; if you'll be using 32-bit and 64-bit CUDA machines, you'll need to maintain two copies of the SDK, so we recommend that you name them appropriately (i.e. ~/NVIDIA_CUDA_SDK-x86 and ~NVIDIA_CUDA_SDK-x86_64).

Run "make" within the "common" directory of the SDK(s) you install in your home directory. Among other things, this builds libcutil.a into the "lib" directory where you installed the SDK and will allow you to build code examples.

: /af13/jlg9n/NVIDIA_CUDA_SDK ; cd common
: /af13/jlg9n/NVIDIA_CUDA_SDK/common ; make

To test the SDK, build the "scan" utility, which will allow you to test your SDK:

: /af13/jlg9n/NVIDIA_CUDA_SDK ; cd projects/scan
: /af13/jlg9n/NVIDIA_CUDA_SDK ; make

Then, cd into the root of the SDK(s) you've installed and run the scan test:

: /af13/jlg9n/NVIDIA_CUDA_SDK ; bin/linux/release/scan

You should see all three scan tests pass:

scan_naive: Test PASSED
scan_workefficient: Test PASSED
scan_best: Test PASSED

If not, send email to root with the output of scan and the path to the copy of the SDK you're using.
[edit]
Notes

As new versions of the driver, toolkit and SDK become available, systems staff can easily add them to the /cuda directory on all of the boxes - just send email to root with the pointer to the new installers, and we'll copy them into the master directory.

You may need to tweak your Xorg configuration to set up the display settings you prefer; the CUDA_USERS sudo group is authorized to run "/usr/bin/nvidia-xsettings", "/usr/bin/nvidia-settings", and "/usr/bin/sudoedit /etc/X11/xorg.conf" via sudo.

For your convenience, the CUDA_USERS sudo group is also authorized to run "/sbin/shutdown" and "/sbin/reboot" for remote boot management.
[edit]
Troubleshooting
[edit]
Libcudart errors

Problem: When executing a CUDA program under Linux, you get the following error:

error while loading shared libraries: libcudart.so.2: cannot open shared object file: No such file or directory

Solution: You need to add the path to the CUDA libraries to your $LD_LIBRARY_PATH environment variable.

Explanation: When a CUDA program is executed, it needs to dynamically link to the CUDA runtime libraries. By default, these libraries are located in the /usr/local/cuda/lib directory. When searching for these libraries, the operating system looks in directories specified in the $LD_LIBRARY_PATH environment variable. If the CUDA library directory is not specified here, the program will fail with the error shown above.

There are two solutions (these assume that you are using the bash shell, which is the default CS Department shell):

1. Run the following command:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib

This change is not persistent and will need to be re-run each time you log in.

2. Edit your .profile file (located at ~/.profile). Find the line that sets the $LD_LIBRARY_PATH variable, which should look similar to the following:

LD_LIBRARY_PATH="/usr/lib:/usr/openwin/lib:/usr/dt/lib:/X11.6/lib:/X11.5/lib:/uva/lib:/gnu/lib"

Modify that line to add the path to the CUDA libraries:

LD_LIBRARY_PATH="/usr/lib:/usr/openwin/lib:/usr/dt/lib:/X11.6/lib:/X11.5/lib:/uva/lib:/gnu/lib:/usr/local/cuda/lib"

After editing the file, you either need to log out and log back in or run the following command:

source ~/.profile

This solution is persistent and only needs to be performed once.
[edit]
Advanced Topics
[edit]
Enabling double-precision

By default, CUDA only supports single-precision floating point arithmetic. You must explicitly enable double-precision support.
[edit]
Choosing among multiple GPUs

When running a CUDA program on a computer with multiple GPUs, your program may not be executed on the most powerful GPU. To maximize performance, you should modify your program to automatically choose the best GPU.
[edit]
Measuring kernel runtime

A naive approach to measuring the runtime of a CUDA kernel may produce wildly inaccurate results. Make sure that you measure runtime correctly.
[edit]
Links 
阅读(3819) | 评论(0) | 转发(0) |
0

上一篇:svn 命令

下一篇:我使用的ubuntu 源

给主人留下些什么吧!~~