官术网_书友最值得收藏!

GPU memory handling

At the start of the TensorFlow session, by default, a session grabs all of the GPU memory, even if the operations and variables are placed only on one GPU in a multi-GPU system. If another session starts execution at the same time, it will receive an 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 that's executed after this setting will be able to grab all of the memory of the visible GPU.

  • For letting the session grab a part of the memory of the GPU, use the config option per_process_gpu_memory_fraction to allocate a percentage of the memory:
config.gpu_options.per_process_gpu_memory_fraction = 0.5

This will allocate 50% of the memory in all of the GPU devices.

  • By combining both of the preceding strategies, you can make only a certain percentage, alongside just some of the GPU, visible to the process.
  • Limit the TensorFlow process to grab only the minimum required memory at the start of the process. As the process executes further, set a config option to allow for the growth of this memory:
config.gpu_options.allow_growth = True

This option only allows for the allocated memory to grow, so the memory is never released back.

To find out more about learning techniques for distributing computation across multiple compute devices, refer to our book,  Mastering TensorFlow.
主站蜘蛛池模板: 八宿县| 仪征市| 密山市| 赤水市| 水城县| 株洲市| 邹城市| 南川市| 苏尼特右旗| 惠安县| 樟树市| 阿拉善右旗| 蓬溪县| 黔南| 金坛市| 灵璧县| 礼泉县| 岐山县| 贵德县| 昔阳县| 淮南市| 枣庄市| 瓦房店市| 福鼎市| 宿迁市| 河曲县| 宾川县| 上思县| 浙江省| 商水县| 化德县| 腾冲县| 化隆| 岳阳市| 德州市| 子长县| 钟山县| 东乡族自治县| 筠连县| 汕尾市| 商都县|