Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use CPUs or multiple GPUs for tensorflow linux-x86_64-gpu 1.5 #533

Closed
andyguo007 opened this issue Mar 1, 2018 · 4 comments
Closed

use CPUs or multiple GPUs for tensorflow linux-x86_64-gpu 1.5 #533

andyguo007 opened this issue Mar 1, 2018 · 4 comments
Labels

Comments

@andyguo007
Copy link

Hi,

I am using gpu version of tensorflow 1.5 (linux-x86_64-gpu). And I have two Titan X GPUs. Here are some thing I found confusing when running tensorflow:

use:
tensorflow.GraphDef def = new tensorflow.GraphDef();
tensorflow.SetDefaultDevice(device, def);

when "device" is "/cpu:0" or "/cpu:1" or ... etc., I found that GPU:0 is being used.

  1. Does it mean that when using the gpu version, a gpu would definitely be used even when no gpu is appointed (when only cpus are appointed)?

  2. If I have multiple sessions using "cpu:0" and "cpu:1" ... etc., are these sessions sharing one GPU in this case?

  3. If there are ONLY two sessions appointed with "gpu:0" and "gpu:1" individually, are these two sessions running solely on it's own appointed GPU?

Thanks a lot,
Andy

@saudet saudet added the question label Mar 1, 2018
@saudet
Copy link
Member

saudet commented Mar 1, 2018

According to the documentation, that sounds like what it should be doing, yes:

You will see that now a and b are assigned to cpu:0. Since a device was not explicitly specified for the MatMul operation, the TensorFlow runtime will choose one based on the operation and available devices (gpu:0 in this example) and automatically copy tensors between devices if required.

https://www.tensorflow.org/programmers_guide/using_gpu

It sounds like it will respect the GPU we specify, though:

If you have more than one GPU in your system, the GPU with the lowest ID will be selected by default. If you would like to run on a different GPU, you will need to specify the preference explicitly:

@saudet saudet closed this as completed Mar 1, 2018
@saudet
Copy link
Member

saudet commented Jun 7, 2018

It looks like if we set the "device count" to 0, it will in effect ignore any GPUs:
https://medium.com/@lisulimowicz/tensorflow-cpus-and-gpus-configuration-9c223436d4ef
However, the field isn't currently being mapped by the presets...

@saudet
Copy link
Member

saudet commented Jun 7, 2018

Also, SetDefaultDevice() will only work if the device has not already been set on the nodes of the graph. We can clear these settings as with the "--clear_devices" option of this script:
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/tools/freeze_graph.py

saudet added a commit that referenced this issue Jun 7, 2018
@saudet
Copy link
Member

saudet commented Jun 7, 2018

Ok, now we should be able to do something like the following to disable the GPU:

        ConfigProto configProto = new ConfigProto();
        configProto.mutable_device_count().put(new BytePointer("GPU"), 0);
        SessionOptions options = new SessionOptions();
        options.config(configProto);
        Session sess = new Session(options);
        Status s = sess.Create(def);
        ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants