- Mastering TensorFlow 1.x
- Armando Fandango
- 240字
- 2021-06-25 22:50:57
GPU memory handling
When you start running the TensorFlow session, by default it grabs all of the GPU memory, even if you place the operations and variables only on one GPU in a multi-GPU system. If you try to run another session at the same time, you will get out of memory error. This can be solved in multiple ways:
- For multi-GPU systems, set the environment variable CUDA_VISIBLE_DEVICES=<list of device idx>
os.environ['CUDA_VISIBLE_DEVICES']='0'
The code executed after this setting will be able to grab all of the memory of only the visible GPU.
- When you do not want the session to grab all of the memory of the GPU, then you can use the config option per_process_gpu_memory_fraction to allocate a percentage of memory:
config.gpu_options.per_process_gpu_memory_fraction = 0.5
This will allocate 50% of the memory of all the GPU devices.
- You can also combine both of the above strategies, i.e. make only a percentage along with making only some of the GPU visible to the process.
- You can also limit the TensorFlow process to grab only the minimum required memory at the start of the process. As the process executes further, you can set a config option to allow the growth of this memory.
config.gpu_options.allow_growth = True
This option only allows for the allocated memory to grow, but the memory is never released back.
You will learn techniques for distributing computation across multiple compute devices and multiple nodes in later chapters.
推薦閱讀
- Intel FPGA/CPLD設計(基礎篇)
- 精選單片機設計與制作30例(第2版)
- 平衡掌控者:游戲數值經濟設計
- 數字邏輯(第3版)
- Learning Stencyl 3.x Game Development Beginner's Guide
- RISC-V處理器與片上系統設計:基于FPGA與云平臺的實驗教程
- 新編電腦組裝與硬件維修從入門到精通
- FreeSWITCH Cookbook
- 嵌入式系統原理及應用:基于ARM Cortex-M4體系結構
- FPGA實戰訓練精粹
- UML精粹:標準對象建模語言簡明指南(第3版)
- The Machine Learning Workshop
- 多媒體應用技術(第2版)
- 快·易·通:2天學會電腦組裝·系統安裝·日常維護與故障排除
- 電腦組裝與硬件維修從入門到精通