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 矩阵乘法速度
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
相关阅读更多精彩内容
- 姓名:丁英琦 学号:17101223408 转载自:http://mp.weixin.qq.com/s/ebxfK...