Reputation: 49
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 codeCUDA_VISIBLE_DEVICES
as environment variable in PyCharm project configuration settings.CUDA_LAUNCH_BLOCKING=2
in 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
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_DEVICES
then tensorflow detects all 4 GPUs but code run on only GPU 2.
Upvotes: 0
Views: 1221
Reputation: 138
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
Upvotes: 1