1

I've been trying to use GPU with tensorflow on Colaboratory, but when I do

a = tf.constant(np.random.rand(1000,20000))
b = tf.constant(np.random.rand(20000,1000))
with tf.device('/device:GPU:0'):
    c_gpu = tf.matmul(a,b)
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
print(sess.run(c_gpu))

the devices of the operations are not printed, although the result of the operation is. I suspect it is not using the GPU because I had measured the times of the matrix multiplication for both GPU and CPU and compared them.

Daniel Widdis
  • 8,424
  • 13
  • 41
  • 63

1 Answers1

0

No, it is not necessary. In Colaboratory you should check if Runtime -> Change runtime type the parameter Hardware accelerator is GPU.

Then to test if Tensorflow use it, you can see this interesting sample, it works for me: https://stackoverflow.com/a/43703735/9250875

RomRoc
  • 1,465
  • 2
  • 12
  • 12