Tensorflow can't find GPU, Ubuntu

When looking for the GPU inside Pycharm in the environment "tf" with this script:

import tensorflow as tf

print('TensorFlow version:',tf.__version__)
physical_devices = tf.config.list_physical_devices()
for dev in physical_devices:
print(dev)

sys_details = tf.sysconfig.get_build_info()
cuda_version = sys_details["cuda_version"]
print("CUDA version:",cuda_version)
cudnn_version = sys_details["cudnn_version"]
print("CUDNN version:",cudnn_version)
print(tf.config.list_physical_devices("GPU"))

i get the following:

/home/victor/miniconda3/envs/tf/bin/python /home/victor/PycharmProjects/Collect/Code/import tester.py 
2023-02-14 14:23:25.400435: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2023-02-14 14:23:25.991714: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libcudnn.so.8: cannot open shared object file: No such file or directory
2023-02-14 14:23:26.110734: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libcudnn.so.8: cannot open shared object file: No such file or directory
2023-02-14 14:23:26.110751: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
TensorFlow version: 2.11.0
2023-02-14 14:23:26.585477: I tensorflow/compiler/xla/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2023-02-14 14:23:26.752919: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudnn.so.8'; dlerror: libcudnn.so.8: cannot open shared object file: No such file or directory
2023-02-14 14:23:26.752936: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1934] 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...
PhysicalDevice(name='/physical_device:CPU:0', device_type='CPU')
CUDA version: 11.2
CUDNN version: 8
Process finished with exit code 0

When looking outside Pycharm (in the terminal) for Tensorflow with the same script i get:

(tf) victor@victor-ThinkPad-P53:~/Downloads$ python3
Python 3.9.16 (main, Jan 11 2023, 16:05:54) 
[GCC 11.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
import tensorflow as tf
>>> 
>>> print('TensorFlow version:',tf.__version__)
TensorFlow version: 2.11.0
>>> physical_devices = tf.config.list_physical_devices()
>>> for dev in physical_devices:
...     print(dev)
... 
PhysicalDevice(name='/physical_device:CPU:0', device_type='CPU')
PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')
>>> sys_details = tf.sysconfig.get_build_info()
>>> cuda_version = sys_details["cuda_version"]
>>> print("CUDA version:",cuda_version)
CUDA version: 11.2
>>> cudnn_version = sys_details["cudnn_version"]
>>> print("CUDNN version:",cudnn_version)
CUDNN version: 8
>>> print(tf.config.list_physical_devices("GPU"))
[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]


Why am I not able to use Pycharm with GPU support, but outside pycharm it works just fine?

0
Though I haven't used TensorFlow to know how it should be configured for GPU usage, the first thing I would suggest checking is that your code runs in the same environment between PyCharm and external terminal.

To do this, you can run the following snippet in both cases:

```python
import sys
import os

print(sys.executable + '\n')

for i, v in os.environ.items():
print(f'{i}={v}')
```

You can compare the outputs.
0

请先登录再写评论。