windows TensorFlow GPU版本的安装|TensorFlow can't cudat80_64.dll

来源:互联网 发布:乐乎lofter帅哥 编辑:程序博客网 时间:2024/05/20 10:15

安装的版本可能是cuda9.0,推荐重新安装cuda8.0

分为三个步骤:
1 . 第一步 安装CUDA
下载CUDA并安装:
各个版本的CUDA :https://developer.nvidia.com/cuda-toolkit-archive

2 . 第二步 安装 cudnn

cudnn 各个下载连接:https://developer.nvidia.com/rdp/cudnn-download#a-collapse6-8

下载好之后,解压,里面有三个文件夹,分别把里面三个文件夹里面的文件复制到CUDA所安装的目录对于的同名文件夹中。在下载软件包的时候,需要注意cuda8对应 cudnn6,cuda9 对应cudnn7。同时也要注意tensorflow-gpu的版本,本人的是1.4.0, 对应cuda8和cudnn6.

可以使用下面代码进行检测:

import ctypesimport impimport sysdef main():    try:        import tensorflow as tf        print("TensorFlow successfully installed.")        if tf.test.is_built_with_cuda():            print("The installed version of TensorFlow includes GPU support.")        else:            print("The installed version of TensorFlow does not include GPU support.")        sys.exit(0)    except ImportError:        print("ERROR: Failed to import the TensorFlow module.")    candidate_explanation = False    python_version = sys.version_info.major, sys.version_info.minor    print("\n- Python version is %d.%d." % python_version)    if not (python_version == (3, 5) or python_version == (3, 6)):        candidate_explanation = True        print("- The official distribution of TensorFlow for Windows requires "              "Python version 3.5 or 3.6.")    try:        _, pathname, _ = imp.find_module("tensorflow")        print("\n- TensorFlow is installed at: %s" % pathname)    except ImportError:        candidate_explanation = False        print(""" - No module named TensorFlow is installed in this Python environment. You may   install it using the command `pip install tensorflow`.""")    try:        msvcp140 = ctypes.WinDLL("msvcp140.dll")    except OSError:        candidate_explanation = True        print(""" - Could not load 'msvcp140.dll'. TensorFlow requires that this DLL be   installed in a directory that is named in your %PATH% environment   variable. You may install this DLL by downloading Microsoft Visual   C++ 2015 Redistributable Update 3 from this URL:   https://www.microsoft.com/en-us/download/details.aspx?id=53587""")    try:        cudart64_80 = ctypes.WinDLL("cudart64_80.dll")    except OSError:        candidate_explanation = True        print(""" - Could not load 'cudart64_80.dll'. The GPU version of TensorFlow   requires that this DLL be installed in a directory that is named in   your %PATH% environment variable. Download and install CUDA 8.0 from   this URL: https://developer.nvidia.com/cuda-toolkit""")    try:        nvcuda = ctypes.WinDLL("nvcuda.dll")    except OSError:        candidate_explanation = True        print(""" - Could not load 'nvcuda.dll'. The GPU version of TensorFlow requires that   this DLL be installed in a directory that is named in your %PATH%   environment variable. Typically it is installed in 'C:\Windows\System32'.   If it is not present, ensure that you have a CUDA-capable GPU with the   correct driver installed.""")    cudnn5_found = False    try:        cudnn5 = ctypes.WinDLL("cudnn64_5.dll")        cudnn5_found = True    except OSError:        candidate_explanation = True        print(""" - Could not load 'cudnn64_5.dll'. The GPU version of TensorFlow   requires that this DLL be installed in a directory that is named in   your %PATH% environment variable. Note that installing cuDNN is a   separate step from installing CUDA, and it is often found in a   different directory from the CUDA DLLs. You may install the   necessary DLL by downloading cuDNN 5.1 from this URL:   https://developer.nvidia.com/cudnn""")    cudnn6_found = False    try:        cudnn = ctypes.WinDLL("cudnn64_6.dll")        cudnn6_found = True    except OSError:        candidate_explanation = True    if not cudnn5_found or not cudnn6_found:        print()        if not cudnn5_found and not cudnn6_found:            print("- Could not find cuDNN.")        elif not cudnn5_found:            print("- Could not find cuDNN 5.1.")        else:            print("- Could not find cuDNN 6.")            print("""   The GPU version of TensorFlow requires that the correct cuDNN DLL be installed   in a directory that is named in your %PATH% environment variable. Note that   installing cuDNN is a separate step from installing CUDA, and it is often   found in a different directory from the CUDA DLLs. The correct version of   cuDNN depends on your version of TensorFlow:   * TensorFlow 1.2.1 or earlier requires cuDNN 5.1. ('cudnn64_5.dll')   * TensorFlow 1.3 or later requires cuDNN 6. ('cudnn64_6.dll')   You may install the necessary DLL by downloading cuDNN from this URL:   https://developer.nvidia.com/cudnn""")    if not candidate_explanation:        print(""" - All required DLLs appear to be present. Please open an issue on the   TensorFlow GitHub page: https://github.com/tensorflow/tensorflow/issues""")    sys.exit(-1)if __name__ == "__main__":    main()

3. 第三步 安装tensorfolw-gpu
官方的安装说明:https://www.tensorflow.org/install/install_windows

笔者使用pip 进行安装:

pip3 install --upgrade tensorflow-gpu

检测是否成功安装使用 tensorflow-gpu

import tensorflow as tfhello = tf.constant('Hello, TensorFlow!')sess = tf.Session()print(sess.run(hello))

输出:

2017-12-21 15:58:53.856201: 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.88GiB2017-12-21 15:58:53.856201: 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)b'Hello, TensorFlow!'
阅读全文
0 0
原创粉丝点击