Lists available devices in this session. ```python devices = sess.list_devices() for d in devices: print(d.name) ``` Where: Each element in the list has the following properties name: A string with the full name of the device. ex: `/job:worker/replic
(self)
| 707 | tf_session.TF_DeleteSessionOptions(opts) |
| 708 | |
| 709 | def list_devices(self): |
| 710 | """Lists available devices in this session. |
| 711 | |
| 712 | ```python |
| 713 | devices = sess.list_devices() |
| 714 | for d in devices: |
| 715 | print(d.name) |
| 716 | ``` |
| 717 | |
| 718 | Where: |
| 719 | Each element in the list has the following properties |
| 720 | name: A string with the full name of the device. ex: |
| 721 | `/job:worker/replica:0/task:3/device:CPU:0` |
| 722 | device_type: The type of the device (e.g. `CPU`, `GPU`, `TPU`.) |
| 723 | memory_limit: The maximum amount of memory available on the device. |
| 724 | Note: depending on the device, it is possible the usable memory could |
| 725 | be substantially less. |
| 726 | |
| 727 | Raises: |
| 728 | tf.errors.OpError: If it encounters an error (e.g. session is in an |
| 729 | invalid state, or network errors occur). |
| 730 | |
| 731 | Returns: |
| 732 | A list of devices in the session. |
| 733 | """ |
| 734 | raw_device_list = tf_session.TF_SessionListDevices(self._session) |
| 735 | device_list = [] |
| 736 | size = tf_session.TF_DeviceListCount(raw_device_list) |
| 737 | for i in range(size): |
| 738 | name = tf_session.TF_DeviceListName(raw_device_list, i) |
| 739 | device_type = tf_session.TF_DeviceListType(raw_device_list, i) |
| 740 | memory = tf_session.TF_DeviceListMemoryBytes(raw_device_list, i) |
| 741 | incarnation = tf_session.TF_DeviceListIncarnation(raw_device_list, i) |
| 742 | device_list.append( |
| 743 | _DeviceAttributes(name, device_type, memory, incarnation)) |
| 744 | tf_session.TF_DeleteDeviceList(raw_device_list) |
| 745 | return device_list |
| 746 | |
| 747 | def close(self): |
| 748 | """Closes this session. |