| 817 | TEST(CAPI, TensorHandleSilentCopyAsync) { TensorHandleSilentCopy(true); } |
| 818 | |
| 819 | void TensorHandleSilentCopyLocal(bool async) { |
| 820 | std::unique_ptr<TF_Status, decltype(&TF_DeleteStatus)> status( |
| 821 | TF_NewStatus(), TF_DeleteStatus); |
| 822 | TFE_ContextOptions* opts = TFE_NewContextOptions(); |
| 823 | TFE_ContextOptionsSetAsync(opts, static_cast<unsigned char>(async)); |
| 824 | TFE_ContextOptionsSetDevicePlacementPolicy(opts, |
| 825 | TFE_DEVICE_PLACEMENT_EXPLICIT); |
| 826 | TFE_Context* ctx = TFE_NewContext(opts, status.get()); |
| 827 | TFE_ContextSetThreadLocalDevicePlacementPolicy(ctx, |
| 828 | TFE_DEVICE_PLACEMENT_SILENT); |
| 829 | TFE_DeleteContextOptions(opts); |
| 830 | ASSERT_EQ(TF_OK, TF_GetCode(status.get())) << TF_Message(status.get()); |
| 831 | |
| 832 | TFE_TensorHandle* hcpu = TestMatrixTensorHandle(); |
| 833 | TF_Tensor* t = TFE_TensorHandleResolve(hcpu, status.get()); |
| 834 | ASSERT_EQ(TF_OK, TF_GetCode(status.get())) << TF_Message(status.get()); |
| 835 | |
| 836 | // Disable the test if no GPU is present. |
| 837 | string gpu_device_name; |
| 838 | if (GetDeviceName(ctx, &gpu_device_name, "GPU")) { |
| 839 | TFE_TensorHandle* hgpu = TFE_TensorHandleCopyToDevice( |
| 840 | hcpu, ctx, gpu_device_name.c_str(), status.get()); |
| 841 | ASSERT_TRUE(TF_GetCode(status.get()) == TF_OK) << TF_Message(status.get()); |
| 842 | |
| 843 | TFE_Op* matmul = MatMulOp(ctx, hcpu, hgpu); |
| 844 | TFE_OpSetDevice(matmul, gpu_device_name.c_str(), status.get()); |
| 845 | ASSERT_TRUE(TF_GetCode(status.get()) == TF_OK) << TF_Message(status.get()); |
| 846 | TFE_TensorHandle* retvals[1]; |
| 847 | int num_retvals = 1; |
| 848 | TFE_Execute(matmul, &retvals[0], &num_retvals, status.get()); |
| 849 | ASSERT_TRUE(TF_GetCode(status.get()) == TF_OK) << TF_Message(status.get()); |
| 850 | TFE_DeleteOp(matmul); |
| 851 | TFE_DeleteTensorHandle(retvals[0]); |
| 852 | TFE_DeleteTensorHandle(hgpu); |
| 853 | } |
| 854 | |
| 855 | TF_DeleteTensor(t); |
| 856 | TFE_DeleteTensorHandle(hcpu); |
| 857 | TFE_Executor* executor = TFE_ContextGetExecutorForThread(ctx); |
| 858 | TFE_ExecutorWaitForAllPendingNodes(executor, status.get()); |
| 859 | ASSERT_EQ(TF_OK, TF_GetCode(status.get())) << TF_Message(status.get()); |
| 860 | TFE_DeleteExecutor(executor); |
| 861 | TFE_DeleteContext(ctx); |
| 862 | } |
| 863 | TEST(CAPI, TensorHandleSilentCopyLocal) { TensorHandleSilentCopyLocal(false); } |
| 864 | TEST(CAPI, TensorHandleSilentCopyLocalAsync) { |
| 865 | TensorHandleSilentCopyLocal(true); |
no test coverage detected