检测安装Tensorflow后是否成功调用GPU

在安装好tensorflow及其相关部件后,我们可以通过以下方法去检测Tensorflow是否成功调用了GPU。

 

目录


本人配置注明:

本人tensorflow、CuDA等部件版本如下:

Tensorflow 2.7.0

Python 3.7.11

关于各部件版本对应问题,我会尽快发帖说明。

检测Tensorflow是否调用GPU

方法一

输入以下命令:

import tensorflow.compat.v1 as tf

sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))

[!!!此处需要 import tensorflow.compat.v1 as tf 如果直接 import tensorflow as tf,则会报错’AttributeError: module ‘tensorflow’ has no attribute ‘Session’ ]

Device mapping:

/job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: NVIDIA GeForce RTX 3050 Ti Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.6

2023-03-03 13:20:44.274717: I tensorflow/core/platform/cpu_feature_guard.cc:151] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX AVX2

To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.

2023-03-03 13:20:45.877778: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1525] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 1657 MB memory: -> device: 0, name: NVIDIA GeForce RTX 3050 Ti Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.6

2023-03-03 13:20:54.015703: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1525] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 1657 MB memory: -> device: 0, name: NVIDIA GeForce RTX 3050 Ti Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.6

2023-03-03 13:21:04.540028: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1525] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 1657 MB memory: -> device: 0, name: NVIDIA GeForce RTX 3050 Ti Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.6

2023-03-03 13:25:34.047020: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1525] Created device /device:GPU:0 with 1657 MB memory: -> device: 0, name: NVIDIA GeForce RTX 3050 Ti Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.6

2023-03-03 13:25:34.047944: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1525] Created device /device:GPU:0 with 1657 MB memory: -> device: 0, name: NVIDIA GeForce RTX 3050 Ti Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.6

2023-03-03 13:26:04.474123: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1525] Created device /device:GPU:0 with 1657 MB memory: -> device: 0, name: NVIDIA GeForce RTX 3050 Ti Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.6

2023-03-03 13:27:33.161191: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1525] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 1657 MB memory: -> device: 0, name: NVIDIA GeForce RTX 3050 Ti Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.6

方法二

输入以下命令:

import tensorflow as tf

print(tf.test.is_gpu_available())

若结果返回为True,则显示GPU可用。


以上仅个人在配置使用Tensorflow过程中所作总结,希望对大家有用。

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
青葱年少的头像青葱年少普通用户
上一篇 2023年6月25日
下一篇 2023年6月25日

相关推荐