0

These are the activated devices that I have:

[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 5415837867258701517
, name: "/device:GPU:0"
device_type: "GPU"
memory_limit: 3198956339
locality {
  bus_id: 1
  links {
  }
}
incarnation: 12462133041849407996
physical_device_desc: "device: 0, name: GeForce GTX 960M, pci bus id: 0000:01:00.0, compute capability: 5.0"
]

What I want to do is to configure my program to use GeForce GTX 960M and also make this configuration permanent for all my previous/future programs if is it possible?

Hasani
  • 3,543
  • 14
  • 65
  • 125
  • By default, TensorFlow will try to run things on the GPU if possible (if there is a GPU available and operations can be run in it). You can use [`tf.device`](https://www.tensorflow.org/api_docs/python/tf/device) to that a section of the code must be run on the GPU or fail otherwise (unless you use `allow_soft_placement`, see [Using GPUs](https://www.tensorflow.org/guide/using_gpu)). With multiple GPUs, you can select which ones CUDA use with [`CUDA_VISIBLE_DEVICES`](https://devblogs.nvidia.com/cuda-pro-tip-control-gpu-visibility-cuda_visible_devices/), but I don't think that's your problem. – jdehesa Aug 02 '19 at 12:01
  • @jdehesa: Thank you! But do you know how can I switch between using GPU or CPU? I want to make sure which of those I am using know and compare using them. – Hasani Aug 02 '19 at 12:44
  • As I said, with `tf.device` you can choose what device you want to use (GPU or CPU), and with `CUDA_VISIBLE_DEVICES` you can disable the GPU completely (setting it to `-1`). You can also disable the GPU per-session, see [How to run Tensorflow on CPU](https://stackoverflow.com/q/37660312/1782792). – jdehesa Aug 02 '19 at 12:50
  • @jdehesa: I put `os.environ['CUDA_VISIBLE_DEVICES'] = '1' ` in the begining of my program but no difference happend! – Hasani Aug 02 '19 at 12:59
  • To disable the GPU, you would need to put `os.environ['CUDA_VISIBLE_DEVICES'] = '-1'` at the beginning _before_ importing TensorFlow for the first time. – jdehesa Aug 02 '19 at 13:05
  • @jdehesa: I know but it seems I get no differences when I try to change between them. – Hasani Aug 02 '19 at 13:24
  • @jdehesa: How should I enable the GPU again? With this? `os.environ['CUDA_VISIBLE_DEVICES'] = '1'` ? – Hasani Aug 02 '19 at 13:25
  • Note to disable you need to use `-1`, not `1`. With the `CUDA_VISIBLE_DEVICES` method, you disable the GPU for CUDA for the whole process, you cannot reenable again (you would have to unload and reload CUDA, which I'm not sure how feasible it is in Python). If you want to try different configurations in the same process, recreate the graph with different `tf.device` directives or use the `tf.ConfigProto` when creating the session as suggested in the linked question. – jdehesa Aug 02 '19 at 13:39

1 Answers1

1

try with the function: set_visible_devices

physical_devices = tf.config.list_physical_devices('GPU')
tf.config.set_visible_devices(physical_devices[1:],'GPU')

Where you can specify which GPUs you would like to use

Gravity90
  • 53
  • 4