In [11]: def time_matmul(x):
...: %timeit tf.matmul(x, x)
...:
In [12]: with tf.device("CPU:0"):
...: x = tf.random_uniform([1000, 1000])
...: assert x.device.endswith("CPU:0")
...: time_matmul(x)
...:
The slowest run took 4.25 times longer than the fastest. This could mean that an intermediate result is being cached.
100 loops, best of 3: 8.05 ms per loop
In [13]: with tf.device("GPU:0"):
...: x = tf.random_uniform([1000,1000])
...: assert x.device.endswith("GPU:0")
...: time_matmul(x)
...:
The slowest run took 448.91 times longer than the fastest. This could mean that an intermediate result is being cached.
10000 loops, best of 3: 222 µs per loop
网友评论