Every line of 'tensorflow list devices' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
321 @tf_export('config.experimental.list_logical_devices') 322 def list_logical_devices(device_type=None): 323 """Return a list of logical devices created by runtime. 324 325 Logical devices may correspond to physical devices or remote devices in the 326 cluster. Operations and tensors may be placed on these devices by using the 327 `name` of the LogicalDevice. 328 329 For example: 330 331 ```python 332 logical_devices = tf.config.experimental.list_logical_devices('GPU') 333 # Allocate on GPU:0 334 with tf.device(logical_devices[0].name): 335 one = tf.constant(1) 336 # Allocate on GPU:1 337 with tf.device(logical_devices[1].name): 338 two = tf.constant(2) 339
Args: device_type: (optional) Device type to filter by such as "CPU" or "GPU"
Returns: List of LogicalDevice objects """ return context.context().list_logical_devices(device_type=device_type)
628 def list_devices(self): 629 """Lists available devices in this session. 630 631 ```python 632 devices = sess.list_devices() 633 for d in devices: 634 print(d.name) 635
Each element in the list has the following properties:
name
: A string with the full name of the device. ex:
/job:worker/replica:0/task:3/device:CPU:0
device_type
: The type of the device (e.g. CPU
, GPU
, TPU
.)memory_limit
: The maximum amount of memory available on the device.
Note: depending on the device, it is possible the usable memory could
be substantially less.
Raises:
tf.errors.OpError: If it encounters an error (e.g. session is in an
invalid state, or network errors occur).Returns: A list of devices in the session. """ with errors.raise_exception_on_not_ok_status() as status: if self._created_with_new_api: raw_device_list = tf_session.TF_SessionListDevices( self._session, status) else: raw_device_list = tf_session.TF_DeprecatedSessionListDevices( self._session, status) device_list = [] size = tf_session.TF_DeviceListCount(raw_device_list) for i in range(size): name = tf_session.TF_DeviceListName(raw_device_list, i, status) device_type = tf_session.TF_DeviceListType(raw_device_list, i, status) memory = tf_session.TF_DeviceListMemoryBytes(raw_device_list, i, status) device_list.append(_DeviceAttributes(name, device_type, memory)) tf_session.TF_DeleteDeviceList(raw_device_list) return device_list
107 def gpu_device_names(): 108 ''' 109 :returns, list of gpu device name, num of gpus 110 ''' 111 devices = [] 112 for x in device_lib.list_local_devices(): #pylint: disable=invalid-name 113 if x.device_type == 'GPU': 114 devices.append(tf.compat.as_text(x.name)) 115 return devices, len(devices)