centos7安装tensorflow-gpu版本

  1. 安装anaconda,建议下载anaconda3 4.2版本,默认python 3.5版本,去清华镜像下载,速度快
    wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-4.2.0-Linux-x86_64.sh
  2. 安装anaconda3,执行命令:
    • 安装命令 bash Anaconda3-4.2.0-Linux-x86_64.sh
    • 根据提示,输入enter,根据提示输入yes 同意license agreement
    • 指定安装路径,可以直接输入enter使用默认安装路径,可以输入自定义路径/work/anaconda3 然后按enter
    • 根据提示输入yes,安装结束
    • 此时Anaconda并未安装完成,若在终端输入python将会发现依然是Centos自带的python版本,这是因为.bashrc的更新还没有生效,执行source ~/.bashrc命令使其生效即可
  3. 验证python版本
    • 执行命令:python便可看到python及anaconda版本信息
      Python 3.5.2 |Anaconda 4.2.0 (64-bit)| (default, Jul  2 2016, 17:53:06)
      [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
      Type "help", "copyright", "credits" or "license" for more information.
      >>> 
      
    • 验证python执行OK
      >>> print("hello world!")
      hello world!
      
  4. 安装显卡驱动
  • 检查是否电脑配置有Nvidia显卡

    $ /usr/sbin/lspci | grep -i nvidia
        执行结果:
        3b:00.0 3D controller: NVIDIA Corporation GP102GL [Tesla P40] (rev a1)
        d8:00.0 3D controller: NVIDIA Corporation GP102GL [Tesla P40] (rev a1)
    
  • 屏蔽默认带有的nouveau
    打开/lib/modprobe.d/dist-blacklist.confnvidiafb注释掉。
    #blacklist nvidiafb,然后添加以下语句:

    blacklist nouveau
    options nouveau modeset=0
    
  • 重建initramfs image步骤

    mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.bak
    dracut /boot/initramfs-$(uname -r).img $(uname -r)
    
  • 修改运行级别为文本模式
    systemctl set-default multi-user.target

  • 查看nouveau是否已经禁用
    ls mod | grep nouveau 如果没有显示相关内容,说明禁用成功

  • 修改运行级别回图形模式 systemctl set-default graphical.target

  • 安装nvidia-detect命令,从ELRepo源安装
    添加源:

    • centos-7 rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
    • CentOS-6 rpm -Uvh http://www.elrepo.org/elrepo-release-6-6.el6.elrepo.noarch.rpm
    • CentOS-5 rpm -Uvh http://www.elrepo.org/elrepo-release-5-5.el5.elrepo.noarch.rpm

    安装:yum install nvidia-detect

  • 检查显卡驱动信息:nvidia-detect -v

    Probing for supported NVIDIA devices...
    [10de:1b38] NVIDIA Corporation GP102GL [Tesla P40]
    This device requires the current 390.48 NVIDIA driver kmod-nvidia
    [10de:1b38] NVIDIA Corporation GP102GL [Tesla P40]
    This device requires the current 390.48 NVIDIA driver kmod-nvidia
    [102b:0536] Matrox Electronics Systems Ltd. Device 0536
    WARNING: Xorg log file /var/log/Xorg.0.log does not exist
    WARNING: Unable to determine Xorg ABI compatibility
    WARNING: The driver for this device does not support the current Xorg version
    

390.48为需安装的显卡版本号,也可以去英伟达官网,下载驱动安装,因为这个版本去yum源里面没有搜索到,我直接去英伟达官网下载cuda相应的驱动
安装地址
tensorflow 1.7版本支持cuda 9.0,因此下载对应cuda9.0的驱动版本
驱动链接

  • yum install -y "kernel-devel-uname-r == $(uname -r)"
  • yum install gcc gcc-c++ 安装gcc、g++编译器
  • 安装驱动:sh NVIDIA-Linux-x86_64-384.125.run
  • 驱动安装成功后使用 nvidia-smi命令查看显卡信息
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 390.46                 Driver Version: 390.46                    |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  Tesla P40           Off  | 00000000:3B:00.0 Off |                    0 |
| N/A   29C    P0    50W / 250W |      0MiB / 22919MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
|   1  Tesla P40           Off  | 00000000:D8:00.0 Off |                    0 |
| N/A   32C    P0    50W / 250W |      0MiB / 22919MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

  • 重新启动, 使用root用户登陆
    reboot

5 .cuda安装 tensorflow1.7支持cuda 9.0,因此需要下载对应的版本

  • 安装地址
  • 安装过程:
    rpm -i cuda-repo-rhel7-9-0-local-9.0.176-1.x86_64-rpm
    yum clean all
    yum install cuda
    

6 .cudnn安装,注册,下载对应版本的cudnn

  • 解压cudnn文件,并将cudnn文件复制到cuda目录
    tar -zxvf cudnn-9.0-linux-x64-v7.1.solitairetheme8
    sudo cp cuda/include/cudnn.h /usr/local/cuda/include/
    sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/ -d
    sudo chmod a+r /usr/local/cuda/include/cudnn.h
    sudo chmod a+r /usr/local/cuda/lib64/libcudnn*
    
  1. 安装tensorflow-gpu
  • 前面已经安装anaconda3,直接使用pip命令安装tensorflow
    pip install tensorflow-gpu  #默认安装最新版本tensorflow-gpu版本
    
  1. 验证tensorflow-gpu安装是否成功
    # python
        Python 3.5.2 |Anaconda 4.2.0 (64-bit)| (default, Jul  2 2016, 17:53:06) 
    [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import tensorflow as tf
    >>> hello = tf.constant('Hello, Tensorflow')
    >>> sess = tf.Session()
    2018-04-09 09:58:07.326972: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 AVX512F FMA
    2018-04-09 09:58:09.165200: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1344] Found device 0 with properties: 
    name: Tesla P40 major: 6 minor: 1 memoryClockRate(GHz): 1.531
    pciBusID: 0000:3b:00.0
    totalMemory: 22.38GiB freeMemory: 22.21GiB
    2018-04-09 09:58:09.383838: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1344] Found device 1 with properties: 
    name: Tesla P40 major: 6 minor: 1 memoryClockRate(GHz): 1.531
    pciBusID: 0000:d8:00.0
    totalMemory: 22.38GiB freeMemory: 22.21GiB
    2018-04-09 09:58:09.387220: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1423] Adding visible gpu devices: 0, 1
    2018-04-09 09:58:10.093199: I tensorflow/core/common_runtime/gpu/gpu_device.cc:911] Device interconnect StreamExecutor with strength 1 edge matrix:
    2018-04-09 09:58:10.093276: I tensorflow/core/common_runtime/gpu/gpu_device.cc:917]      0 1 
    2018-04-09 09:58:10.093289: I tensorflow/core/common_runtime/gpu/gpu_device.cc:930] 0:   N Y 
    2018-04-09 09:58:10.093300: I tensorflow/core/common_runtime/gpu/gpu_device.cc:930] 1:   Y N 
    2018-04-09 09:58:10.094592: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1041] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 21559 MB memory) -> physical GPU (device: 0, name: Tesla P40, pci bus id: 0000:3b:00.0, compute capability: 6.1)
    2018-04-09 09:58:10.352224: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1041] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:1 with 21559 MB memory) -> physical GPU (device: 1, name: Tesla P40, pci bus id: 0000:d8:00.0, compute capability: 6.1)
    >>> print(sess.run(hello))
    b'Hello, Tensorflow'
  • tensorflow-gpu版本安装成功,终于完成
  1. 异常

ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory

  • cuda版本不对,tensorflow1.7支持cuda8.0~9.0版本,重新安装cuda即可

libcudnn.so.7: cannot open shared object file: No such file or directory

  • cuda的路径可能设置错了

sudo ldconfig /usr/local/cuda/lib64

Unable to find the kernel source tree for the currently running kernel. Please make sure you have installed the kernel source files for your kernel and that they are properly configured; on Red Hat Linux systems, for
example, be sure you have the 'kernel-source' or 'kernel-devel' RPM installed. If you know the correct kernel source files are installed, you may specify the kernel source path with the '--kernel-source-path' command line
option.

  • kernel-devel 版本不对,使用此命令安装yum install -y "kernel-devel-uname-r == $(uname -r)"

参考文章:

https://blog.csdn.net/Oh_My_Fish/article/details/78861867
https://www.cnblogs.com/kluan/p/4823152.html
<hr />

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 151,829评论 1 331
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 64,603评论 1 273
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 101,846评论 0 226
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 42,600评论 0 191
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 50,780评论 3 272
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 39,695评论 1 192
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,136评论 2 293
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 29,862评论 0 182
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 33,453评论 0 229
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 29,942评论 2 233
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 31,347评论 1 242
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 27,790评论 2 236
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 32,293评论 3 221
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 25,839评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,448评论 0 181
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 34,564评论 2 249
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 34,623评论 2 249

推荐阅读更多精彩内容