赞
踩
好久没看这一块了,最近一直瞎折腾,各种捣鼓,到了这个阶段,迷……
打算测一下cpu和gpu的实际差距,虽然我这gpu一般般,只有2G,但还是想看看能不能来点儿惊喜。
测试代码来自如下平台:
https://databricks.com/tensorflow/using-a-gpu
如果嫌麻烦可以直接copy以下代码:
- #!/usr/bin/env python
- # -*- coding:utf-8 -*-
- import sys
- import tensorflow as tf
- from datetime import datetime
-
- device_name = sys.argv[1] # Choose device from cmd line. Options: gpu or cpu
- shape = (int(sys.argv[2]), int(sys.argv[2]))
- if device_name == "gpu":
- device_name = "/gpu:0"
- else:
- device_name = "/cpu:0"
-
- with tf.device(device_name):
- random_matrix = tf.random_uniform(shape=shape, minval=0, maxval=1)
- dot_operation = tf.matmul(random_matrix, tf.transpose(random_matrix))
- sum_operation = tf.reduce_sum(dot_operation)
-
- startTime = datetim
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。