Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TensorFlow CUDA_ERROR_OUT_OF_MEMORY

Tags:

tensorflow

I'm trying to build a large CNN in TensorFlow, and intend to run it on a multi-GPU system. I've adopted a "tower" system and split batches for both GPUs, while keeping the variables and other computations on the CPU. My system has 32GB of memory, but when I run my code I get the error:

E tensorflow/stream_executor/cuda/cuda_driver.cc:924] failed to alloc 17179869184 bytes on host: CUDA_ERROR_OUT_OF_MEMORY
W ./tensorflow/core/common_runtime/gpu/pool_allocator.h:195] could not allocate pinned host memory of size: 17179869184
Killed

I've seen that the code works (though very very slowly) if I hide CUDA devices to TensorFlow, and thus it doesn't use cudaMallocHost()...

Thank you for your time.

like image 886
Alexandre Vieira Avatar asked Apr 19 '17 18:04

Alexandre Vieira


1 Answers

There are some options:

1- reduce your batch size

2- use memory growing:

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

3- don't allocate whole of your GPU memory(only 90%):

config = tf.ConfigProto()
config.gpu_options.per_process_gpu_memory_fraction = 0.9
session = tf.Session(config=config, ...)
like image 60
Ali Abbasi Avatar answered Sep 18 '22 14:09

Ali Abbasi