| 866 | } |
| 867 | |
| 868 | void 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 | |
| 899 | TEST(CAPI, TensorHandleNullptr) { |
| 900 | TFE_TensorHandle* h = nullptr; |
nothing calls this directly
no test coverage detected