Skip to content

Commit

Permalink
Support for device list
Browse files Browse the repository at this point in the history
  • Loading branch information
dstogov committed May 23, 2018
1 parent 5d3303b commit 7ec79fc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
30 changes: 30 additions & 0 deletions TensorFlow.php
Expand Up @@ -800,6 +800,36 @@ public function __destruct() {
$this->close();
}

public function devices() {
$ret = [];
$list = self::$ffi->TF_SessionListDevices($this->c, $this->status->c);
if ($this->status->code() != OK) {
throw new \Exception($this->status->error());
}
$count = self::$ffi->TF_DeviceListCount($list);
for ($i = 0; $i < $count; $i++) {
$name = self::$ffi->TF_DeviceListName($list, $i, $this->status->c);
if ($this->status->code() != OK) {
throw new \Exception($this->status->error());
}
$type = self::$ffi->TF_DeviceListType($list, $i, $this->status->c);
if ($this->status->code() != OK) {
throw new \Exception($this->status->error());
}
$mem = self::$ffi->TF_DeviceListMemoryBytes($list, $i, $this->status->c);
if ($this->status->code() != OK) {
throw new \Exception($this->status->error());
}
$dev = new \stdClass(); //??
$dev->name = $name;
$dev->type = $type;
$dev->mem = $mem;
$ret[] = $dev;
}
self::$ffi->TF_DeleteDeviceList($list);
return $ret;
}

public function close() {
if (!is_null($this->c)) {
self::$ffi->TF_CloseSession($this->c, $this->status->c);
Expand Down
6 changes: 6 additions & 0 deletions test_dev.php
@@ -0,0 +1,6 @@
<?php
require_once("TensorFlow.php");

$tf = new TensorFlow();
$sess = $tf->session();
var_dump($sess->devices());

0 comments on commit 7ec79fc

Please sign in to comment.