CentOS 5.8 に CUDA 開発環境を導入する

CentOS 5.8 (64bit版) に CUDA 開発環境を導入する。 導入環境は以下の通り。

  • CentOS release 5.8 (Final)
  • GeForce GTX 580
  • gcc (GCC) 4.1.2 (Red Hat 4.1.2-52)
  • g++ (GCC) 4.1.2 (Red Hat 4.1.2-52)

 

GPU の確認

CUDA 開発環境を導入する前に GPU が CUDA に対応しているかの確認を行う。 CUDA に対応している GPU の一覧は CUDA GPUs にまとめられている。

GPU の型番は以下のコマンドで確認することができる。

# lspci | grep NVIDIA
02:00.0 VGA compatible controller: NVIDIA Corporation GF110 [GeForce GTX 580] (rev a1)
02:00.1 Audio device: NVIDIA Corporation GF110 High Definition Audio Controller (rev a1)

 

必要なファイルのダウンロード

今回は CUDA 4.0 を導入するので, CUDA Toolkit 4.0 から以下のファイルをダウンロードする。

  • Developer Drivers for Linux (270.41.19)
  • CUDA Toolkit for RedHat Enterprise Linux 5.5
  • GPU Computing SDK - complete package including all code samples

 

Developer Drivers のインストール

CUDA のドライバは, X-Windowシステムを停止させた状態でインストールする。

# init 3
# chmod +x *.run

# ./devdriver_4.0_linux_64_270.41.19.run
ERROR: Unable to find the kernel source tree for the currently running kernel.  Please make
       sure you have installed the kernel source files for your kernel and that they are  
       properly configured; on Red Hat Linux systems, for example, be sure you have the   
       'kernel-source' or 'kernel-devel' RPM installed.  If you know the correct kernel   
       source files are installed, you may specify the kernel source path with the        
       '--kernel-source-path' command line option.

kernel-source か kernel-devel をインストールして, その PATH を指定する必要がある模様。
既に kernel-devel がインストールされてたので kernel source の場所を確認して, 再度 Developer Drivers のインストールを行う。

# ls /usr/src/kernels/
2.6.18-308.16.1.el5-x86_64

# ./devdriver_4.0_linux_64_270.41.19.run --kernel-source-path=/usr/src/kernels/2.6.18-308.16.1.el5-x86_64

インストール時にライセンスの確認(Accept), インストールの確認(Yes) をそれぞれ選択。 最後にインストール完了(OK) を選択で終了。

 

CUDA Toolkit のインストール

CUDA Toolkit のインストールと PATH の設定を行う。

# ./cudatoolkit_4.0.17_linux_64_rhel5.5.run
...
Enter install path (default /usr/local/cuda, '/cuda' will be appended): [Enter]
A previous version of CUDA was found in /usr/local/cuda/bin
Would you like to uninstall? (yes/no/abort): Yes

(省略)

* Please make sure your PATH includes /usr/local/cuda/bin
* Please make sure your LD_LIBRARY_PATH
*   for 32-bit Linux distributions includes /usr/local/cuda/lib
*   for 64-bit Linux distributions includes /usr/local/cuda/lib64:/usr/local/cuda/lib
* OR
*   for 32-bit Linux distributions add /usr/local/cuda/lib
*   for 64-bit Linux distributions add /usr/local/cuda/lib64 and /usr/local/cuda/lib
* to /etc/ld.so.conf and run ldconfig as root
* Please read the release notes in /usr/local/cuda/doc/

* To uninstall CUDA, delete /usr/local/cuda
* Installation Complete

 

PATH の設定

インストールに成功すると上記のようなメッセージが表示されるので, PATH と LD_LIBRARY_PATH の設定を行う。

# emacs -nw /etc/profile.d/cuda.sh
# cat /etc/profile.d/cuda.sh
#!/bin/bash

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

 

GPU Computing SDK のインストール

最後に SDK のインストールを行う。 ここでは個人のホームディレクトリにインストールを行なっていく。

$ ./gpucomputingsdk_4.0.17_linux.run
...
Enter install path (default ~/NVIDIA_GPU_Computing_SDK): [Enter]

Located CUDA at /usr/local/cuda
If this is correct, choose the default below.
If it is not correct, enter the correct path to CUDA

Enter CUDA install path (default /usr/local/cuda): [Enter]

(省略)

* Please make sure your PATH includes /usr/local/cuda/bin
* Please make sure your LD_LIBRARY_PATH includes /usr/local/cuda/lib
* To uninstall the NVIDIA GPU Computing SDK, please delete /home/crisis/NVIDIA_GPU_Computing_SDK
* Installation Complete

 

ライブラリとサンプルの make

はじめにライブラリの make から。
~/NVIDIA_GPU_Computing_SDK/C/common にある Makefile を実行することで CUDA 開発で必要なライブラリが生成される。

$ cd ~/NVIDIA_GPU_Computing_SDK/C/common
$ make
a - obj/x86_64/release/bank_checker.cpp.o
a - obj/x86_64/release/cmd_arg_reader.cpp.o
a - obj/x86_64/release/cutil.cpp.o
a - obj/x86_64/release/stopwatch.cpp.o
a - obj/x86_64/release/stopwatch_linux.cpp.o
a - obj/x86_64/release/multithreading.cpp.o

$ cd ../lib
$ sudo cp libcutil_x86_64.a /usr/local/cuda/lib64

つぎにサンプルの make を行なっていく。
すべてのサンプルを make したいので, ~/NVIDIA_GPU_Computing_SDK/C にある Makefile を実行する。

$ cd ~/NVIDIA_GPU_Computing_SDK/C
$ make
(省略)
/usr/bin/ld: cannot find -lXi
collect2: ld はステータス 1 で終了しました
make[1]: *** [../../bin/linux/release/FunctionPointers] エラー 1
make[1]: ディレクトリ `/home/crisis/NVIDIA_GPU_Computing_SDK/C/src/FunctionPointers' から出ます
make: *** [src/FunctionPointers/Makefile.ph_build] エラー 2

ライブラリが足りないと上記のようなエラーとなる。
今回は /usr/bin/ld: cannot find -lXi というエラーなので, libXi-devel を yum 等で追加してやれば解決できる。

$ sudo yum -y install libXi-devel

$ make
(省略)
/usr/bin/ld: cannot find -lXmu
collect2: ld はステータス 1 で終了しました
make[1]: *** [../../bin/linux/release/FunctionPointers] エラー 1
make[1]: ディレクトリ `/home/crisis/NVIDIA_GPU_Computing_SDK/C/src/FunctionPointers' から出ます
make: *** [src/FunctionPointers/Makefile.ph_build] エラー 2

$ sudo yum -y install libXmu-devel
$ make
(省略)
Finished building all

以上で CUDA 開発環境の導入とサンプルプログラムの make が完了。 最後に動作確認をしておきます。

 

動作確認

GPU 情報の取得/表示を行う deviceQuery というサンプルプログラムで動作確認を行う。

$ cd ~/NVIDIA_GPU_Computing_SDK/C/bin/linux/release/
$ ./deviceQuery
./deviceQuery Starting...

 CUDA Device Query (Runtime API) version (CUDART static linking)

cudaGetDeviceCount returned 38
-> no CUDA-capable device is detected
[deviceQuery] test results...
FAILED

Press ENTER to exit…

「CUDA に対応したデバイスがない…」って感じかな?
そんなはずはないと調べてみると, 同じ症状の方が居ました。

ドキュメントのpdfを見たらGUIを使っていない場合は/dev/nvidia*のデバイスファイルを手動で確保しないといけないらしくドキュメントに記載されているシェルを実行する必要があったみたいだ。 (引用: 自宅サーバのcuda環境を3.2→4.0にバージョンアップ)

引用サイトに記載されていたシェルスクリプトを実行後, 再度 deviceQuery を実行。

$ ./deviceQuery
[deviceQuery] starting...
./deviceQuery Starting...

 CUDA Device Query (Runtime API) version (CUDART static linking)

Found 1 CUDA Capable device(s)

Device 0: "GeForce GTX 580"
  CUDA Driver Version / Runtime Version          4.0 / 4.0
  CUDA Capability Major/Minor version number:    2.0
  Total amount of global memory:                 1535 MBytes (1609760768 bytes)
  (16) Multiprocessors x (32) CUDA Cores/MP:     512 CUDA Cores
  GPU Clock Speed:                               1.59 GHz

(省略)

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 4.0, CUDA Runtime Version = 4.0, NumDevs = 1, Device = GeForce GTX 580
[deviceQuery] test results...
PASSED

Press ENTER to exit...

今度は問題なく実行できた。 以上で動作確認終了。

 

参考URL

Comments