By default, TensorFlow maps nearly all of the GPU memory of all GPUs (subject to CUDA_VISIBLE_DEVICES) visible to the process. This is done to more efficiently use the relatively precious GPU memory resources on the devices by reducing memory fragmentation.

In some cases it is desirable for the process to only allocate a subset of the available memory, or to only grow the memory usage as is needed by the process. TensorFlow provides two Config options on the Session to control this.

The first is the allow_growth option, which attempts to allocate only as much GPU memory based on runtime allocations: it starts out allocating very little memory, and as Sessions get run and more GPU memory is needed, we extend the GPU memory region needed by the TensorFlow process. Note that we do not release memory, since that can lead to even worse memory fragmentation. To turn this option on, set the option in the ConfigProto by:

 
config = tf.ConfigProto()
config.gpu_options.allow_growth = True
session = tf.Session(config=config, ...)

The second method is the per_process_gpu_memory_fraction option, which determines the fraction of the overall amount of memory that each visible GPU should be allocated. For example, you can tell TensorFlow to only allocate 40% of the total memory of each GPU by:

 
config = tf.ConfigProto()
config.gpu_options.per_process_gpu_memory_fraction = 0.4
session = tf.Session(config=config, ...)

This is useful if you want to truly bound the amount of GPU memory available to the TensorFlow process.

Allowing GPU memory growth的更多相关文章

  1. Reducing and Profiling GPU Memory Usage in Keras with TensorFlow Backend

    keras 自适应分配显存 & 清理不用的变量释放 GPU 显存 Intro Are you running out of GPU memory when using keras or ten ...

  2. GPU Memory Usage占满而GPU-Util却为0的调试

    最近使用github上的一个开源项目训练基于CNN的翻译模型,使用THEANO_FLAGS='floatX=float32,device=gpu2,lib.cnmem=1' python run_nn ...

  3. 重置GPU显存 Reset GPU memory after CUDA errors

    Sometimes CUDA program crashed during execution, before memory was flushed. As a result, device memo ...

  4. tensorflow 运行效率 GPU memory leak 问题解决

    问题描述: Tensorflow 训练时运行越来越慢,重启后又变好. 用的是Tensorflow-GPU 1.2版本,在GPU上跑,大概就是才开始训练的时候每个batch的时间很低,然后随着训练的推进 ...

  5. Jupyter notebook Tensorflow GPU Memory 释放

    Jupyter notebook 每次运行完tensorflow的程序,占着显存不释放.而又因为tensorflow是默认申请可使用的全部显存,就会使得后续程序难以运行.暂时还没有找到在jupyter ...

  6. Gradient Boosting, Decision Trees and XGBoost with CUDA ——GPU加速5-6倍

    xgboost的可以参考:https://xgboost.readthedocs.io/en/latest/gpu/index.html 整体看加速5-6倍的样子. Gradient Boosting ...

  7. NVIDIA GPU Pascal架构简述

    NVIDIA GPU Pascal架构简述 本文摘抄自英伟达Pascal架构官方白皮书:https://www.nvidia.com/en-us/data-center/resources/pasca ...

  8. Tensorflow2对GPU内存的分配策略

    一.问题源起 从以下的异常堆栈可以看到是BLAS程序集初始化失败,可以看到是执行MatMul的时候发生的异常,基本可以断定可能数据集太大导致memory不够用了. 2021-08-10 16:38:0 ...

  9. GPU keylogger && GPU Based rootkit(Jellyfish rootkit)

    catalog . OpenCL . Linux DMA(Direct Memory Access) . GPU rootkit PoC by Team Jellyfish . GPU keylogg ...

随机推荐

  1. spark 常用技巧总结

    解析url scala> import java.net.URLimport java.net.URL scala> val urlstr="http://www.baidu.c ...

  2. oracle登陆认证方式

    转自:http://blog.itpub.net/14359/viewspace-683064/ 案例: 1,发现此时操作系统认证不成功: C:\Users\Administrator.WIN-201 ...

  3. vbox 按照增强工具 centos7

    命令:mount -t auto /dev/cdrom /mnt/cdrom 这命令就是把CentOS CDROM挂载在/mnt/cdrom目录中,这样我们就可以访问光盘里面的内容了.执行“mount ...

  4. 机器学习进阶-svm支持向量机

    支持向量机需要解决的问题:找出一条最好的决策边界将两种类型的点进行分开 这个时候我们需要考虑一个问题,在找到一条直线将两种点分开时,是否具有其他的约束条件,这里我们在满足找到一条决策边界时,同时使得距 ...

  5. html表单中get与post之间的区别

    当用户在 HTML 表单 (HTML Form) 中输入信息并提交之后,有两种方法将信息从浏览器传送到 Web 服务器 (Web Server). 一种方法是通过 URL,另外一种是在 HTTP Re ...

  6. Warning:Configuration 'compile' is obsolete and has been replaced with 'implementation'. It will be

    1.替换 compile为implementation. 2.file->invalidate caches 或者build中的clear

  7. css:关于position和float

    在CSS中,我们是通过定位属性position来进行定位的,具体它有如下几个属性值.常见的属性有如下几个: absolute  生成绝对定位的元素,相对于static定位以外的第一个父元素进行定位.元 ...

  8. vue:在路由跳转中使用拦截器

    1:首先在路由对象中的某一个具体的路由对象加这样一个属性 meta: {  requireAuth:true  } 2:然后在main.js中添加这段代码 router.beforeEach((to, ...

  9. docker的完整解决方案2

    这个解决方案很简单 使用docker自带的swarm 首先初始化集群 docker swarm init 然后其余节点加入集群,这个就不说,太简单了 集群初始化后,可以查看下集群状态 docker n ...

  10. javascript:getElementsByName td name

    问题:    今天写动态生成HTML表格的时候需要用到统计td内的数据,在生成的时候设置了td的name属性,但是document.getElementsByName("tdname&quo ...