首页 > 解决方案 > 如何在 PyCharm 中通过 Tensorflow 访问 GPU?

问题描述

我有一个关于在PyCharm中不访问 GPU 的问题,我使用NVIDIA作为GPU

我安装tensorflow-gpuPycharm设置部分的Python 解释器中,然后运行代码,但我仍然无法访问它。

我想知道我是否应该使用 CUDA 库?我该如何解决?

这是我的代码片段,如下所示。

print(tf.config.list_physical_devices('GPU'))

if tf.test.gpu_device_name():
    print('Default GPU Device: {}'.format(tf.test.gpu_device_name()))
else:
    print("Please install GPU version of TF")

这是代码的输出,如下所示。

[]
2021-06-12 23:28:52.693028: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:176] None of the MLIR Optimization Passes are enabled (registered 2)
2021-06-12 23:28:52.702716: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1733] Found device 0 with properties: 
pciBusID: 0000:01:00.0 name: NVIDIA GeForce GTX 1650 Ti computeCapability: 7.5
coreClock: 1.485GHz coreCount: 16 deviceMemorySize: 4.00GiB deviceMemoryBandwidth: 178.84GiB/s
2021-06-12 23:28:52.702905: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1766] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...
Please install GPU version of TF
2021-06-12 23:28:52.816304: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1258] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-06-12 23:28:52.816435: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1264]      0 
2021-06-12 23:28:52.816495: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1277] 0:   N 

标签: pythontensorflowpycharm

解决方案


我解决了我的问题。

以下是解决该问题的步骤。

1 )从https://developer.nvidia.com/cuda-downloads下载CUDA

2 )从https://developer.nvidia.com/rdp/cudnn-download下载CUDNN

3 )从CUDNN zip 文件中复制bin、include和最后的lib并将其粘贴到 C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA{version}

4 ) 然后在PyCharm.py中运行代码,它终于感知到了GPU


推荐阅读