
Tf.t_log_device_placement(True) as the first statement of your To find out which devices your operations and tensors are assigned to, put For example, since tf.cast only has a CPU kernel, on a system with devices CPU:0 and GPU:0, the CPU:0 device is selected to run tf.cast, even if requested to run on the GPU:0 device. If a TensorFlow operation has no corresponding GPU implementation, then the operation falls back to the CPU device. For example, tf.matmul has both CPU and GPU kernels and on a system with devices CPU:0 and GPU:0, the GPU:0 device is selected to run tf.matmul unless you explicitly request to run it on another device. If a TensorFlow operation has both CPU and GPU implementations, by default, the GPU device is prioritized when the operation is assigned.

This guide is for users who have tried these approaches and found that they need fine-grained control of how TensorFlow uses the GPU.


The simplest way to run on multiple GPUs, on one or many machines, is using Distribution Strategies. Note: Use tf.config.list_physical_devices('GPU') to confirm that TensorFlow is using the GPU. TensorFlow code, and tf.keras models will transparently run on a single GPU with no code changes required.
