title: How to get current available GPUs in tensorflow?
body: <p>I have a plan to use distributed TensorFlow, and I saw TensorFlow can use GPUs for training and testing. In a cluster environment, each machine could have 0 or 1 or more GPUs, and I want to run my TensorFlow graph into GPUs on as many machines as possible.</p>
  
  <p>I found that when running <code>tf.Session()</code> TensorFlow gives information about GPU in the log messages like below:</p>
  
  <pre><code>I tensorflow/core/common_runtime/gpu/gpu_init.cc:126] DMA: 0 
  I tensorflow/core/common_runtime/gpu/gpu_init.cc:136] 0:   Y 
  I tensorflow/core/common_runtime/gpu/gpu_device.cc:838] Creating TensorFlow device (/gpu:0) -&gt; (device: 0, name: GeForce GTX 1080, pci bus id: 0000:01:00.0)
  </code></pre>
  
  <p>My question is how do I get information about current available GPU from TensorFlow? I can get loaded GPU information from the log, but I want to do it in a more sophisticated, programmatic way.
  I also could restrict GPUs intentionally using the CUDA_VISIBLE_DEVICES environment variable, so I don't want to know a way of getting GPU information from OS kernel.</p>
  
  <p>In short, I want a function like <code>tf.get_available_gpus()</code> that will return <code>['/gpu:0', '/gpu:1']</code> if there are two GPUs available in the machine. How can I implement this?</p>