なんとな~くしあわせ?の日記

「そしてそれゆえ、知識そのものが力である」 (Nam et ipsa scientia potestas est.) 〜 フランシス・ベーコン

CUDAプログラミングを試みる

PGIアクセラレータコンパイラ使用のための CUDA 3.0 のインストール(Linux)
ここの下段に書かれているCUDAコマンドの実証はできた。

[kato@photon29 ~]$ which nvcc
/usr/local/cuda/bin/nvcc

(テストプログラム作成)
[kato@photon29 ~]$ vi test.c
main()
{printf("hello\n");}
:wq

[kato@photon29 ~]$ nvcc test.c
hello.c: In function 'main':
hello.c:2: warning: incompatible implicit declaration of built-in function 'printf'

[kato@photon29 ~]$ ./a.out
hello
[kato@photon29 ~]$ ldd a.out (shared library のリンク確認)

次はSDKをインストールしたいのだけどいろいろ困難。
とりあえずNvidiaGPU Computing SDK code samplesの部分からダウンロードしてshコマンドでインストール。SDKを使うにはこいつをmakeしてやらねばならない。参考になりそうなリンクを発見したけれども録画が開始されたのでこのへんでやめておく。
GPGPU/NVIDIA CUDA

追記:結局足りないライブラリを集めてやるとmakeできた。
並列処理に必要なOpenMPIに加えてlibXmu,libXmu-devel,freeglutなどをyumでインストールした。
その後で~/.bashrcのパスをいろいろ加えてやる。下は64bitの場合だと思う。

export PATH=".:~/bin:/usr/local/bin:/usr/bin:$PATH"
export PATH="/usr/local/cuda/bin:$PATH:"
export LD_LIBRARY_PATH="/usr/local/cuda/lib64"
export MANPATH="/usr/share/openmpi/1.2.4-gcc/man"

いまの自分の環境変数はこんな風になっている。

export PATH=$PATH:.:/bin:/usr/local/bin:/usr/local/pgsql/bin:/usr/local/cuda/bin
export MANPATH=$MANPATH:/usr/local/pgsql/man:/usr/lib/openmpi/1.4-gcc/man
export PGDATA=/usr/local/pgsql/data
export LD_LIBRARY_PATH=:/usr/local/pgsql/lib:/usr/local/cuda/lib:/root/NVIDIA_GPU_Computing_SDK/C:$LD_LIBRARY_PATH

そしてお手本通り

[root@cathymaiden C]# ./bin/linux/release/bandwidthTest
[bandwidthTest]
./bin/linux/release/bandwidthTest Starting...

Running on...

Device 0: GeForce GTS 450
Quick Mode

Host to Device Bandwidth, 1 Device(s), Paged memory
Transfer Size (Bytes) Bandwidth(MB/s)
33554432 3182.4

Device to Host Bandwidth, 1 Device(s), Paged memory
Transfer Size (Bytes) Bandwidth(MB/s)
33554432 2388.6

Device to Device Bandwidth, 1 Device(s)
Transfer Size (Bytes) Bandwidth(MB/s)
33554432 36641.2


[bandwidthTest] - Test results:
PASSED


Press to Quit...

                                                                                                                    • -

[root@cathymaiden C]# ./bin/linux/release/matrixMul
[ matrixMul ]
./bin/linux/release/matrixMul Starting...

Device 0: "GeForce GTS 450" with Compute 2.1 capability

Using Matrix Sizes: A(32 x 64), B(32 x 64), C(32 x 64)

Run Kernels...

matrixMul, Throughput = 9.6613 GFlop/s, Time = 0.00001 s, Size = 131072 Ops, NumDevsUsed = 1, Workgroup = 256

Check against Host computation...

PASSED


Press to Quit...

                                                                                                                    • -

とりあえず動いたというところか。