tensorflow GPU小测试
来源:互联网 发布:wps数据透视表求和 编辑:程序博客网 时间:2024/06/06 01:06
tensorflow GPU小测试
简单测试了一下tensorflow的GPU计算和CPU计算的区别。这里的计算例子只非常简单的小规模矩阵相乘,但是也体现出了CPU和GPU算力的差距,代码及结果如下:
import tensorflow as tfimport datetime#running# Creates a graph.(cpu version)print('cpu version')starttime1 = datetime.datetime.now()with tf.device('/gpu:0'): a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0,1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[6, 9], name='a') b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0,1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[9, 6], name='b') c = tf.matmul(a, b) c = tf.matmul(c,a) c = tf.matmul(c,b)# Creates a session with log_device_placement set to True.sess1 = tf.Session(config=tf.ConfigProto(log_device_placement=True))# Runs the op.for i in range(59999): sess1.run(c)print(sess1.run(c))sess1.close()endtime1 = datetime.datetime.now()time1 = (endtime1 - starttime1).microseconds#print('time1:',time1)#############################################print('gpuversion')# Creates a graph.(gpu version)starttime2 = datetime.datetime.now()#runningwith tf.device('/gpu:0'): a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0,1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[6, 9], name='a') b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0,1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[9, 6], name='b') c = tf.matmul(a, b) c = tf.matmul(c,a) c = tf.matmul(c,b)# Creates a session with log_device_placement set to True.sess2 = tf.Session(config=tf.ConfigProto(log_device_placement=True))# Runs the op.for i in range(59999): sess2.run(c)print(sess2.run(c))sess2.close()endtime2 = datetime.datetime.now()time2 = (endtime2 - starttime2).microsecondsprint('time1:',time1)print('time2:',time2)
结果如下:
cpu version[[ 18225. 36450. 54675. 72900. 91125. 109350.] [ 24300. 48600. 72900. 97200. 121500. 145800.] [ 18225. 36450. 54675. 72900. 91125. 109350.] [ 24300. 48600. 72900. 97200. 121500. 145800.] [ 18225. 36450. 54675. 72900. 91125. 109350.] [ 24300. 48600. 72900. 97200. 121500. 145800.]]gpuversion[[ 18225. 36450. 54675. 72900. 91125. 109350.] [ 24300. 48600. 72900. 97200. 121500. 145800.] [ 18225. 36450. 54675. 72900. 91125. 109350.] [ 24300. 48600. 72900. 97200. 121500. 145800.] [ 18225. 36450. 54675. 72900. 91125. 109350.] [ 24300. 48600. 72900. 97200. 121500. 145800.]]time1: 356158time2: 363249
注:以上时间单位是微秒
阅读全文
0 0
- tensorflow GPU小测试
- tensorflow-gpu
- Window10安装TensorFlow(GPU)与可行性测试
- tensorflow gpu使用说明
- 安装windows tensorflow-gpu
- Install GPU Tensorflow
- Tensorflow gpu 安装
- windows gpu tensorflow anaconda
- TensorFlow(GPU) 安装
- win10+ubutun+tensorflow+gpu
- TensorFlow GPU版安装
- tensorflow-gpu SSE
- TensorFlow gpu加速问题
- tensorflow gpu使用说明
- Tensorflow多GPU
- Tensorflow GPU win7
- tensorflow GPU环境配置
- Ubuntu16.0.4+Tensorflow-GPU
- Http协议常见的数字错误 200、400、401、403、404、500、503等
- @Autowired与@Resource区别
- Tensorflow在ubuntu16.04下的安装(GPU加速版)
- Java简单过滤敏感不雅文字
- 更改Ubuntu默认python版本
- tensorflow GPU小测试
- 基于Java发送邮件
- 随笔
- 巧妙利用PSR监控Windows桌面
- 3次握手4四断开笔记
- js中的ajax技术
- json:java对象与json字符串互转、java的list和map各自与json字符串的互转
- 迭代求立方根
- 打开Form时报错 FRM-18108:装载下列对象失败 FRM-10102不能附加PLSQL程序库