Default eager tensor device name should match default device name.
authorAlexandre Passos <apassos@google.com>
Fri, 16 Feb 2018 23:30:46 +0000 (15:30 -0800)
committerTensorFlower Gardener <gardener@tensorflow.org>
Fri, 16 Feb 2018 23:37:26 +0000 (15:37 -0800)
PiperOrigin-RevId: 186055679

tensorflow/c/eager/c_api.cc

index 8e834eb99c13d1f26da9f0860897267efc2fd01c..98ef6f0d0ab094eae3e2e21624c3a4ba30d1c3d3 100644 (file)
@@ -161,10 +161,11 @@ int64_t TFE_TensorHandleDim(TFE_TensorHandle* h, int dim_index) {
 }
 
 const char* TFE_TensorHandleDeviceName(TFE_TensorHandle* h) {
-  // This might be a bit confusing as a tensor on CPU can sometimes return
-  // "CPU:0" and sometimes "/job:localhost/replica:0/task:0/cpu:0".
-  // TODO(ashankar): Figure out which one would be nicer.
-  return (h->d == nullptr) ? "CPU:0" : h->d->name().c_str();
+  // TODO(apassos) this will be potentially incorrect in the distributed case as
+  // our local device will have a name which depends on the ClusterSpec and
+  // hence will require the context to resolve.
+  return (h->d == nullptr) ? "/job:localhost/replica:0/task:0/device:CPU:0"
+                           : h->d->name().c_str();
 }
 
 TF_Tensor* TFE_TensorHandleResolve(TFE_TensorHandle* h, TF_Status* status) {