Repository navigation
Closed
Labels
stat:contribution welcomeStatus - Contributions welcome
Description
When I set the nvidia driver in exclusive mode and one of the GPU is already used by another process, I get a segmentation fault:
$ python -c "import tensorflow as tf;tf.InteractiveSession()"
I tensorflow/core/common_runtime/local_device.cc:25] Local device intra op parallelism threads: 12
Segmentation fault (core dumped)
If I limit the visible GPUs to only GPUs that have nothing running on them, it don't segfault:
$CUDA_VISIBLE_DEVICES=1 python -c "import tensorflow as tf;tf.InteractiveSession()"
I tensorflow/core/common_runtime/local_device.cc:25] Local device intra op parallelism threads: 12
I tensorflow/core/common_runtime/gpu/gpu_init.cc:88] Found device 0 with properties:
name: GeForce GTX TITAN X
major: 5 minor: 2 memoryClockRate (GHz) 1.076
pciBusID 0000:09:00.0
Total memory: 12.00GiB
Free memory: 11.87GiB
I tensorflow/core/common_runtime/gpu/gpu_init.cc:112] DMA: 0
I tensorflow/core/common_runtime/gpu/gpu_init.cc:122] 0: Y
I tensorflow/core/common_runtime/gpu/gpu_device.cc:643] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX TITAN X, pci bus id: 0000:09:00.0)
I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:47] Setting region size to 12105628263
I tensorflow/core/common_runtime/local_session.cc:45] Local session inter op parallelism threads: 12
Here is my output of nvidia-smi:
$ nvidia-smi
Wed Nov 11 16:48:27 2015
+------------------------------------------------------+
| NVIDIA-SMI 352.39 Driver Version: 352.39 |
|-------------------------------+----------------------+----------------------+
| 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 750 Off | 0000:05:00.0 On | N/A |
| N/A 48C P8 0W / 38W | 25MiB / 2047MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
| 1 GeForce GTX TIT... Off | 0000:06:00.0 Off | N/A |
| 42% 82C P2 127W / 250W | 262MiB / 12287MiB | 39% E. Process |
+-------------------------------+----------------------+----------------------+
| 2 GeForce GTX TIT... Off | 0000:09:00.0 Off | N/A |
| 22% 46C P8 17W / 250W | 23MiB / 12287MiB | 0% E. Process |
+-------------------------------+----------------------+----------------------+
| 3 GeForce GTX TIT... Off | 0000:0A:00.0 Off | N/A |
| 22% 37C P8 15W / 250W | 361MiB / 12287MiB | 0% E. Process |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 1171 G /usr/bin/X 17MiB |
| 1 32740 C python 209MiB |
| 3 9429 C python 336MiB |
+-----------------------------------------------------------------------------+
I suppose that in the code that check the available GPUs, it don't handle correctly a case when one of the GPUs can't be used.
Reacted by Yann Henon, Farshid Tavakolizadeh, Francesco, A.Juneja, Ankit Shah and Aditya Singh Rathore
Metadata
Metadata
Assignees
Labels
stat:contribution welcomeStatus - Contributions welcome
Activity
zheng-xq commentedon Nov 11, 2015
@nouiz, you are correct in your analysis. TensorFlow tries to grab all the GPU it sees from the system that passes its criteria. CUDA_VISIBLE_DEVICES is the solution I would suggest. Please let us know if that is not enough.
skearnes commentedon Nov 12, 2015
@zheng-xq +1 on CUDA_VISIBLE_DEVICES; this fixes the issue for me.
vrv commentedon Nov 13, 2015
Re-open if CUDA_VISIBLE_DEVICES isn't good enough
noisychannel commentedon Dec 11, 2015
@vrv This is still a problem when there are multiple GPUs (in exclusive mode) on the machine and some of them have processes running on them. Setting CUDA_VISIBLE_DEVICES is not ideal if you do not actually know which GPU is available. nvidia-smi will only show the current state of the GPUs and there's no way of ensuring that while you spawn your process, no other process occupied the GPU you set for use. Is there a way of polling GPUs and assigning the process to the first available, compatible GPU on the machine instead of having to manually specify the GPU id?
PS: I cannot reopen this issue.
vrv commentedon Dec 11, 2015
@zheng-xq: is it possible to query the status of the exclusive mode bit?
zheng-xq commentedon Dec 11, 2015
@noisychannel, even if we can query which GPU is available, and by the time we actually try to assign the GPU, it could be taken by other processes. This is not very different from having a script query GPU status through nvidia-smi, and set the GPU id accordingly.
The only way I can think of that makes your case easier is actually to create the context, and if it fails, ignore that failure and move on to the next. However, this is undesirable for many more common cases, where such context creation errors are signs of bigger problems.
noisychannel commentedon Dec 11, 2015
The established way to do this seems to be:
cudaSetDevice().As for exception handling while creating the context, it seems like the this scenario can be handled with the exceptions returned by
cuCtxCreate().A solution like this is optimal when you delegate the scheduling of your jobs to something like SGE and cannot trust the script based querying approach which I think is common for large clusters.
zheng-xq commentedon Dec 11, 2015
This would work fine if the framework only wants to use a single GPU. TensorFlow is designed to use multiple GPU seamlessly at the same time. So at the initialization stage, it grabs all the visible devices that are compatible, since the client program might use all of them. The actual device used is only known at the graph construction/execution time, which is at a much later stage.
For most of our existing users, the GPUs that are available to a particular job is known when it starts. So it is okay for TensorFlow to take all of them. A few options to think about:
noisychannel commentedon Dec 11, 2015
@zheng-xq For 1: AFAIK, the only responsibility of most job schedulers is to ensure that you will have access to the number of GPUs you have asked for on the machine which has been assigned to you. It leaves the actual CPU/GPU scheduling of the processes on that machine to the OS/Cuda driver. Also, hypothetically, if the scheduler was to attempt something of this sort, it would not be able to block the GPU without creating something like a context.
For 2 : I understand that this is probably painful. However, it does add a more general set of features. The case where I want
kout ofnGPUs on the machine is most prominent. Eg,, it would be able to handle the case where the candidate list is the set of all GPUs on the machine and I want only 2 available and compatible GPUs from that list. Having the ability to specify how many GPUs you want to use will be a great addition and this will tie in perfectly with most job schedulers. So to tensorflow, I specify, I want to run this thing on 2 GPUs and I tell the job scheduler that I need 2 GPUs.skearnes commentedon Dec 11, 2015
Drive-by comment: the sysadmin for my local SGE cluster was able to have an environment variable set that tells me which GPUs my jobs have been assigned. I then use this variable to set CUDA_VISIBLE_DEVICES. I would guess that most common schedulers have similar capabilities, although they may require root-level tweaking.
noisychannel commentedon Dec 11, 2015
This is useful to know. However, something like this would require all jobs on the cluster to respect that environment variable when using GPUs. And it takes away some of the scheduling responsibility that should ideally belong to the CUDA driver, adding another layer of complexity. In fact, most other toolkits that are GPU capable will not require something like this and as long as the GPUs are set in exclusive mode, they work just fine.
jtrmal commentedon Dec 11, 2015
Another drive-by comment: when the allocation fails, the app actually segfaults on our machines. That does not provide any possibility for the user to recover from it at the python level.
A good-enough solution would be
a) throw an exception so that user can it catch and try (for example) another device
b) ideally, adding /gpu:auto which would just iterate through the devices and allocate the one that is available.
zheng-xq commentedon Dec 14, 2015
@noisychannel, please see if you can work around this issue at the moment. Meanwhile, I will investigate if we can officially support the soft-try-and-device-limit approach in TensorFlow.
24 remaining items
noisychannel commentedon Jan 18, 2017
This may be helpful to some users who are on a cluster. Often, you don't have information about which GPU has been allocated to you or which one to occupy if free, with CUDA_VISIBLE_DEVICES.
I use this script to (https://gist.github.com/noisychannel/cdf57e2f177e98ae653230323a093d1e) to return the first free GPU and then use something like :
Edit : This is the parsed nvidia-smi output that @yaroslavvb mentioned earlier in this thread.
cbquillen commentedon Jan 19, 2017
@yaroslavvb
Looking at the NVIDIA docs more, I think you can get your setup_one_gpu script to work reliably if you set the CUDA_DEVICE_ORDER environment variable to 'PCI_BUS_ID'.
@zheng-xq A cheezy solution that would probably reduce the likelihood of complaints (but create some less-likely new problems) would be to force set CUDA_DEVICE_ORDER='PCI_BUS_ID' within Tensorflow.
Removed extra parens (tensorflow#152)
[OpenCL] Removes unneeded device to host copy (tensorflow#152)
tensorflowbutler commentedon Dec 22, 2017
It has been 14 days with no activity and this issue has an assignee.Please update the label and/or status accordingly.
zheng-xq commentedon Dec 22, 2017
If someone is interested in adding CUDA_DEVICE_ORDER='PCI_BUS_ID' support in TensorFlow, a contribution is welcome. But note that we can only override it if it is not already set. And it has to been before any potential Cuda calls are made.
cliffwoolley commentedon Dec 22, 2017
I don't think I've actually seen an application that sets CUDA_DEVICE_ORDER on its own. Usually this would be set in the environment before launching the application, perhaps in combination with CUDA_VISIBLE_DEVICES.
cbquillen commentedon Dec 22, 2017
You can certainly set environment variables within an application before the first call to tf.Session().
cliffwoolley commentedon Dec 22, 2017
Of course it's possible. Just as in C you'd use setenv(). I was just saying that for those particular environment variables, the choice is a bit specific to the combination of application and machine the application is run on. So usually the user (or script) invoking the application would set those env vars rather than having the application set them unilaterally. I'd argue for example that it's unwise for TF itself to set CUDA_DEVICE_ORDER, because it would undo the CUDA feature that this variable sits on top of, which is to, by default, have the "best" device be device 0; this is handy when you don't know much about the system you're running on and are just trying things out. More sophisticated users just pick a GPU or, if really fancy, pick one based on NVML output as we're discussing here. But we shouldn't, IMO, assume all users are so sophisticated.
imagefun commentedon Apr 12, 2018
export CUDA_VISIBLE_DEVICES=0solves my issue!wt-huang commentedon Nov 10, 2018
Closing as this is resolved, free to reopen if problem persists.
saikrishnadas commentedon Apr 4, 2020
Python 3.6.9
Tensorflow 2.1.0 gpu supported
Cuda 10.0
TensorRT 6.0
GPU - 1
Is still get the error even after
export CUDA_VISIBLE_DEVICES=0orexport CUDA_VISIBLE_DEVICES=1Error log :