Skip to content

Instantly share code, notes, and snippets.

@manparvesh
Created May 31, 2019 16:57
Show Gist options
  • Save manparvesh/b71c5396b97bd42b294ac66d8a264c6b to your computer and use it in GitHub Desktop.
Save manparvesh/b71c5396b97bd42b294ac66d8a264c6b to your computer and use it in GitHub Desktop.
Testing if tensorflow is using GPU acceleration
import tensorflow as tf
# If this program does not throw any error while running, it means GPU acceleration is being used.
# If there is an error message after running this program, you need to check you graphics driver settings
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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment