Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify number of GPUs in Python interface?

Tags:

tensorflow

When I start a tensorflow Session it immediately allocates 100% of the memory on both GPUs in my dekstop (devices 0 and 2).

How can I use the Python API to restrict it to just 1 GPU?

like image 856
Markus Avatar asked Nov 04 '25 11:11

Markus


2 Answers

A crude way to restrict it to use just GPU #0, for example, is to define this:

export CUDA_VISIBLE_DEVICES=0
like image 109
Markus Avatar answered Nov 07 '25 11:11

Markus


If you want some operations to be done only with a particular device, you can do the following:

with tf.device('/gpu:0'):
   ...
   # all your operations

Where the devices are specified in the following way: "/cpu:0", "/gpu:0", "/gpu:1". I suggest you to read more details in the topic using GPU devices.

If you want to see some tutorials, take a look at cifar10 tutorial.

like image 22
Salvador Dali Avatar answered Nov 07 '25 10:11

Salvador Dali



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!