检查 Tensorflow 是否在 GPU 上运行

检查 Tensorflow 是否在 GPU 上运行

问题描述:

我已经阅读了很多关于如何理解 Tensorflow 是否在 GPU 上运行的问题和指南",但我仍然很困惑.

I have read many questions and "guides" on how to understand if Tensorflow is running on GPU but I am still quite confused.

我截取了我的会话截图,我想了解发生了什么,以及 Tensorflow 是在 GPU 还是 CPU 上运行.

I have taken a screenshot of my session and I would like to understand what is going on, and if Tensorflow is running on GPU or CPU.

Roberto,试试这个

Roberto, try this

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

输出应该是

Default GPU Device: /device:GPU:0

GPU 0 是您的 GTX 860m

GPU 0 is your GTX 860m