aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/go/session.go
diff options
context:
space:
mode:
Diffstat (limited to 'tensorflow/go/session.go')
-rw-r--r--tensorflow/go/session.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/tensorflow/go/session.go b/tensorflow/go/session.go
index fc914f86df..db6ae4f26c 100644
--- a/tensorflow/go/session.go
+++ b/tensorflow/go/session.go
@@ -65,6 +65,51 @@ func NewSession(graph *Graph, options *SessionOptions) (*Session, error) {
return s, nil
}
+// Device structure contains information about a device associated with a session, as returned by ListDevices()
+type Device struct {
+ Name, Type string
+ MemoryLimitBytes int64
+}
+
+// Return list of devices associated with a Session
+func (s *Session) ListDevices() ([]Device, error) {
+ var devices []Device
+
+ status := newStatus()
+ devices_list := C.TF_SessionListDevices(s.c, status.c)
+ if err := status.Err(); err != nil {
+ return nil, fmt.Errorf("SessionListDevices() failed: %v", err)
+ }
+ defer C.TF_DeleteDeviceList(devices_list)
+
+ for i := 0; i < int(C.TF_DeviceListCount(devices_list)); i++ {
+ device_name := C.TF_DeviceListName(devices_list, C.int(i), status.c)
+ if err := status.Err(); err != nil {
+ return nil, fmt.Errorf("DeviceListName(index=%d) failed: %v", i, err)
+ }
+
+ device_type := C.TF_DeviceListType(devices_list, C.int(i), status.c)
+ if err := status.Err(); err != nil {
+ return nil, fmt.Errorf("DeviceListType(index=%d) failed: %v", i, err)
+ }
+
+ memory_limit_bytes := C.TF_DeviceListMemoryBytes(devices_list, C.int(i), status.c)
+ if err := status.Err(); err != nil {
+ return nil, fmt.Errorf("DeviceListMemoryBytes(index=%d) failed: %v", i, err)
+ }
+
+ device := Device{
+ Name: C.GoString(device_name),
+ Type: C.GoString(device_type),
+ MemoryLimitBytes: int64(memory_limit_bytes),
+ }
+
+ devices = append(devices, device)
+ }
+
+ return devices, nil
+}
+
// Run the graph with the associated session starting with the supplied feeds
// to compute the value of the requested fetches. Runs, but does not return
// Tensors for operations specified in targets.