CentOS Stream 8
Sponsored Link

TensorFlow : Install (GPU Support)
2021/04/14
 
Install TensorFlow which is the Machine Learning Library.
On this example, Setup TensorFlow to use NVIDIA GPU on your computer.
This example is based on the build configurations like follows.
⇒ TensorFlow 2.2, CUDA 10.2, cuDNN 7.6, Python 3.8
You can see Tested build configurations on the site below.
⇒ https://www.tensorflow.org/install/source?hl=en#gpu_support_2
[1]
[2]
[3]
Download cuDNN (CUDA Deep Neural Network library) from the NVIDIA official site. (it needs to register a developer account)
⇒ https://developer.nvidia.com/rdp/cudnn-download
[4] Upload cuDNN to your Server and locate files like follows.
[root@dlp ~]#
tar zxvf cudnn-10.2-linux-x64-v7.6.5.32.solitairetheme8

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

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

[root@dlp ~]#
ldconfig

[5] Install other required packages.
For Cudart (CUDA Runtime native runtime libraries), it also needs for CUDA 10.1, so install it, too.
[root@dlp ~]#
dnf -y install python38-devel gcc gcc-c++ make cuda-cudart-10-1
[6] Login as a common user and prepare Python virtual environment to install TensorFlow.
If you'd like to install it on System Wide, skip this section and execute the next [7] with root user account.
[cent@dlp ~]$
pip3 install --upgrade virtualenv --user

Collecting virtualenv
  Downloading https://files.pythonhosted.org/packages/91/fb/ca6c071f4231e06a9f0c3bd81c15c233bbacd4a7d9dbb7438d95fece8a1e/virtualenv-20.4.3-py2.py3-none-any.whl (7.2MB)
.....
.....

[cent@dlp ~]$
virtualenv --system-site-packages -p python3 ./venv

created virtual environment CPython3.8.6.final.0-64 in 326ms
  creator CPython3Posix(dest=/home/redhat/venv, clear=False, no_vcs_ignore=False, global=True)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/home/redhat/.local/share/virtualenv)
    added seed packages: pip==21.0.1, setuptools==54.1.2, wheel==0.36.2
  activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator

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

(venv) [cent@dlp ~]$
[7] Install TensorFlow 2.2.
(venv) [cent@dlp ~]$
pip3 install --upgrade tensorflow==2.2
# verify to run TensorFlow

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

2021-04-13 19:25:23.267927: I tensorflow/core/platform/profile_utils/cpu_utils.cc:102] CPU Frequency: 2801530000 Hz
2021-04-13 19:25:23.269486: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7fba34000b60 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2021-04-13 19:25:23.269760: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2021-04-13 19:25:23.277790: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcuda.so.1
2021-04-13 19:25:24.436562: 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
2021-04-13 19:25:24.443703: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x560e614d1d60 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:
2021-04-13 19:25:24.444599: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): GeForce GTX 1070, Compute Capability 6.1
2021-04-13 19:25:24.445256: 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
2021-04-13 19:25:24.445941: 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
2021-04-13 19:25:24.446834: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2021-04-13 19:25:24.460012: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10
2021-04-13 19:25:24.469310: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10
2021-04-13 19:25:24.476401: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcurand.so.10
2021-04-13 19:25:24.488069: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusolver.so.10
2021-04-13 19:25:24.493561: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusparse.so.10
2021-04-13 19:25:24.500401: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
2021-04-13 19:25:24.501100: 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
2021-04-13 19:25:24.502009: 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
2021-04-13 19:25:24.503046: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0
2021-04-13 19:25:24.503478: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2021-04-13 19:25:24.504529: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-04-13 19:25:24.504702: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1108]      0
2021-04-13 19:25:24.504915: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1121] 0:   N
2021-04-13 19:25:24.505390: 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
2021-04-13 19:25:24.506284: 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
2021-04-13 19:25:24.507038: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1247] Created TensorFlow device (/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)

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

2021-04-13 19:26:48.997775: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcuda.so.1
2021-04-13 19:26:49.224078: 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
2021-04-13 19:26:49.225626: 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
2021-04-13 19:26:49.226277: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2021-04-13 19:26:49.228453: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10
2021-04-13 19:26:49.230306: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10
2021-04-13 19:26:49.230852: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcurand.so.10
2021-04-13 19:26:49.233650: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusolver.so.10
2021-04-13 19:26:49.235322: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusparse.so.10
2021-04-13 19:26:49.240647: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
2021-04-13 19:26:49.240810: 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
2021-04-13 19:26:49.241897: 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
2021-04-13 19:26:49.242936: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0
2021-04-13 19:26:49.254526: I tensorflow/core/platform/profile_utils/cpu_utils.cc:102] CPU Frequency: 2801530000 Hz
2021-04-13 19:26:49.255459: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7f7a94000b60 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2021-04-13 19:26:49.255695: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2021-04-13 19:26:49.365346: 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
2021-04-13 19:26:49.366805: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x5597c4293280 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:
2021-04-13 19:26:49.366864: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): GeForce GTX 1070, Compute Capability 6.1
2021-04-13 19:26:49.367696: 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
2021-04-13 19:26:49.368619: 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
2021-04-13 19:26:49.368882: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2021-04-13 19:26:49.369150: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10
2021-04-13 19:26:49.369456: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10
2021-04-13 19:26:49.369728: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcurand.so.10
2021-04-13 19:26:49.370013: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusolver.so.10
2021-04-13 19:26:49.370561: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusparse.so.10
2021-04-13 19:26:49.370830: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
2021-04-13 19:26:49.371284: 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
2021-04-13 19:26:49.371949: 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
2021-04-13 19:26:49.372987: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0
2021-04-13 19:26:49.373072: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2021-04-13 19:26:49.374411: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-04-13 19:26:49.374698: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1108]      0
2021-04-13 19:26:49.374960: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1121] 0:   N
2021-04-13 19:26:49.375666: 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
2021-04-13 19:26:49.376543: 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
2021-04-13 19:26:49.377291: 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(1124.8511, shape=(), dtype=float32)
Matched Content