查看GPU机器可使用的卡信息

深度学习

#1

代码

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")

#2

import tensorflow as tf

with tf.device(’/gpu:0’):

a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)

with tf.Session() as sess:

print (sess.run(c))

#3

Run the following in Jupyter

import tensorflow as tf

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


#4

查看GPU内存使用情况:

watch -n 2 nvidia-smi