tensorflow with gpu 环境配置

1、准备工作

1.1 确保GPU驱动已经安装

lspci | grep -i nvidia 通过此命令可以查看GPU信息,测试机已经安装GPU驱动
nvidia-smi 可以查看英伟达显卡信息

1.2 确保gcc安装

可以通过gcc -v 查看,如果没有安装需要安装

1.3 确保安装open-ssh

如果没有安装可以通过 yum install openssh-server 安装
1.4 确保安装kernel
 sudo yum install kernel-devel-$(uname -r) kernel-headers-$(uname -r)

2、安装CUDA工具包

To use TensorFlow with NVIDIA GPUs, the first step is to install the CUDA Toolkit.
备注:测试机选用的是CUDA 8.0,不要使用9.x 有坑

3、安装GPU加速器cuDNN

安装完CUDA就可以安装 cuDNN .
备注:这个地方要选用与CUDA版本匹配的加速器;测试机选用的是:Download cuDNN v6.0 (April 27, 2017), for CUDA 8.0,安装步骤如下图所示:

4、安装或更新pip(如果有需要的话,如果已经有了,可以选择性跳过)

TensorFlow itself can be installed using the pip package manager. First, make sure that your system has pip installed and updated:
$ sudo apt-get install python-pip python-dev
$ pip install --upgrade pip

5、安装TensorFlow

Run the following command to install the TensorFlow Python package using pip:
$ pip install --upgrade tensorflow-gpu

6、测试安装是否成功

To test the installation, open an interactive Python shell and import the TensorFlow module:
 
Python 3.5.3 (default, Jun 23 2017, 16:12:41)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> sess = tf.Session()
2017-07-12 19:24:14.030098: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:893] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2017-07-12 19:24:14.030833: I tensorflow/core/common_runtime/gpu/gpu_device.cc:940] Found device 0 with properties:
name: Tesla M40 24GB
major: 5 minor: 2 memoryClockRate (GHz) 1.112
pciBusID 0000:00:06.0
Total memory: 22.40GiB
Free memory: 22.29GiB
2017-07-12 19:24:14.030855: I tensorflow/core/common_runtime/gpu/gpu_device.cc:961] DMA: 0
2017-07-12 19:24:14.030867: I tensorflow/core/common_runtime/gpu/gpu_device.cc:971] 0: Y
2017-07-12 19:24:14.030882: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1030] Creating TensorFlow device (/gpu:0) -> (device: 0, name: Tesla M40 24GB, pci bus id: 0000:00:06.0)
>>> hello_world = tf.constant("Hello, TensorFlow!")
>>> print (sess.run(hello_world))
b'Hello, TensorFlow!'
>>> print (sess.run(tf.constant(123)*tf.constant(456)))
56088
>>>
参考链接

posted on 2018-04-02 13:26  雪 狼  阅读(428)  评论(0编辑  收藏  举报

导航