如果什么都不加,直接运行装了GPU的Tensorflow,结果是这样子的

import tensorflow as tf

a = tf.constant([1.0, 2.0, 3.0], shape=[3], name='a')
b = tf.constant([1.0, 2.0, 3.0], shape=[3], name='b')
c = a + b sess = tf.Session(config=tf.ConfigProto(log_device_placement=True)) # 通过log_device_placement参数来记录运行每一个运算的设备。
print(sess.run(c))

来来来,看图

当指定cpu还是GPU时:

import tensorflow as tf

# 通过tf.device将运算指定到特定的设备上。
with tf.device('/cpu:0'):
a = tf.constant([1.0, 2.0, 3.0], shape=[3], name='a')
b = tf.constant([1.0, 2.0, 3.0], shape=[3], name='b') with tf.device('/gpu:0'):
c = a + b sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
print(sess.run(c))

结果就变成了这样子:

最后一个

import tensorflow as tf

a_cpu = tf.Variable(0, name="a_cpu")
with tf.device('/gpu:0'):
a_gpu = tf.Variable(0, name="a_gpu")
# 通过allow_soft_placement参数自动将无法放在GPU上的操作放回CPU上。
sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True, log_device_placement=True))
sess.run(tf.global_variables_initializer())

结果:

最新文章

  1. 从零自学Hadoop(10):Hadoop1.x与Hadoop2.x
  2. EasyUI、Struts2、Hibernate、spring 框架整合
  3. javascript面向对象(学习和理解)
  4. SQL Server case表达式的用法
  5. CSS基础(一):开篇
  6. watchdog机制
  7. HDU 5285 wyh2000 and pupil
  8. 从服务器将Oracle数据库导出到本地Oracle数据库的方法
  9. css样式图片、渐变、相关小知识
  10. <转载>构造函数声明为Private和Protected
  11. [妙味DOM]第六课:鼠标滚轮和COOKIE
  12. Ubuntu系统怎么切换多用户命令界面
  13. IoT experitment
  14. linux resin 基本站点配置
  15. RAC手动中断订阅
  16. a标签的四个伪类
  17. CentOS 7不能联网解决办法
  18. iOS最为简单时间轴(GZTimeLine)
  19. [转]乔布斯的薄伽梵歌 Steve’s Bhagavat Gita
  20. mac iterm2

热门文章

  1. Jenkins服务使用 宿主机的docker、docker-compose (Jenkins 执行sudo命令时出现“sudo: no tty present and no askpass program specified”,以及 docker-compose command not found解决办法)
  2. PHP的序列化、对象、反射、异常与错误
  3. Outlook 邮件助手
  4. dump net core lldb 安装
  5. 数组中[::-1]或[::-n]的区别,如三维数组[:,::-1,:]
  6. SP375 QTREE - Query on a tree (树剖)
  7. pandas-01 Series()的几种创建方法
  8. git拉取单个子目录
  9. 关于创建Web图像时应记住的五个要素
  10. 使用SAP Cloud Application Programming模型开发OData的一个实际例子