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

Function SetAndGetOpDevices

tensorflow/c/eager/c_api_test.cc:868–897  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

866}
867
868void SetAndGetOpDevices(bool async) {
869 TF_Status* status = TF_NewStatus();
870 TFE_ContextOptions* opts = TFE_NewContextOptions();
871 TFE_Context* ctx = TFE_NewContext(opts, status);
872 CHECK_EQ(TF_OK, TF_GetCode(status)) << TF_Message(status);
873 TFE_DeleteContextOptions(opts);
874
875 TFE_TensorHandle* m = TestMatrixTensorHandle();
876 TFE_Op* matmul = MatMulOp(ctx, m, m);
877
878 // Disable the test if no GPU is present.
879 string gpu_device_name;
880 if (GetDeviceName(ctx, &gpu_device_name, "GPU")) {
881 TFE_OpSetDevice(matmul, "GPU:0", status);
882 ASSERT_TRUE(TF_GetCode(status) == TF_OK) << TF_Message(status);
883 const char* device_name = TFE_OpGetDevice(matmul, status);
884 ASSERT_TRUE(strstr(device_name, "GPU:0") != nullptr);
885
886 TFE_OpSetDevice(matmul, "CPU:0", status);
887 ASSERT_TRUE(TF_GetCode(status) == TF_OK) << TF_Message(status);
888 device_name = TFE_OpGetDevice(matmul, status);
889 ASSERT_TRUE(strstr(device_name, "CPU:0") != nullptr);
890 }
891
892 TFE_DeleteOp(matmul);
893 TFE_DeleteTensorHandle(m);
894 TFE_DeleteContext(ctx);
895 ASSERT_EQ(TF_OK, TF_GetCode(status)) << TF_Message(status);
896 TF_DeleteStatus(status);
897}
898
899TEST(CAPI, TensorHandleNullptr) {
900 TFE_TensorHandle* h = nullptr;

Callers

nothing calls this directly

Calls 15

TF_NewStatusFunction · 0.85
TFE_NewContextOptionsFunction · 0.85
TFE_NewContextFunction · 0.85
TF_GetCodeFunction · 0.85
TF_MessageFunction · 0.85
TFE_DeleteContextOptionsFunction · 0.85
TestMatrixTensorHandleFunction · 0.85
TFE_OpSetDeviceFunction · 0.85
TFE_OpGetDeviceFunction · 0.85
TFE_DeleteOpFunction · 0.85
TFE_DeleteTensorHandleFunction · 0.85
TFE_DeleteContextFunction · 0.85

Tested by

no test coverage detected