TimZaman
TimZaman

Reputation: 2707

How to list visible Tensorflow devices without allocation?

One can list the currently visible devices to Tensorflow with:

from tensorflow.python.client import device_lib
LOCAL_DEVICES = device_lib.list_local_devices()

(see: How to get current available GPUs in tensorflow?)

However, this seems to initialize and allocate these GPUs. How can we list the devices without allocating them?

Upvotes: 0

Views: 1224

Answers (1)

mrry
mrry

Reputation: 126184

For GPU devices, the TensorFlow list_local_devices() function is a wrapper around the cuDeviceGetCount(), cuDeviceGet(), and cuDeviceGetProperties() functions in the CUDA API. (In addition, there is typically one "CPU device" that uses all of the cores in the local system.)

The simplest solution might be to call these CUDA APIs directly. This script shows how to do this from Python using ctypes.

Upvotes: 2

Related Questions