尝试安装tensorflow以与GPU一起工作。我看到的一些文档说,当检测到时,tensorflow会自带gpu支持。如果是这样,我应该使用什么命令来查看tensorflow是否正在使用我的GPU?我看到其他文档说需要安装tensorflow-gpu。我都尝试过了,但是不知道如何查看我的GPU是否正在被使用?
尝试安装tensorflow以与GPU一起工作。我看到的一些文档说,当检测到时,tensorflow会自带gpu支持。如果是这样,我应该使用什么命令来查看tensorflow是否正在使用我的GPU?我看到其他文档说需要安装tensorflow-gpu。我都尝试过了,但是不知道如何查看我的GPU是否正在被使用?
打开命令行并运行Python
以下示例列出了主机上可见的GPU数量。 文档
import tensorflow as tf
devices = tf.config.list_physical_devices('GPU')
print(len(devices))
针对 CUDA 的文档 Docs
import tensorflow as tf
tf.test.is_built_with_cuda()
返回TensorFlow是否使用了CUDA(GPU)支持进行构建。 文档
您也可以使用以下函数进行检查,但它已被弃用**。
import tensorflow as tf
tf.test.is_gpu_available()
如果您的GPU可用,则两者都返回True。
在此处查找Tensorflow 2 GPU检查,
已弃用,https://www.tensorflow.org/api_docs/python/tf/test/is_gpu_available
https://www.tensorflow.org/api_docs/python/tf/config/list_physical_devices
检查Tensorflow是否支持CUDA(GPU),
https://www.tensorflow.org/api_docs/python/tf/test/is_built_with_cuda
Tensorflow GPU指南,
https://www.tensorflow.org/guide/gpu
import tensorflow as tf
print(tf.config.list_physical_devices('GPU'))
# [PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
print(tf.test.is_built_with_cuda)
# <function is_built_with_cuda at 0x7f4f5730fbf8>
print(tf.test.gpu_device_name())
# /device:GPU:0
print(tf.config.get_visible_devices())
# [PhysicalDevice(name='/physical_device:CPU:0', device_type='CPU'), PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
print(tf.config.list_physical_devices('GPU'))