| 772 | } |
| 773 | |
| 774 | void TensorHandleSilentCopy(bool async) { |
| 775 | std::unique_ptr<TF_Status, decltype(&TF_DeleteStatus)> status( |
| 776 | TF_NewStatus(), TF_DeleteStatus); |
| 777 | TFE_ContextOptions* opts = TFE_NewContextOptions(); |
| 778 | TFE_ContextOptionsSetDevicePlacementPolicy(opts, TFE_DEVICE_PLACEMENT_SILENT); |
| 779 | TFE_ContextOptionsSetAsync(opts, static_cast<unsigned char>(async)); |
| 780 | TFE_Context* ctx = TFE_NewContext(opts, status.get()); |
| 781 | TFE_DeleteContextOptions(opts); |
| 782 | ASSERT_EQ(TF_OK, TF_GetCode(status.get())) << TF_Message(status.get()); |
| 783 | |
| 784 | TFE_TensorHandle* hcpu = TestMatrixTensorHandle(); |
| 785 | TF_Tensor* t = TFE_TensorHandleResolve(hcpu, status.get()); |
| 786 | ASSERT_EQ(TF_OK, TF_GetCode(status.get())) << TF_Message(status.get()); |
| 787 | |
| 788 | // Disable the test if no GPU is present. |
| 789 | string gpu_device_name; |
| 790 | if (GetDeviceName(ctx, &gpu_device_name, "GPU")) { |
| 791 | TFE_TensorHandle* hgpu = TFE_TensorHandleCopyToDevice( |
| 792 | hcpu, ctx, gpu_device_name.c_str(), status.get()); |
| 793 | ASSERT_TRUE(TF_GetCode(status.get()) == TF_OK) << TF_Message(status.get()); |
| 794 | |
| 795 | TFE_Op* matmul = MatMulOp(ctx, hcpu, hgpu); |
| 796 | TFE_OpSetDevice(matmul, gpu_device_name.c_str(), status.get()); |
| 797 | ASSERT_TRUE(TF_GetCode(status.get()) == TF_OK) << TF_Message(status.get()); |
| 798 | TFE_TensorHandle* retvals[1]; |
| 799 | int num_retvals = 1; |
| 800 | TFE_Execute(matmul, &retvals[0], &num_retvals, status.get()); |
| 801 | ASSERT_TRUE(TF_GetCode(status.get()) == TF_OK) << TF_Message(status.get()); |
| 802 | TFE_DeleteOp(matmul); |
| 803 | TFE_DeleteTensorHandle(retvals[0]); |
| 804 | TFE_DeleteTensorHandle(hgpu); |
| 805 | } |
| 806 | |
| 807 | TF_DeleteTensor(t); |
| 808 | TFE_DeleteTensorHandle(hcpu); |
| 809 | TFE_Executor* executor = TFE_ContextGetExecutorForThread(ctx); |
| 810 | TFE_ExecutorWaitForAllPendingNodes(executor, status.get()); |
| 811 | ASSERT_EQ(TF_OK, TF_GetCode(status.get())) << TF_Message(status.get()); |
| 812 | TFE_DeleteExecutor(executor); |
| 813 | TFE_DeleteContext(ctx); |
| 814 | } |
| 815 | |
| 816 | TEST(CAPI, TensorHandleSilentCopy) { TensorHandleSilentCopy(false); } |
| 817 | TEST(CAPI, TensorHandleSilentCopyAsync) { TensorHandleSilentCopy(true); } |
no test coverage detected