Centos8 运行CUDA10.2+Tensorflow1.15.0

  1. python版本必须正确 截止2019.12.04日 请不要用python3.8.0 版本,
  2. 因为安装不了tensorflow, python 3.6.8 是可以的。

#软件安装过程

  1. Python3.6.8 安装 centos8 自带的,或者从源代码安装
    mkdir -p /var/server/
    cd /var/server
    wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tgz
    tar -zxvf /Python-3.6.8.tgz
    cd /Python-3.6.8
    sudo ./configure --enable-optimizations
    sudo make altinstall
    pip3 install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple

验证是否安装成功 python3

  1. Centos8 NVIDIA 显卡驱动安装
    https://www.nvidia.com/Download/index.aspx?lang=en-us

验证是否安装成功:
nvidia-smi

在这里插入图片描述


Wed Dec  4 04:35:16 2019
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 440.33.01    Driver Version: 440.33.01    CUDA Version: 10.2     |
|-------------------------------+----------------------+----------------------+
| 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 105...  Off  | 00000000:02:00.0  On |                  N/A |
| 62%   66C    P0    N/A /  95W |   4024MiB /  4039MiB |     88%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      1470      G   /usr/libexec/Xorg                             39MiB |
|    0      1840      G   /usr/bin/gnome-shell                          42MiB |
|    0      6996      C   .../tensorflow-gpu-1.15.0/venv/bin/python3  3925MiB |
+-----------------------------------------------------------------------------+
  1. CUDA 10.2 安装
    验证是否安装成功
    cd /usr/local/cuda/samples
    make
    cd 1_Utilities/
    make
    ls
    ./deviceQuery
  deviceQuery  deviceQuery.cpp  deviceQuery.o  Makefile  NsightEclipse.xml  readme.txt
(venv) [root@localhost deviceQuery]# ./deviceQuery
./deviceQuery Starting...

CUDA Device Query (Runtime API) version (CUDART static linking)

Detected 1 CUDA Capable device(s)

Device 0: "GeForce GTX 1050 Ti"
 CUDA Driver Version / Runtime Version          10.2 / 10.2
 CUDA Capability Major/Minor version number:    6.1
 Total amount of global memory:                 4040 MBytes (4235919360 bytes)
 ( 6) Multiprocessors, (128) CUDA Cores/MP:     768 CUDA Cores
 GPU Max Clock rate:                            1493 MHz (1.49 GHz)
 Memory Clock rate:                             3504 Mhz
 Memory Bus Width:                              128-bit
 L2 Cache Size:                                 1048576 bytes
 Maximum Texture Dimension Size (x,y,z)         1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384)
 Maximum Layered 1D Texture Size, (num) layers  1D=(32768), 2048 layers
 Maximum Layered 2D Texture Size, (num) layers  2D=(32768, 32768), 2048 layers
 Total amount of constant memory:               65536 bytes
 Total amount of shared memory per block:       49152 bytes
 Total number of registers available per block: 65536
 Warp size:                                     32
 Maximum number of threads per multiprocessor:  2048
 Maximum number of threads per block:           1024
 Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
 Max dimension size of a grid size    (x,y,z): (2147483647, 65535, 65535)
 Maximum memory pitch:                          2147483647 bytes
 Texture alignment:                             512 bytes
 Concurrent copy and kernel execution:          Yes with 2 copy engine(s)
 Run time limit on kernels:                     Yes
 Integrated GPU sharing Host Memory:            No
 Support host page-locked memory mapping:       Yes
 Alignment requirement for Surfaces:            Yes
 Device has ECC support:                        Disabled
 Device supports Unified Addressing (UVA):      Yes
 Device supports Compute Preemption:            Yes
 Supports Cooperative Kernel Launch:            Yes
 Supports MultiDevice Co-op Kernel Launch:      Yes
 Device PCI Domain ID / Bus ID / location ID:   0 / 2 / 0
 Compute Mode:
    < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 10.2, CUDA Runtime Version = 10.2, NumDevs = 1
Result = PASS
(venv) [root@localhost deviceQuery]# pwd
/usr/local/cuda/samples/1_Utilities/deviceQuery
(venv) [root@localhost deviceQuery]# ./deviceQuery
./deviceQuery Starting...

CUDA Device Query (Runtime API) version (CUDART static linking)

Detected 1 CUDA Capable device(s)
  1. 安装tensorflow
    mkdir -p /var/server/tensorflow-gpu-1.15.0
    cd /var/server/tensorflow-gpu-1.15.0
    python3 -m venv venv
    source venv/bin/activate

pip install tensorflow-gpu -i https://pypi.tuna.tsinghua.edu.cn/simple
或你想用比较低的版本。
pip install tensorflow-gpu=1.15.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

export PATH=/usr/local/cuda/binKaTeX parse error: Expected '}', got 'EOF' at end of input: {PATH:+:{PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:KaTeX parse error: Expected '}', got 'EOF' at end of input: …LIBRARY_PATH:+:{LD_LIBRARY_PATH}}

验证tensorflow-gpu 是否可以正常工作

source /var/server/tensorflow-gpu-1.15.0/venv/bin/activate
#“想要测试tensorflow是否可以使用GPU:”
import tensorflow as tf
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))

然后看到输出:

2019-12-04 09:47:43.083342: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.0
2019-12-04 09:47:43.083399: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcublas.so.10.0'; dlerror: libcublas.so.10.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/local/cuda/lib64:/usr/local/cuda/lib64:/usr/local/cuda/lib64:
2019-12-04 09:47:43.083440: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcufft.so.10.0'; dlerror: libcufft.so.10.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/local/cuda/lib64:/usr/local/cuda/lib64:/usr/local/cuda/lib64:
2019-12-04 09:47:43.083478: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcurand.so.10.0'; dlerror: libcurand.so.10.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/local/cuda/lib64:/usr/local/cuda/lib64:/usr/local/cuda/lib64:
2019-12-04 09:47:43.083516: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcusolver.so.10.0'; dlerror: libcusolver.so.10.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/local/cuda/lib64:/usr/local/cuda/lib64:/usr/local/cuda/lib64:
2019-12-04 09:47:43.083553: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcusparse.so.10.0'; dlerror: libcusparse.so.10.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/local/cuda/lib64:/usr/local/cuda/lib64:/usr/local/cuda/lib64:
2019-12-04 09:47:43.083593: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcudnn.so.7'; dlerror: libcudnn.so.7: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/local/cuda/lib64:/usr/local/cuda/lib64:/usr/local/cuda/lib64:
2019-12-04 09:47:43.083599: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1641] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...

发现很多库都找不到.

依次搜索 每个缺失的lib
find / -name “libcublas.so."
find / -name " libcufft.so.

然后做软链接到/usr/local/cuda/lib64/

ln -s libcudart.so.10.2 libcudart.so.10.0
ln -s libcublas.so.10.2 libcublas.so.10.0
ln -s libcufft.so.10.2 libcufft.so.10.0
ln -s libcurand.so.10.2 libcurand.so.10.0
ln -s libcusolver.so.10.2 libcusolver.so.10.0
ln -s libcusparse.so.10.2 libcusparse.so.10.0
ln -s libcudnn.so.7 libcudnn.so.7

特别注意的是:libcublas.so.10 并不在/usr/local/cuda 目录下,

cudnn 需要手动安装
https://developer.nvidia.com/rdp/cudnn-download

在这里插入图片描述
安装方法 https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html

然后再测试tensorflow-gpu 是否可以正常运行,
source venv/bin/activate
python3
import tensorflow as tf
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))

如果还是出错,
find / -name " libcudnn.so*"
找到实际路径后,一样做个软链接到/usr/local/cuda/lib64 里

至此,终于可以跑起来了。

我运行的show and Tell (看图说话)的模型训练,CPU是 3.7GHZ,8核心的,每秒处理是1.45秒/步 迭代。
用GPU计算后,0.30秒/步,速度提升了大概5倍。

在这里插入图片描述

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论
自编译tensorflow: 1.python3.5,tensorflow1.12; 2.支持cuda10.0,cudnn7.3.1,TensorRT-5.0.2.6-cuda10.0-cudnn7.3; 3.无mkl支持; 软硬件硬件环境:Ubuntu16.04,GeForce GTX 1080 TI 配置信息: hp@dla:~/work/ts_compile/tensorflow$ ./configure WARNING: --batch mode is deprecated. Please instead explicitly shut down your Bazel server using the command "bazel shutdown". You have bazel 0.19.1 installed. Please specify the location of python. [Default is /usr/bin/python]: /usr/bin/python3 Found possible Python library paths: /usr/local/lib/python3.5/dist-packages /usr/lib/python3/dist-packages Please input the desired Python library path to use. Default is [/usr/local/lib/python3.5/dist-packages] Do you wish to build TensorFlow with XLA JIT support? [Y/n]: XLA JIT support will be enabled for TensorFlow. Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]: No OpenCL SYCL support will be enabled for TensorFlow. Do you wish to build TensorFlow with ROCm support? [y/N]: No ROCm support will be enabled for TensorFlow. Do you wish to build TensorFlow with CUDA support? [y/N]: y CUDA support will be enabled for TensorFlow. Please specify the CUDA SDK version you want to use. [Leave empty to default to CUDA 10.0]: Please specify the location where CUDA 10.0 toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: /usr/local/cuda-10.0 Please specify the cuDNN version you want to use. [Leave empty to default to cuDNN 7]: 7.3.1 Please specify the location where cuDNN 7 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda-10.0]: Do you wish to build TensorFlow with TensorRT support? [y/N]: y TensorRT support will be enabled for TensorFlow. Please specify the location where TensorRT is installed. [Default is /usr/lib/x86_64-linux-gnu]://home/hp/bin/TensorRT-5.0.2.6-cuda10.0-cudnn7.3/targets/x86_64-linux-gnu Please specify the locally installed NCCL version you want to use. [Default is to use https://github.com/nvidia/nccl]: Please specify a list of comma-separated Cuda compute capabilities you want to build with. You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus. Please note that each additional compute capability significantly increases your build time and binary size. [Default is: 6.1,6.1,6.1]: Do you want to use clang as CUDA compiler? [y/N]: nvcc will be used as CUDA compiler. Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]: Do you wish to build TensorFlow with MPI support? [y/N]: No MPI support will be enabled for TensorFlow. Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native -Wno-sign-compare]: Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: Not configuring the WORKSPACE for Android builds. Preconfigured Bazel build configs. You can use any of the below by adding "--config=" to your build command. See .bazelrc for more details. --config=mkl # Build with MKL support. --config=monolithic # Config for mostly static monolithic build. --config=gdr # Build with GDR support. --config=verbs # Build with libverbs support. --config=ngraph # Build with Intel nGraph support. --config=dynamic_kernels # (Experimental) Build kernels into separate shared objects. Preconfigured Bazel build configs to DISABLE default on features: --config=noaws # Disable AWS S3 filesystem support. --config=nogcp # Disable GCP support. --config=nohdfs # Disable HDFS support. --config=noignite # Disable Apacha Ignite support. --config=nokafka # Disable Apache Kafka support. --config=nonccl # Disable NVIDIA NCCL support. Configuration finished 编译: bazel build --config=opt --verbose_failures //tensorflow/tools/pip_package:build_pip_package 卸载已有tensorflow: hp@dla:~/temp$ sudo pip3 uninstall tensorflow 安装自己编译的成果: hp@dla:~/temp$ sudo pip3 install tensorflow-1.12.0-cp35-cp35m-linux_x86_64.whl
<h3>回答1:</h3><br/>如果您想在CentOS 8上安装Python 3.6,有两种方法可以使用yum或dnf软件包管理器。在使用这些管理器之前,请确保您具有管理员访问权限。 方法1:使用yum安装Python 3.6 1.安装EPEL存储库 yum install epel-release 2.安装Python3.6 yum install python36 3.查看Python版本号 python3.6 -V 方法2:使用dnf安装Python 3.6 1.启用PowerTools仓库 dnf config-manager --set-enabled PowerTools 2.安装Python3.6 dnf install python3.6 3.查看Python版本号 python3.6 -V 以上两种方法均可在CentOS 8上安装Python3.6,您可以根据自己的需要选择其中一种。使用yum或dnf软件包管理器安装Python 3.6非常方便,并且可以轻松地配置和管理Python解释器。 <h3>回答2:</h3><br/>CentOS 8作为一个基于Red Hat Enterprise Linux 8开发的Linux发行版,标配的Python版本为Python 3.6以上,所以我们不需要进行安装即可使用。但是,有些特定的项目或应用程序需要安装Python 3.6及以上版本来进行开发和运行。下面以CentOS 8系统为例,介绍安装Python 3.6的方法。 使用YUM安装Python 3.6: 1.首先,通过更新yum仓库,使其更新到最新: sudo dnf update 2.安装Python 3.6的依赖项: sudo dnf install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make libffi-devel xz-devel 3.下载并安装Python 3.6源代码: wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz tar xzf Python-3.6.5.tgz cd Python-3.6.5 ./configure --enable-optimizations make altinstall 注意:使用“altinstall”而不是“install”,因为后者将覆盖系统默认的Python版本。 4.验证Python 3.6安装是否成功: python3.6 -V 如果控制台输出Python 3.6.5,则说明已正确安装Python 3.6。 使用dnf安装Python 3.6: 1.添加dnf源: sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm 2.启用Remi库: sudo dnf module reset -y python38 sudo dnf module enable python38:remi 3.安装Python 3.6: sudo dnf install python36 4.验证Python 3.6安装是否成功: python3.6 -V 如果控制台输出Python 3.6.5,则说明已正确安装Python 3.6。 注意:如果您想在系统上同时拥有多个Python版本,建议使用Python虚拟环境来管理它们。虚拟环境可完全隔离不同的Python版本和依赖项,方便程序员进行不同版本Python代码的开发、部署和测试。 <h3>回答3:</h3><br/>安装Python3.6是CentOS 8的一项基本操作,因为Python 3.6是面向对象编程中最流行的语言之一,有很多应用和库都是使用Python 3.6编写的。要安装Python 3.6的方法有很多种,但是本文将介绍最简单的方法:使用yum/dnf命令来安装Python 3.6的rpm包。 步骤1:更新系统 在安装Python 3.6之前,建议更新你的CentOS 8系统。可以输入以下命令来更新软件包库中的所有软件: sudo dnf update 步骤2:添加EPEL和额外的软件包库 要安装Python 3.6,必须添加EPEL和额外的软件包库。可以使用以下命令进行安装: sudo dnf install epel-release sudo dnf config-manager --set-enabled PowerTools 步骤3:安装Python 3.6.rpm包 已经更新过软件包库并添加了必要的软件包库,可以输入以下命令来安装Python 3.6的rpm包: sudo dnf install python36 步骤4:验证安装 在安装完成后,可以通过输入以下命令来测试Python 3.6是否已成功安装: python3.6 -V 输出的结果应该如下: Python 3.6.x 如果成功安装且输出与预期相同,则说明Python 3.6已经成功安装。 总结: 在CentOS 8上安装Python 3.6非常简单,只需要运行上述命令即可完成安装。当然,如果需要安装其他版本的Python,可以下载源代码自行编译安装。无论你选择哪种方法,Python 3.6都是一门非常方便的编程语言,在任何领域都非常有用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

开心自由天使

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值