MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / TensorHandleSilentCopyLocal

Function TensorHandleSilentCopyLocal

tensorflow/c/eager/c_api_test.cc:819–862  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

817TEST(CAPI, TensorHandleSilentCopyAsync) { TensorHandleSilentCopy(true); }
818
819void 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}
863TEST(CAPI, TensorHandleSilentCopyLocal) { TensorHandleSilentCopyLocal(false); }
864TEST(CAPI, TensorHandleSilentCopyLocalAsync) {
865 TensorHandleSilentCopyLocal(true);

Callers 1

TESTFunction · 0.85

Calls 15

TF_NewStatusFunction · 0.85
TFE_NewContextOptionsFunction · 0.85
TFE_NewContextFunction · 0.85
TFE_DeleteContextOptionsFunction · 0.85
TF_GetCodeFunction · 0.85
TF_MessageFunction · 0.85
TestMatrixTensorHandleFunction · 0.85
TFE_TensorHandleResolveFunction · 0.85

Tested by

no test coverage detected