title: TensorFlow - Low GPU usage on Titan X
body: <p>For a while, I have been noticing that TensorFlow (v0.8) does not seem to fully use the computation power of my Titan X. For several CNNs that I have been running the GPU usage does not seem to exceed ~30%. Typically the GPU utilization is even lower, more like 15%. One particular example of a CNN that shows this behavior is the CNN from DeepMind's Atari paper with Q-learning (see link below for code). </p>
  
  <p>When I see other people of our lab running CNNs written in Theano or Torch the GPU usage is typically 80%+. This makes me wondering, why are the CNNs that I write in TensorFlow so 'slow' and what can I do to make more efficient use of the GPU processing power? Generally, I am interested in ways to profile the GPU operations and discover where the bottlenecks are. Any recommendations how to do this are very welcome since this seems not really possible with TensorFlow at the moment.</p>
  
  <p>Things I did to find out more about the cause of this problem:</p>
  
  <ol>
  <li><p>Analyzing TensorFlow's <strong>device placement</strong>, everything seems to be on gpu:/0 so looks OK.</p></li>
  <li><p>Using <strong>cProfile</strong>, I have optimized the batch generation and other preprocessing steps. The preprocessing is performed on a single thread, but the actual optimization performed by TensorFlow steps take much longer (see average runtimes below). One obvious idea to increase the speed is by using TFs queue runners, but since the batch preparation is already 20x faster than optimization I wonder whether this is going to make a big difference.</p>
  
  <pre><code>Avg. Time Batch Preparation: 0.001 seconds
  Avg. Time Train Operation:   0.021 seconds
  Avg. Time Total per Batch:   0.022 seconds (45.18 batches/second)
  </code></pre></li>
  <li><p>Run on multiple machines to rule out hardware issues.</p></li>
  <li><p>Upgraded to the latest versions of CuDNN v5 (RC), CUDA Toolkit 7.5 and reinstalled TensorFlow from sources about a week ago.</p></li>
  </ol>
  
  <p>An example of the Q-learning CNN for which this 'problem' occurs can be found here: <a href="https://github.com/tomrunia/DeepReinforcementLearning-Atari/blob/master/qnetwork.py" rel="noreferrer">https://github.com/tomrunia/DeepReinforcementLearning-Atari/blob/master/qnetwork.py</a></p>
  
  <p>Example of NVIDIA SMI displaying the low GPU utilization: <a href="https://i.stack.imgur.com/shmpF.png" rel="noreferrer">NVIDIA-SMI</a></p>