0

My this problem is same as 1: How to set specific gpu in tensorflow? but it didn't solve my problem.

I have 4 GPUs in my PC and I want to run code on GPU 0 but whenever I run my tensorflow code, my code is always running only on GPU 2. As reading these (2, 3, 4) solutions and information I tried to solve my problem by adding:

  • os.environ['CUDA_VISIBLE_DEVICES']= '0' in python code
  • orCUDA_VISIBLE_DEVICES as environment variable in PyCharm project configuration settings.
  • furthermore I also add CUDA_LAUNCH_BLOCKING=2in code or environment variable to block the GPU 2. Is it right way to block any GPU?

Above solutions are not working for me. Code is always running on GPU 2. I checked it by watch nvidia-smi. My system environment is

  • Ubuntu 16.04
  • RTX2080Ti (all 4 GPUs)
  • Driver version 418.74
  • CUDA 9.0 and CuDNN 7.5
  • Tensorflow-gpu 1.9.0

Any suggestions for this problem? It's wired that adding environment variable in project settings in PyCharm or in python code... still only GPU 2 is visible. When I remove CUDA_VISIBLE_DEVICESthen tensorflow detects all 4 GPUs but code run on only GPU 2.

Community
  • 1
  • 1
  • u can check this, NVIDIA_VISIBLE_DEVICES=$gpu_id CUDA_VISIBLE_DEVICES=0 set gpu id to the gpu u want like 0,1,2 or 3 – Venkataraman Dec 30 '19 at 10:59

1 Answers1

1

I tried this in tensorflow 2.0.0

physical_devices = tf.config.experimental.list_physical_devices('GPU')

tf.config.experimental.set_visible_devices(physical_devices[0], 'GPU')

logical_devices = tf.config.experimental.list_logical_devices('GPU')

This should make u r code run in GPU index 0

Venkataraman
  • 138
  • 1
  • 9
  • You suggestion works fine in tf 2.0 but not working in tf 1.9, I think some functions are changed in 2.0. I tried to get the same possibility in tf 1.9 by checking these links. [Same issue](https://stackoverflow.com/questions/52050990/why-does-tensorflow-always-use-gpu-0) and [official tf guide](https://www.tensorflow.org/guide/gpu). To use some of GPUs, there is simplest way `MirroredStrategy()`defined in [this link](https://www.tensorflow.org/guide/distributed_training) but it also not working. – Muhammad Ahsan Dec 31 '19 at 02:47
  • can u try MultiWorkerMirroredStrategy, i have also tried this in tf2.0 – Venkataraman Dec 31 '19 at 04:54