CentOS 8
Sponsored Link

TensorFlow : インストール (GPU サポート)2020/07/23

 
機械学習ライブラリー, TensorFlow をインストールします。
コンピューターに搭載の NVIDIA GPU が使用できるようにセットアップします。
当例では以下の組み合わせでセットアップします。
⇒ TensorFlow 2.2, CUDA 10.1, cuDNN 7.6, Python 3.8
TensorFlow 公式のテスト済みのビルド構成は以下から確認可能です。
⇒ https://www.tensorflow.org/install/source?hl=en#gpu_support_2
[1]
[2]
[3]
cuDNN (CUDA Deep Neural Network library) を NVIDIA 社のサイトからダウンロードしておきます。(ダウンロードにはアカウント登録が必要)
⇒ https://developer.nvidia.com/rdp/cudnn-download
[4] ダウンロードした cuDNN をサーバーにアップロードして、所定の場所へ配置しておきます。
[root@dlp ~]#
tar zxvf cudnn-10.1-linux-x64-v7.6.5.32.tgz

[root@dlp ~]#
cp ./cuda/include/cudnn.h /usr/local/cuda-10.1/include/

[root@dlp ~]#
cp -a ./cuda/lib64/libcudnn* /usr/local/cuda-10.1/lib64/

[root@dlp ~]#
ldconfig

[root@dlp ~]#
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-10.1/extras/CUPTI/lib64' >> /etc/profile.d/cuda101.sh

[root@dlp ~]#
source /etc/profile.d/cuda101.sh

[5] その他必要なパッケージをインストールしておきます。
[root@dlp ~]#
dnf -y install python38-devel python3-virtualenv gcc gcc-c++ make
[6] 任意の一般ユーザーでログインして、TensorFlow インストール用の Python 仮想環境を準備します。
TensorFlow をシステムワイドにインストールする場合は、当作業は不要で、root ユーザーで [7] を実行すれば OK です。
[cent@dlp ~]$
/usr/bin/py3-virtualenv --system-site-packages -p python3 ./venv

Running virtualenv with interpreter /usr/bin/python3
Using base prefix '/usr'
/usr/lib/python3.6/site-packages/virtualenv.py:1043: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import imp
New python executable in /home/cent/venv/bin/python3
Also creating executable in /home/cent/venv/bin/python
Installing setuptools, pip, wheel...done.

[cent@dlp ~]$
source ./venv/bin/activate

(venv) [cent@dlp ~]$
[7] TensorFlow 2.2 をインストールします。
(venv) [cent@dlp ~]$
pip3 install --upgrade tensorflow==2.2.0
# TensorFlow 動作確認

(venv) [cent@dlp ~]$
python3 -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

2020-07-22 19:32:14.249439: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcuda.so.1
2020-07-22 19:32:14.550135: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-07-22 19:32:14.553826: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties:
pciBusID: 0000:05:00.0 name: GeForce GTX 1070 computeCapability: 6.1
coreClock: 1.7845GHz coreCount: 15 deviceMemorySize: 7.93GiB deviceMemoryBandwidth: 238.66GiB/s
2020-07-22 19:32:14.558365: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2020-07-22 19:32:14.569762: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10
2020-07-22 19:32:14.577865: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10
2020-07-22 19:32:14.585534: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcurand.so.10
2020-07-22 19:32:14.596212: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusolver.so.10
2020-07-22 19:32:14.602357: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusparse.so.10
2020-07-22 19:32:14.623688: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
2020-07-22 19:32:14.625668: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-07-22 19:32:14.629147: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-07-22 19:32:14.632464: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0
2020-07-22 19:32:14.646382: I tensorflow/core/platform/profile_utils/cpu_utils.cc:102] CPU Frequency: 2801715000 Hz
2020-07-22 19:32:14.648402: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7f259c000b60 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-07-22 19:32:14.650661: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2020-07-22 19:32:14.761719: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-07-22 19:32:14.764389: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x55aac35432f0 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:
2020-07-22 19:32:14.766704: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): GeForce GTX 1070, Compute Capability 6.1
2020-07-22 19:32:14.768802: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-07-22 19:32:14.771914: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties:
pciBusID: 0000:05:00.0 name: GeForce GTX 1070 computeCapability: 6.1
coreClock: 1.7845GHz coreCount: 15 deviceMemorySize: 7.93GiB deviceMemoryBandwidth: 238.66GiB/s
2020-07-22 19:32:14.775533: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2020-07-22 19:32:14.777365: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10
2020-07-22 19:32:14.779119: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10
2020-07-22 19:32:14.780878: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcurand.so.10
2020-07-22 19:32:14.782656: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusolver.so.10
2020-07-22 19:32:14.784453: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusparse.so.10
2020-07-22 19:32:14.786275: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
2020-07-22 19:32:14.788071: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-07-22 19:32:14.791508: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-07-22 19:32:14.794860: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0
2020-07-22 19:32:14.796393: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2020-07-22 19:32:14.799452: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-07-22 19:32:14.801291: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1108]      0
2020-07-22 19:32:14.802473: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1121] 0:   N
2020-07-22 19:32:14.803807: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-07-22 19:32:14.807194: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-07-22 19:32:14.810579: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1247] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 7554 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1070, pci bus id: 0000:05:00.0, compute capability: 6.1)
tf.Tensor(942.073, shape=(), dtype=float32)
関連コンテンツ