TensorFlow 2.14.1 Not Detecting GPU on Ubuntu 24.04.1 LTS Despite CUDA Drivers Being Installed - Stack Overflow

admin2025-04-17  6

I'm using TensorFlow 2.14.1 on Ubuntu 24.04.1 LTS. When I open a Python terminal and import TensorFlow (import tensorflow as tf), I encounter the following warnings:

I tensorflow/tsl/cuda/cudart_stub:28] Could not find cuda drivers on your machine, GPU will not be used.
E tensorflow/compiler/xla/stream_executor/cuda/cuda_dnn:9342] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered
E tensorflow/compiler/xla/stream_executor/cuda/cuda_dnn:9342] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered

After closing Python, I ran nvidia-smi in the terminal, and my GPU is detected (see image below).

However, when I try to list the physical GPU devices in TensorFlow using:

physical_devices = tf.config.list_physical_devices('GPU')
print("Num GPUs:", len(physical_devices))

I get:

Num GPUs: 0

Has anyone encountered this issue before? Why is TensorFlow not detecting my GPU even though nvidia-smi shows it?

Edit: For those considering closing this question, this is directly related to programming with TensorFlow, a library for building neural networks. The issue prevents me from utilizing the GPU, which is crucial for performance. This seems very much on-topic for Stack Overflow.

转载请注明原文地址:http://www.anycun.com/QandA/1744851228a88508.html