Cudaを使うときの、ビデオカードのオプション(-ta=tesla:???)の自動判別
Cuda Fortranを使っているんだけど、ビデオカードによる性能の比較をしてみたくて、色々計算してます。その時に困るのが、カードによって引き渡すオプションが違うこと。例えば
ビデオカード オプション GTX660,760 -ta=tesla:cc30 GTX1070,1080 -ta=tesla:cc60
というようになっている。これは、pgaccelinfoコマンドの一番下の行で確認できて、
・・・ Async Engines: 2 Unified Addressing: Yes Managed Memory: Yes PGI Compiler Option: -ta=tesla:cc60
のように出力される。これを計算機ごとに変更していては、非常にめんどくさい。ということで、シェルのファイルで自動判別することにしました。流れとしては、pgaccelinfoで表示するデータからgrepして1行取り出し、決まった文字数以降が(-ta=tesla:cc60)などになるようにして、コンパイル時のオプションに引き渡すようにするという手順です。
comp.bashというファイルの中身を、
#! /bin/bash pgaccelinfo |grep tesla > sss AAA=`cat sss` BBB=${AAA:21} echo $BBB pgfortran -fast -Mcuda=8.0 -acc $BBB sub.cuf main.cuf -lcufft time ./a.out
として、
$ bash ./comp.bash
これでとりあえず動いています。1行目とコマンドラインですが、shではダメです。変数の部分選択をやってくれません。
きっともっと賢い方法があると思うんだけど、調べるのもめんどくさいので、これでいいのです。
Ubuntu14.04に、Cuda8.0をインストールでハマる
GTX1070が付いているマシンにUbuntuを入れて、Cuda8.0をインストールしようとしたんだけど、ハマった。色々やっているうちに、Nvidiaのドライバがうまくインストールできなくて、
$ pgaccelinfo
としても、CUDA Driver VersionとNVRM versionの2行くらいしか表示されなかったり、
# modprobe nvidia
として普通にmoduleを読み込めても、それでもpgaccelinfoでは2行しか表示されなかったり。もう訳が分からなくなったので、Cudaのアンインストールと、nvidiaのアンインストールをして、まっさらな状態から入れなおしたら動きました。具体的には、
1.nvidiaのアンインストール
# nvidia-uninstall # apt-get remove nvidia*
2.Cudaのアンインストール
# /usr/local/cuda/bin/uninstall_cuda_8.0.pl
としてきれいにしてから、とりあえず再起動。
# reboot
3.Nvidiaドライバのインストール
# ./NVIDIA-Linux-x86_64-384.59.run --disable-nouveau
途中で英語で色々聞かれますが、基本そのままでした。
4.Cuda8.0のインストール
./cuda_8.0.61_375.26_linux.run
ここでインストールの際に、NVIDIAのドライバはスキップします。すると最終的に、
Installing the CUDA Toolkit in /usr/local/cuda-8.0 ... =========== = Summary = =========== Driver: Not Selected Toolkit: Installed in /usr/local/cuda-8.0 Samples: Not Selected Please make sure that - PATH includes /usr/local/cuda-8.0/bin - LD_LIBRARY_PATH includes /usr/local/cuda-8.0/lib64, or, add /usr/local/cuda-8.0/lib64 to /etc/ld.so.conf and run ldconfig as root To uninstall the CUDA Toolkit, run the uninstall script in /usr/local/cuda-8.0/bin Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-8.0/doc/pdf for detailed information on setting up CUDA.とWARNINGが出ますが、先に新しいNVIDIAドライバを入れてあるので、WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 361.00 is required for CUDA 8.0 functionality to work.
To install the driver using this installer, run the following command, replacingwith the name of this run file: sudo .run -silent -driver Logfile is /tmp/cuda_install_5632.log # pgaccelinfo CUDA Driver Version: 9000 NVRM version: NVIDIA UNIX x86_64 Kernel Module 384.59 Wed Jul 19 23:53:34 PDT 2017 Device Number: 0 Device Name: GeForce GTX 1070 Device Revision Number: 6.1 Global Memory Size: 8506769408 Number of Multiprocessors: 15 Concurrent Copy and Execution: Yes Total Constant Memory: 65536 Total Shared Memory per Block: 49152 Registers per Block: 65536 Warp Size: 32 Maximum Threads per Block: 1024 Maximum Block Dimensions: 1024, 1024, 64 Maximum Grid Dimensions: 2147483647 x 65535 x 65535 Maximum Memory Pitch: 2147483647B Texture Alignment: 512B Clock Rate: 1746 MHz Execution Timeout: No Integrated Device: No Can Map Host Memory: Yes Compute Mode: default Concurrent Kernels: Yes ECC Enabled: No Memory Clock Rate: 4004 MHz Memory Bus Width: 256 bits L2 Cache Size: 2097152 bytes Max Threads Per SMP: 2048 Async Engines: 2 Unified Addressing: Yes Managed Memory: Yes PGI Compiler Option: -ta=tesla:cc60となり、ちゃんと動くことがわかります。再起動しても、そのままでした。めでたしめでたし。
Ubuntu14.04で、CUIでのログイン設定
cudaをインストールするときに、
Installing the NVIDIA display driver... It appears that an X server is running. Please exit X before installation. If you're sure that X is not running, but are getting this error, please delete any X lock files in /tmp.
と怒られた。どうやら、先にXサーバが動いているので、とりあえず止めてからインストールしてくれということらしい。昔は、/etc/inittabというファイルにrunlevelという項目があって、そこを適当に編集(例えば「5」⇒「3」)に変更すれば、GUIからCUIに変更できた。でもそれが無くなっていて、別の方法が必要みたい。恐らくすぐに忘れるので、メモ。
1./etc/default/grubファイルを一部編集
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" ↓ GRUB_CMDLINE_LINUX_DEFAULT="quiet splash text"
2.grubの変更を反映
# update-grub
以上で、再起動すればCUIでログインできるようになるはず。
研究室で使用する計算機のクライアント設定手順
install後の設定。サーバでNIS、NFSが動いてて、さらにfortranの実行ファイルを実行できるように、calc2のfortranがインストールされている場所をマウントしている。あとは必要なアプリケーション(ここではsshとemacs)をインストール。結構適当ですが、動いています。
1.rootのパスワード設定
# sudo su
2.aptitudeのインストール
# apt-get install aptitude
3.emacsのインストール
# aptitude install emacs
4.sshサーバのインストールと起動
# apt-get install openssh-server # /etc/init.d/ssh restart
5.hostsの編集
/etc/hosts内
127.0.0.1 calc?.testlab.net calc? 172.20.121.1 server.testlab.net server
を追加
6.NFSのインストール、/home1のマウント、/optのマウント(fortranのため)
# aptitude install nfs-common # mkdir /home1 # mount -t nfs server:/home1 /home1 # mount -t nfs calc2:/opt /opt
/etc/fstab内
server:/home1 /home1 nfs auto 0 0 calc2:/opt /opt nfs auto 0 0
を追加
7.fortranの設定(ログイン時にfortranのパスが通っている状態にするため)
/etc/bash.bashrc内
/opt/intel//////(自分の環境に合わせて)
を追加
8.NISの設定
# aptitude -y install nis
途中、ドメイン名を指定(testlab.net)
/etc/yp.conf内
domain testlab.net server server.testlab.net
を追加
/etc/nsswitch.conf内
行の最後に「nis」を追加
passwd: compat nis # 7行目:追記 group: compat nis # 追記 shadow: compat nis # 追記 hosts: files mdns4_minimal [NOTFOUND=return] dns nis # 追記
# initctl restart ypbind 実行
ubuntu16.04でサーバ作ってみようと思う
今研究室で使っているサーバが、ubuntu14で、10年位前のPCにインストールして使ってる。一応、NIS、NFS、sambaが動いていて問題はないんだけど、さすがに古い。ちょっと前までWIEN2k計算機として利用していたi7でメモリ8GのPCがあるので、それをサーバにしたい。現状でubuntu14がインストールされているので、とりあえずubuntu16にアップデートしてみた。
うまく設定できて、時間があったら色々書きます。とりあえず、NISのスレーブは失敗しました。意味わからん。
(2016.12.2追記)
あきらめて、ubuntu14.04をクリーンインストールしました。