没有合适的资源?快使用搜索试试~ 我知道了~
基于tensorflow指定GPU运行及GPU资源分配的几种方式小结
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
2 下载量 70 浏览量
2020-12-20
15:31:16
上传
评论 1
收藏 49KB PDF 举报
温馨提示
试读
1页
1. 在终端执行时设置使用哪些GPU(两种方式) (1) 如下(export 语句执行一次就行了,以后再运行代码不用执行) (2) 如下 2. 代码中指定(两种方式) (1) import os os.environ["CUDA_VISIBLE_DEVICES"] = "1" (2) # Creates a graph. with tf.device('/gpu:1'): a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a') b = tf.constant([1.0, 2.0, 3.0, 4.
资源详情
资源评论
资源推荐
基于基于tensorflow指定指定GPU运行及运行及GPU资源分配的几种方式小结资源分配的几种方式小结
1. 在终端执行时设置使用哪些在终端执行时设置使用哪些GPU(两种方式)(两种方式)
(1) 如下(export 语句执行一次就行了,以后再运行代码不用执行)
(2) 如下
2. 代码中指定(两种方式)代码中指定(两种方式)
(1)
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "1"
(2)
# Creates a graph.
with tf.device('/gpu:1'):
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
# Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
# Runs the op.
print sess.run(c)
若想使用多个GPU,如下
c = [] for d in ['/gpu:0', '/gpu:1']:
with tf.device(d):
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3])
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2])
c.append(tf.matmul(a, b))
with tf.device('/cpu:0'):
sum = tf.add_n(c)
# Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
# Runs the op.
print sess.run(sum)
3.GPU资源分配资源分配
(1) 设置允许GPU增长
config = tf.ConfigProto()
config.gpu_options.allow_growth = True
session = tf.Session(config=config, ...)
(2) 设置每个GPU内存使用多少
config = tf.ConfigProto()
config.gpu_options.per_process_gpu_memory_fraction = 0.4
session = tf.Session(config=config, ...)
以上这篇基于tensorflow指定GPU运行及GPU资源分配的几种方式小结就是小编分享给大家的全部内容了,希望能给大家一个
参考,也希望大家多多支持软件开发网。
您可能感兴趣的文章您可能感兴趣的文章:基于Tensorflow使用CPU而不用GPU问题的解决tensorflow:指定gpu 限制使用量百分比,设置最小使用量
的实现运行tensorflow python程序,限制对GPU和CPU的占用操作tensorflow使用指定gpu的方法tensorflow指定GPU与动态分
配GPU memory设置检测tensorflow是否使用gpu进行计算的方式解决TensorFlow GPU版出现OOM错误的问题解决
Tensorflow占用GPU显存问题已安装tensorflow-gpu,但keras无法使用GPU加速的解决
weixin_38691220
- 粉丝: 2
- 资源: 940
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0