tensorflow--指定GPU及分配显存

export CUDA_VISIBLE_DEVICES]

转载:https://www.jianshu.com/p/756541f9ff40
前提:
1.安装好tensorflow的gpu版本及其对应CUDA
2.有GPU

指定某一块或多块gpu运行

1

# 指定第二块gpu
CUDA_VISIBLE_DEVICES=1 python {xxx}.py

2

export CUDA_VISIBLE_DEVICES=1
python {xxx}.py

3

import os
os.environ["CUDA_VISIBLE_DEVICES"] = "2"

如果设置-1,是不使用显卡。
参数参考:

Environment Variable SyntaxResults
CUDA_VISIBLE_DEVICES=1CUDA_VISIBLE_DEVICES=1
CUDA_VISIBLE_DEVICES=0,1Devices 0 and 1 will be visible
CUDA_VISIBLE_DEVICES=“0,1”Devices 0 and 1 will be visible
CUDA_VISIBLE_DEVICES=“0,1”Devices 0, 2, 3 will be visible; device 1 is masked
CUDA_VISIBLE_DEVICES=""No GPU will be visible

配置gpu显存使用率

方法一:通过配置Session的运行参数配置gpu的使用

# 通过配置Session的运行参数配置gpu的使用

config = tf.ConfigProto(allow_soft_placement=True, allow_soft_placement=True)
config.gpu_options.per_process_gpu_memory_fraction = 0.4  #占用40%显存
sess = tf.Session(config=config)

参数参考:

SyntaxResults
tf.ConfigProto(log_device_placement=True)记录设备指派情况
tf.ConfigProto(allow_soft_placement=True)自动选择一个运行设备
tf.ConfigProto(allow_soft_placement=True)动态申请显存
config.gpu_options.per_process_gpu_memory_fraction = 0.4动态申请显存
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值