本来很久以前就在实验室的笔记本上安装好了win10_64+tensorflow1.4+cuda8.0+cudnn6.0+GT610。但是今天跑demo的时候,发现只能在cpu上跑。不知道是不是610显卡太渣了的原因。
回到寝室,就在寝室的电脑上重新装了一边,发现win7_64+tensorflow1.4+cuda8.0+cudnn6.0+GTX1050可以在gpu上跑。
安装:
1.安装GPU版本的tensorflow
方法很简单,直接在控制台中Python3 -m pip install tensorflow-gpu。当然这样安装的是最新版本的tensorflow,目前最新的是1.8。我们这里安装的是tensorflow1.4,在官网https://pypi.org/project/tensorflow/1.4.0/#files下载。然后安装。
2.安装Cuda
这里安装的是cuda8.0.44,在官网https://developer.nvidia.com/cuda-80-download-archive下载。
下载的是个.exe文件,双击安装就可以了。
3.安装cudnn6.0
官网下载https://developer.nvidia.com/rdp/cudnn-archive
这里可能需要注册登录填个调查文件啥的。
下载的是一个.zip文件
解压后有三个文件
将这三个目录下的文件分别拷贝到cuda的安装路径C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0下对应的文件夹中。
4.运行demo
# Creates a graph.# import os# os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"# os.environ['CUDA_VISIBLE_DEVICES'] = '0'import tensorflow as tf# tf.device('/gpu:0')a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')c = tf.matmul(a, b)# Creates a session with log_device_placement set to True.sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))# Runs the op.print(sess.run(c))
看到输出结果
F:\python\python3.exe D:/Python_learn/test1/test.py2018-05-08 23:03:45.547195: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\platform\cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow 电脑 binary was not compiled to use: AVX2018-05-08 23:03:45.844212: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\common_runtime\gpu\gpu_device.cc:1030] Found device 0 with properties: name: GeForce GTX 1050 major: 6 minor: 1 memoryClockRate(GHz): 1.455pciBusID: 0000:01:00.0totalMemory: 2.00GiB freeMemory: 1.49GiB2018-05-08 23:03:45.844212: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\common_runtime\gpu\gpu_device.cc:1120] Creating TensorFlow device (/device:GPU:0) -> (device: 0, name: GeForce GTX 1050, pci bus id: 0000:01:00.0, compute capability: 6.1)Device mapping:/job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: GeForce GTX 1050, pci bus id: 0000:01:00.0, compute capability: 6.1MatMul: (MatMul): /job:localhost/replica:0/task:0/device:GPU:0b: (Const): 电脑 /job:localhost/replica:0/task:0/device:GPU:0a: (Const): /job:localhost/replica:0/task:0/device:GPU:02018-05-08 23:03:45.979220: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\common_runtime\direct_session.cc:299] Device mapping:/job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: GeForce GTX 1050, pci bus id: 0000:01:00.0, compute capability: 6.12018-05-08 23:03:45.981220: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\common_runtime\placer.cc:874] MatMul: (MatMul)/job:localhost/replica:0/task:0/device:GPU:02018-05-08 23:03:45.981220: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\common_runtime\placer.cc:874] b: (Const)/job:localhost/replica:0/task:0/device:GPU:02018-05-08 23:03:45.982220: I 电脑 C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\common_runtime\placer.cc:874] a: (Const)/job:localhost/replica:0/task:0/device:GPU:0[[ 22. 28.] [ 49. 64.]]Process finished with exit code 0
表示安装成功了,是在gpu上运行的。
5.怎么查看tensorflow对应的CUDA和cudnn条件
tensorflow官网https://tensorflow.google.cn/versions/r1.4/install/install_windows查看
电脑