Reputation: 13
(there are no stupid questions but a lot of inquisitive idiots [me] so sorry if the answer is obvious). I have a mac and I want to run a tensor flow program on a gpu. Sadly, my computer does not have the necessary sort of gpu, so I was hoping to use one of amazons. I successfully created a p2.xlarge instance, but I don't know how to actually access that gpu from my program. How does the program know to use the amazon gpu? is there some code I need to include? This is the code I currently have, meant to be used on local gpus:
class DeviceCellWrapper(tf.contrib.rnn.GRUCell):
def __init__(self,device,cell):
self._cell = cell
self._device = device
@property
def state_size(self):
return self._cell.state_size
@property
def output_size(self):
return self._cell.output_size
def __call__(self,inputs,state,scope=None):
with tf.device(self._device):
return self._cell(inputs,state,scope)
devices = ["/gpu:0]
so what should I replace /gpu:0
with?
Upvotes: 1
Views: 299
Reputation: 32051
You should use the command nvidia-smi
to see what processes are running on the GPU(s). You'll see something like this:
$ nvidia-smi
Wed May 17 15:59:12 2017
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 367.55 Driver Version: 367.55 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce GTX 1080 Off | 0000:07:00.0 Off | N/A |
| 27% 33C P0 40W / 180W | 0MiB / 8113MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
| 1 GeForce GTX 1080 Off | 0000:08:00.0 Off | N/A |
| 27% 36C P0 39W / 180W | 0MiB / 8113MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
| 2 GeForce GTX 1080 Off | 0000:0B:00.0 Off | N/A |
| 27% 31C P0 40W / 180W | 0MiB / 8113MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
| 3 GeForce GTX 1080 Off | 0000:0C:00.0 Off | N/A |
| 27% 32C P0 39W / 180W | 0MiB / 8113MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
| 4 GeForce GTX 1080 Off | 0000:85:00.0 Off | N/A |
| 27% 33C P0 40W / 180W | 0MiB / 8113MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
| 5 GeForce GTX 1080 Off | 0000:86:00.0 Off | N/A |
| 27% 31C P0 40W / 180W | 0MiB / 8113MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
| 6 GeForce GTX 1080 Off | 0000:8D:00.0 Off | N/A |
| 27% 32C P0 39W / 180W | 0MiB / 8113MiB | 1% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| No running processes found |
+-----------------------------------------------------------------------------+
You should set the environment variable CUDA_VISIBLE_DEVICES=[gpu_id[,gpu_id]]
to limit a specific python process to seeing only that GPU (useful if you want to run multiple applications on different GPUs).
If you don't set CUDA_VISIBLE_DEVICES
tensorflow will consume memory on all GPUs. By default you will use one GPU if it's available, so unless you're ready to move to distributed training (and since you're asking this question, you're not ready yet), you should use CUDA_VISIBLE_DEVICES
.
When you start your tensorflow script you'll see something like this which indicates that it loaded up the GPU drivers correctly:
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcublas.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcudnn.so.5 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcufft.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcurand.so.8.0 locally
Upvotes: 1