tf.config.list_logical_devices
Stay organized with collections
Save and categorize content based on your preferences.
Return a list of logical devices created by runtime.
tf.config.list_logical_devices(
device_type=None
)
Logical devices may correspond to physical devices or remote devices in the
cluster. Operations and tensors may be placed on these devices by using the
name
of the tf.config.LogicalDevice
.
Calling tf.config.list_logical_devices
triggers the runtime to configure any
tf.config.PhysicalDevice
visible to the runtime, thereby preventing
further configuration. To avoid runtime initialization, call
tf.config.list_physical_devices
instead.
For example:
logical_devices = tf.config.list_logical_devices('GPU')
if len(logical_devices) > 0:
# Allocate on GPU:0
with tf.device(logical_devices[0].name):
one = tf.constant(1)
# Allocate on GPU:1
with tf.device(logical_devices[1].name):
two = tf.constant(2)
Args |
device_type
|
(optional string) Only include devices matching this device
type. For example "CPU" or "GPU".
|
Returns |
List of initialized LogicalDevice s
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2023-10-06 UTC.
[null,null,["Last updated 2023-10-06 UTC."],[],[],null,["# tf.config.list_logical_devices\n\n\u003cbr /\u003e\n\n|--------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.14.0/tensorflow/python/framework/config.py#L458-L491) |\n\nReturn a list of logical devices created by runtime.\n\n#### View aliases\n\n\n**Main aliases**\n\n[`tf.config.experimental.list_logical_devices`](https://www.tensorflow.org/api_docs/python/tf/config/list_logical_devices)\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.config.experimental.list_logical_devices`](https://www.tensorflow.org/api_docs/python/tf/config/list_logical_devices), [`tf.compat.v1.config.list_logical_devices`](https://www.tensorflow.org/api_docs/python/tf/config/list_logical_devices)\n\n\u003cbr /\u003e\n\n tf.config.list_logical_devices(\n device_type=None\n )\n\nLogical devices may correspond to physical devices or remote devices in the\ncluster. Operations and tensors may be placed on these devices by using the\n`name` of the [`tf.config.LogicalDevice`](../../tf/config/LogicalDevice).\n\nCalling [`tf.config.list_logical_devices`](../../tf/config/list_logical_devices) triggers the runtime to configure any\n[`tf.config.PhysicalDevice`](../../tf/config/PhysicalDevice) visible to the runtime, thereby preventing\nfurther configuration. To avoid runtime initialization, call\n[`tf.config.list_physical_devices`](../../tf/config/list_physical_devices) instead.\n\n#### For example:\n\n logical_devices = tf.config.list_logical_devices('GPU')\n if len(logical_devices) \u003e 0:\n # Allocate on GPU:0\n with tf.device(logical_devices[0].name):\n one = tf.constant(1)\n # Allocate on GPU:1\n with tf.device(logical_devices[1].name):\n two = tf.constant(2)\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|---------------|-----------------------------------------------------------------------------------------------|\n| `device_type` | (optional string) Only include devices matching this device type. For example \"CPU\" or \"GPU\". |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| List of initialized `LogicalDevice`s ||\n\n\u003cbr /\u003e"]]