From 2173b5b0a58a3c28fe11494157e38004fe549d6b Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Thu, 10 Aug 2017 15:11:10 -0700 Subject: Allow TFE_TensorHandleCopyToDevice to have the same device as src and destination. It will reuse the same underlying buffer in those cases. PiperOrigin-RevId: 164909906 --- tensorflow/c/eager/c_api_test.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'tensorflow/c/eager/c_api_test.cc') diff --git a/tensorflow/c/eager/c_api_test.cc b/tensorflow/c/eager/c_api_test.cc index 797506422b..6614df78d9 100644 --- a/tensorflow/c/eager/c_api_test.cc +++ b/tensorflow/c/eager/c_api_test.cc @@ -170,14 +170,22 @@ TEST(CAPI, TensorHandleCopyBetweenDevices) { ADD_FAILURE() << tag << " -- " << TF_Message(status.get()); continue; } + // Copy from device to the same device. + TFE_TensorHandle* hdevice2 = + TFE_TensorHandleCopyToDevice(hdevice, ctx, name.c_str(), status.get()); + if (TF_GetCode(status.get()) != TF_OK) { + ADD_FAILURE() << tag << " -- " << TF_Message(status.get()); + continue; + } + TFE_DeleteTensorHandle(hdevice); // Copy back to CPU TFE_TensorHandle* hcopy = - TFE_TensorHandleCopyToDevice(hdevice, ctx, kCPUDevice, status.get()); + TFE_TensorHandleCopyToDevice(hdevice2, ctx, kCPUDevice, status.get()); if (TF_GetCode(status.get()) != TF_OK) { ADD_FAILURE() << tag << " -- " << TF_Message(status.get()); continue; } - TFE_DeleteTensorHandle(hdevice); + TFE_DeleteTensorHandle(hdevice2); // Ensure that the contents are the same! TF_Tensor* tcopy = TFE_TensorHandleResolve(hcopy, status.get()); -- cgit v1.2.3