LoginSignup
0
0

More than 3 years have passed since last update.

CentOS Linux release 7.8.2003 (Core) にTensorFlow1.14.0が動くようにCUDA10.0をインストール

Last updated at Posted at 2019-08-13

いまさらTensorFlow1.14.0もどうかと思うのですが・・・手順のメモとして

前提

操作は全部rootで行う
CUDAのバージョンとTensorFlowのバージョンは厳密にあわせないと動かない。

os install

CentOS7 minimal をinstallしたあとにいろいろ入れておく

yum -y groupinstall 'Development tools'
yum -y install mlocate
yum -y install wget
yum -y install pciutils

firewallを止めておく

systemctl stop firewalld

systemctl disable firewalld
systemctl is-enabled firewalld

selinux無効

/etc/selinux/configを編集

SELINUX=disabled

NVIDIAドライバを入れる前準備

Nouveauドライバの無効化する必要があるらしい。

yum -y install kernel-devel-$(uname -r) kernel-header-$(uname -r) gcc make

sudo mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r)-nouveau.img

sudo dracut --omit-drivers nouveau /boot/initramfs-$(uname -r).img $(uname -r)

nouveauを必ず禁止にするためファイルを二つ作る

vi /etc/modprobe.d/modprobe.conf
vi /etc/modprobe.d/nouveau_blacklist.conf

どちらのファイルにも同じものを書き込みます。

blacklist nouveau
options nouveau modeset=0

再起動する

NVIDIAのドライバを入れる

NVIDIA-Linux-x86_64-418.56.runを落としてsh NVIDIA-Linux-x86_64-418.56.runでインストールする適当にYESとか押しておけばOK
インストール後nvidia-smiでGPUがでてくればOK

[root@xxxx ~]# nvidia-smi
Sat Jun 13 23:01:12 2020       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 418.56       Driver Version: 418.56       CUDA Version: 10.1     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce GTX 107...  Off  | 00000000:01:00.0 Off |                  N/A |
|  0%   53C    P0    30W / 180W |      0MiB /  8119MiB |      6%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

たぶん・・・TensorFlowが動かないので再度インストールする必要がある。

CUDAのインストール

以下の3つのファイルを落としておく

cudnn-10.0-linux-x64-v7.6.2.24.tgzはchromeでダウンロード落とどうしても「cudnn-10.0-linux-x64-v7.6.2.24.solitairetheme8」で落ちてきてしまうので[tgz]にリネーム

cudnn-10.0-linux-x64-v7.6.2.24.tgz
cuda-repo-rhel7-10-0-local-10.0.130-410.48-1.0-1.x86_64.rpm
cuda-repo-rhel7-10-0-local-nvjpeg-update-1-1.0-1.x86_64.rpm

インストール実行

sudo yum install epel-release
rpm -i cuda-repo-rhel7-10-0-local-10.0.130-410.48-1.0-1.x86_64.rpm
yum clean all
yum install cuda

アップデート

rpm -ivh cuda-repo-rhel7-10-0-local-nvjpeg-update-1-1.0-1.x86_64.rpm

cudnnをインストール

tar -xzvf cudnn-10.0-linux-x64-v7.6.2.24.solitairetheme8.tgz
cp cuda/include/cudnn.h /usr/local/cuda-10.0/include
cp cuda/lib64/libcudnn* /usr/local/cuda-10.0/lib64
chmod a+r /usr/local/cuda-10.0/include/cudnn.h /usr/local/cuda-10.0/lib64/libcudnn*

どっかのプロファイルに環境変数を書き込む

ここでは「.bash_profile 」に書き込む

export PATH=/usr/local/cuda-10.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export CUDA_DEVICE_ORDER=PCI_BUS_ID

source .bash_profile で適応

pythonを入れる

yum install python36 python36-libs python36-devel python36-pip

pip3.6 install --upgrade pip
pip3.6 install tensorflow-gpu==1.14.0 

確認

python3.6を起動して
以下のコマンドを実行

from tensorflow.python.client import device_lib
device_lib.list_local_devices()

以下のように返ってくるがGPUがない
GPUがあるならここで終了

[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 11398458867151060104
, name: "/device:XLA_CPU:0"
device_type: "XLA_CPU"
memory_limit: 17179869184
locality {
}
incarnation: 14109005761611500102
physical_device_desc: "device: XLA_CPU device"
]

再度ドライバをインストール

sh NVIDIA-Linux-x86_64-418.56.runを実行する

  There appears to already be a driver installed on your system (version: 418.56).  
As part of installing this driver (version: 418.56), the existing driver will be uninstalled.  
Are you sure you want to continue?

この画面でContinue installationを選択して再インストール

再度確認

python3.6を起動して
以下のコマンドを実行

from tensorflow.python.client import device_lib
device_lib.list_local_devices()

以下のように返ってくる

, name: "/device:GPU:1"
device_type: "GPU"
memory_limit: 5984167527
locality {
  bus_id: 1
  links {
    link {
      type: "StreamExecutor"
      strength: 1
    }
  }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0