title: Forcing TensorFlow-GPU to use the CPU from the command line
body: <p>I have TensorFlow-GPU 1.0.0 installed on a server running Ubuntu 14.04.4 LTS x64.</p>
  
  <p>I know I can use <a href="https://stackoverflow.com/a/42382106/395857"><code>CUDA_VISIBLE_DEVICES</code></a> to hide one or several GPUs. Sometimes, I would like to hide all GPUs so that the TensorFlow-based program only uses the CPU. As a result, I tried</p>
  
  <pre><code>username@server:/scratch/coding/src$ CUDA_VISIBLE_DEVICES="" python my_script.py 
  </code></pre>
  
  <p>but this gives me the error message:</p>
  
  <pre><code>E tensorflow/stream_executor/cuda/cuda_driver.cc:509] failed call to cuInit: CUDA_ERROR_NO_DEVICE
  </code></pre>
  
  <p>Here is the <code>ConfigProto</code> I use:</p>
  
  <pre><code>session_conf = tf.ConfigProto(
        device_count={'CPU': 1, 'GPU': 1},
        allow_soft_placement=True, 
        log_device_placement=False
        )
  sess = tf.Session(config=session_conf)
  </code></pre>
  
  <p>I know I could use <code>device_count={'GPU': 0}</code> to prevent the TensorFlow-based program from using the GPU, but I wonder whether this can be achieved from the command line when launching the program (without changing the <code>ConfigProto</code>). </p>
  
  <p>The option <code>allow_soft_placement=True</code>, according to the documentation, is supposed to have TensorFlow  automatically choose an existing and supported device to run the operations in case the specified one doesn't exist.</p>
  
  <p>My first reaction when I saw the message was that CUDA needs at least one GPU to successfully load but I <a href="https://stackoverflow.com/a/42287754/395857">read</a> that one can install GPU drivers and use TensorFlow-GPU on a machine even if the machine doesn't have GPU.</p>
  
  <hr>
  
  <p>Here is the  <code>my_script.py</code> script I use for the test:</p>
  
  <pre><code>import tensorflow as tf
  a = tf.constant(1, name = 'a')
  b = tf.constant(3, name = 'b')
  c = tf.constant(9, name = 'c')
  d = tf.add(a, b, name='d')
  e = tf.add(d, c, name='e')
  
  session_conf = tf.ConfigProto(
            device_count={'CPU': 1, 'GPU': 1},
            allow_soft_placement=True,
            log_device_placement=False
            )
  sess = tf.Session(config=session_conf)
  print(sess.run([d, e]))
  </code></pre>