【问题标题】:Tensorflow doesn't seem to see my gpuTensorflow 似乎没有看到我的 gpu
【发布时间】:2017-05-15 02:51:34
【问题描述】:

我已经在 cuda 7.5 和 8.0 上尝试了 tensorflow,没有 cudnn(我的 GPU 很旧,cudnn 不支持它)。

当我执行device_lib.list_local_devices()时,输出中没有gpu。 Theano 看到了我的 gpu,并且可以很好地使用它,并且 /usr/share/cuda/samples 中的示例也可以正常工作。

我通过 pip install 安装了 tensorflow。我的 gpu 是否太旧而无法支持它? gtx 460

【问题讨论】:

  • 几个快速建议: 1. 您是否安装了支持 GPU 的 PIP 包? (例如pip install tensorflow-gpu) 2. 第一次创建tf.Session 时,是否有关于加载CUDA 库的日志消息?
  • 感谢您的快速回复。我安装了 tensorflow-gpu。在会话初始化期间,它向终端写入最低 cuda 计算能力为 3.0,而我的卡有 2.1 :(
  • 我的 gpu 版本有这个错误。

标签: tensorflow


【解决方案1】:

我在 Windows 操作系统上遇到了同样的问题。我按照 tensorflow 关于安装 CUDA、cudnn 等的说明进行操作,并尝试了上述答案中的建议——但没有成功。 解决我的问题的是更新我的 GPU 驱动程序。您可以通过以下方式更新它们:

  1. 按 windows-button + r
  2. 输入devmgmt.msc
  3. 右键单击“显示适配器”并单击“属性”选项
  4. 转到“驱动程序”选项卡并选择“更新驱动程序”。
  5. 最后,点击“自动搜索更新的驱动软件”
  6. 重新启动计算机并再次运行以下检查:
from tensorflow.python.client import device_lib
local_device_protos = device_lib.list_local_devices()
[x.name for x in local_device_protos]
Sample output:
2022-01-17 13:41:10.557751: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1640] Found device 0 with properties:
name: GeForce 940MX major: 5 minor: 0 memoryClockRate(GHz): 1.189
pciBusID: 0000:01:00.0
2022-01-17 13:41:10.558125: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries are statically linked, skip dlopen check.
2022-01-17 13:41:10.562095: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1763] Adding visible gpu devices: 0
2022-01-17 13:45:11.392814: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1181] Device interconnect StreamExecutor with strength 1 edge matrix:
2022-01-17 13:45:11.393617: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1187]      0
2022-01-17 13:45:11.393739: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1200] 0:   N
2022-01-17 13:45:11.401271: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1326] Created TensorFlow device (/device:GPU:0 with 1391 MB memory) -> physical GPU (device: 0, name: GeForce 940MX, pci bus id: 0000:01:00.0, compute capability: 5.0)
>>> [x.name for x in local_device_protos]
['/device:CPU:0', '/device:GPU:0']

【讨论】:

    【解决方案2】:

    在我的例子中,我有一个工作的 tensorflow-gpu 版本 1.14,但它突然停止工作。我使用以下方法解决了问题:

     pip  uninstall tensorflow-gpu==1.14
     pip  install   tensorflow-gpu==1.14
    

    【讨论】:

      【解决方案3】:

      我在 jupyter 笔记本中遇到了同样的问题。这可能很容易解决。

      $ pip uninstall tensorflow
      $ pip install tensorflow-gpu
      

      您可以检查它是否适用于:

      tf.test.gpu_device_name()
      

      2020 年更新

      似乎 tensorflow 2.0+ 带有 gpu 功能,因此 pip install tensorflow 应该够了

      【讨论】:

      • conda install tensorflow-gpu 出现问题后帮助我解决了问题
      • 这对我来说非常有效。我已经正确配置了所有东西,但只安装了 tensorflow 和 tensorflow-gpu。我猜它只使用了 tensorflow,因此之前只列出了我的 CPU。我都卸载了,然后只安装了 tensorflow-gpu。现在我可以看到 CPU 和 GPU 作为函数调用的结果 device_lib.list_local_devices()
      • 不适用于 TensorFlow 2.0+
      • 是的,它不适用于较新版本的 tensorflow。看起来 tnesorflow-gpu 不再是一个包。我认为 2.2 支持开箱即用的 GPU。
      【解决方案4】:

      总结:

      1. 检查 tensorflow 是否看到您的 GPU(可选)
      2. 检查您的显卡是否可以使用 tensorflow(可选)
      3. find versions of CUDA Toolkit and cuDNN SDK, compatible with your tf version
      4. install CUDA Toolkit
      5. install cuDNN SDK
      6. pip 卸载张量流; pip install tensorflow-gpu
      7. 检查 tensorflow 是否看到你的 GPU

      * 来源 - https://www.tensorflow.org/install/gpu

      详细说明:

      1. 检查 tensorflow 是否看到你的 GPU(可选)

        from tensorflow.python.client import device_lib
        def get_available_devices():
            local_device_protos = device_lib.list_local_devices()
            return [x.name for x in local_device_protos]
        print(get_available_devices()) 
        # my output was => ['/device:CPU:0']
        # good output must be => ['/device:CPU:0', '/device:GPU:0']
        
      2. 检查您的卡是否可以使用 tensorflow(可选)

      3. 查找您需要的 CUDA Toolkit 和 cuDNN SDK 版本

        a) 找到你的 tf 版本

        import sys
        print (sys.version)
        # 3.6.4 |Anaconda custom (64-bit)| (default, Jan 16 2018, 10:22:32) [MSC v.1900 64 bit (AMD64)]
        import tensorflow as tf
        print(tf.__version__)
        # my output was => 1.13.1
        

        b) 为您的 tf 版本找到正确的 CUDA Toolkit 和 cuDNN SDK 版本

        https://www.tensorflow.org/install/source#linux
        * it is written for linux, but worked in my case
        see, that tensorflow_gpu-1.13.1 needs: CUDA Toolkit v10.0, cuDNN SDK v7.4
        
      4. 安装 CUDA 工具包

        a) 安装 CUDA Toolkit 10.0

        https://developer.nvidia.com/cuda-toolkit-archive
        select: CUDA Toolkit 10.0 and download base installer (2 GB)
        installation settings: select only CUDA
            (my installation path was: D:\Programs\x64\Nvidia\Cuda_v_10_0\Development)
        

        b) 添加环境变量:

        system variables / path must have:
            D:\Programs\x64\Nvidia\Cuda_v_10_0\Development\bin
            D:\Programs\x64\Nvidia\Cuda_v_10_0\Development\libnvvp
            D:\Programs\x64\Nvidia\Cuda_v_10_0\Development\extras\CUPTI\libx64
            D:\Programs\x64\Nvidia\Cuda_v_10_0\Development\include
        
      5. 安装 cuDNN SDK

        a) 下载 cuDNN SDK v7.4

        https://developer.nvidia.com/rdp/cudnn-archive (needs registration, but it is simple)
        select "Download cuDNN v7.4.2 (Dec 14, 2018), for CUDA 10.0"
        

        b) 将'bin'文件夹的路径添加到“环境变量/系统变量/路径”中:

        D:\Programs\x64\Nvidia\cudnn_for_cuda_10_0\bin
        
      6. pip 卸载 tensorflow pip install tensorflow-gpu

      7. 检查 tensorflow 是否看到你的 GPU

        - restart your PC
        - print(get_available_devices()) 
        - # now this code should return => ['/device:CPU:0', '/device:GPU:0']
        

      【讨论】:

      • 这是一个格式极其复杂的帖子,希望对您没问题。请注意,对于代码块,需要 4 个空格缩进。如果代码块在(无)有序列表中,它必须有 8 个空格才能正确缩进。 Stack Overflowmarkdown 和 Github 有点不同(例如),可以查看here the help topic about it
      • 谢谢你,brasofilo!现在帖子看起来很棒!我将尝试在下一篇文章中应用您的建议。
      【解决方案5】:

      如果您使用的是 conda,您可能已经安装了 tensorflow 的 cpu 版本。检查环境的包列表(conda list),看看是否是这种情况。如果是这样,请使用 conda remove tensorflow 删除软件包并安装 keras-gpu (conda install -c anaconda keras-gpu。这将安装在 GPU 中运行机器学习代码所需的一切。干杯!

      附:您应该首先检查您是否使用nvidia-smi 正确安装了驱动程序。默认情况下,这不在您的 PATH 中,因此您可能还需要将该文件夹添加到您的路径中。 .exe 文件位于C:\Program Files\NVIDIA Corporation\NVSMI

      【讨论】:

      • 这也为我修复了它。主要是因为我拥有的许多依赖项都是错误的版本
      【解决方案6】:

      以下对我有用,惠普笔记本电脑。我有 Cuda Compute 能力 (版本) 3.0 兼容 Nvidia 卡。视窗 7。

      pip3.6.exe uninstall tensorflow-gpu
      pip3.6.exe uninstall tensorflow-gpu
      pip3.6.exe install tensorflow-gpu
      

      【讨论】:

        【解决方案7】:

        当我查看您的 GPU 时,我发现它仅支持 CUDA Compute Capability 2.1。 (可以通过https://developer.nvidia.com/cuda-gpus查看)不幸的是,TensorFlow 需要具有最低 CUDA Compute Capability 3.0 的 GPU。 https://www.tensorflow.org/get_started/os_setup#optional_install_cuda_gpus_on_linux

        您可能会看到 TensorFlow 检查您的 GPU 的一些日志,但最终该库将避免使用不受支持的 GPU。

        【讨论】:

          猜你喜欢
          • 2020-04-20
          • 1970-01-01
          • 2017-05-02
          • 2017-02-09
          • 1970-01-01
          • 2018-03-07
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多