美文网首页
比对 CPU 和 GPU 矩阵乘法速度

比对 CPU 和 GPU 矩阵乘法速度

作者: 朱小虎XiaohuZhu | 来源:发表于2018-09-25 14:06 被阅读177次
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

相关文章

网友评论

      本文标题:比对 CPU 和 GPU 矩阵乘法速度

      本文链接:https://www.haomeiwen.com/subject/ibfloftx.html