CentOS Stream 9
Sponsored Link

TensorFlow : インストール (GPU サポート)2022/08/10

 
機械学習ライブラリー, TensorFlow をインストールします。
コンピューターに搭載の NVIDIA GPU が使用できるようにセットアップします。
[1]
[2]
[3]
cuDNN (CUDA Deep Neural Network library) を NVIDIA 社のサイトからダウンロードしておきます。(ダウンロードにはアカウント登録が必要)
⇒ https://developer.nvidia.com/rdp/cudnn-download
[4] ダウンロードした cuDNN をサーバーにアップロードして、所定の場所へ配置しておきます。
[root@dlp ~]#
tar Jxvf cudnn-linux-x86_64-8.5.0.96_cuda11-archive.tar.xz

[root@dlp ~]#
cp ./cudnn-linux-x86_64-8.5.0.96_cuda11-archive/include/cudnn.h /usr/local/cuda/include/

[root@dlp ~]#
cp -a ./cudnn-linux-x86_64-8.5.0.96_cuda11-archive/lib/libcudnn* /usr/local/cuda/lib64/

[root@dlp ~]#
ldconfig

[5] その他必要なパッケージをインストールしておきます。
Cudart (CUDA Runtime native runtime libraries) は、CUDA 11.7 用も必要となるので、合わせてインストールしておきます。
[root@dlp ~]#
dnf -y install python3-devel gcc gcc-c++ make cuda-cudart-11-7
[6] 任意の一般ユーザーでログインして、TensorFlow インストール用の Python 仮想環境を準備します。
TensorFlow をシステムワイドにインストールする場合は、当作業は不要で、root ユーザーで [7] を実行すれば OK です。
[cent@dlp ~]$
python3 -m venv --system-site-packages ~/tensorflow

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

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

(tensorflow) [cent@dlp ~]$
python3 -c "from tensorflow.python.client import device_lib; device_lib.list_local_devices()"

2022-09-08 16:29:00.277591: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2022-09-08 16:29:00.611075: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:975] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-09-08 16:29:00.683287: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:975] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-09-08 16:29:00.683779: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:975] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-09-08 16:29:01.208884: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:975] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-09-08 16:29:01.209379: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:975] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-09-08 16:29:01.209824: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:975] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-09-08 16:29:01.210231: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1532] Created device /device:GPU:0 with 5391 MB memory:  -> device: 0, name: NVIDIA GeForce GTX 1060 6GB, pci bus id: 0000:05:00.0, compute capability: 6.1

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

2022-09-08 16:29:41.366784: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:975] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-09-08 16:29:41.404263: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:975] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-09-08 16:29:41.404724: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:975] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-09-08 16:29:41.405501: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2022-09-08 16:29:41.406096: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:975] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-09-08 16:29:41.406473: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:975] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-09-08 16:29:41.406812: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:975] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-09-08 16:29:41.906749: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:975] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-09-08 16:29:41.907205: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:975] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-09-08 16:29:41.907692: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:975] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-09-08 16:29:41.908107: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1532] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 5391 MB memory:  -> device: 0, name: NVIDIA GeForce GTX 1060 6GB, pci bus id: 0000:05:00.0, compute capability: 6.1
tf.Tensor(-277.11124, shape=(), dtype=float32)
関連コンテンツ