Search code examples
tensorflowgpu

Does tensorflow automatically detect GPU or do I have to specify it manually?


I have a code written in tensorflow that I run on CPUs and it runs fine. I am transferring to a new machine which has GPUs and I run the code on the new machine but the training speed did not improve as expected (takes almost the same time).

I understood that Tensorflow automatically detects GPUs and run the operations on them (https://www.quora.com/How-do-I-automatically-put-all-my-computation-in-a-GPU-in-TensorFlow) & (https://www.tensorflow.org/tutorials/using_gpu).

Do I have to change the code to make it manually runs the operations on GPUs (for now I have a single GPU)? and what would be gained by doing that manually?

Thanks


Solution

  • If the GPU version of TensorFlow is installed and if you don't assign all your tensors to CPU, some of them should be assigned to GPU.

    To find out which devices (CPU, GPU) are available to TensorFlow, you can use this:

    from tensorflow.python.client import device_lib
    print(device_lib.list_local_devices())
    

    Regarding the question of the performance, it's quite a broad subject and it really depends of your model, your data and so on. Here are a few and wide remarks on TensorFlow performance.