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

Function TestRemoteExecuteChangeServerDef

tensorflow/c/eager/c_api_test.cc:466–551  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

464}
465
466void TestRemoteExecuteChangeServerDef(bool async) {
467 tensorflow::ServerDef server_def = GetServerDef(2);
468
469 // This server def has the task index set to 0.
470 string serialized = server_def.SerializeAsString();
471
472 server_def.set_task_index(1);
473
474 std::unique_ptr<tensorflow::GrpcServer> worker_server;
475 ASSERT_TRUE(tensorflow::GrpcServer::Create(
476 server_def, tensorflow::Env::Default(), &worker_server)
477 .ok());
478 ASSERT_TRUE(worker_server->Start().ok());
479
480 TF_Status* status = TF_NewStatus();
481 TFE_ContextOptions* opts = TFE_NewContextOptions();
482 TFE_ContextOptionsSetAsync(opts, static_cast<unsigned char>(async));
483 TFE_ContextOptionsSetDevicePlacementPolicy(opts, TFE_DEVICE_PLACEMENT_SILENT);
484 TFE_Context* ctx = TFE_NewContext(opts, status);
485 EXPECT_EQ(TF_OK, TF_GetCode(status)) << TF_Message(status);
486 TFE_DeleteContextOptions(opts);
487
488 TFE_ContextSetServerDef(ctx, 0, serialized.data(), serialized.size(), status);
489 EXPECT_EQ(TF_OK, TF_GetCode(status)) << TF_Message(status);
490
491 const char remote_device_name[] =
492 "/job:localhost/replica:0/task:1/device:CPU:0";
493 const char local_device_name[] =
494 "/job:localhost/replica:0/task:0/device:CPU:0";
495 CheckRemoteMatMulExecutesOK(ctx, remote_device_name, local_device_name);
496
497 TFE_Executor* executor = TFE_ContextGetExecutorForThread(ctx);
498 TFE_ExecutorWaitForAllPendingNodes(executor, status);
499 ASSERT_EQ(TF_OK, TF_GetCode(status)) << TF_Message(status);
500
501 // TODO(b/136478427): Figure out how to correctly shut the server down.
502 worker_server.release();
503
504 // Update the server def with a new set of names (worker instead of
505 // localhost).
506 tensorflow::ServerDef updated_server_def = GetServerDef("worker", 2);
507 serialized = updated_server_def.SerializeAsString();
508
509 updated_server_def.set_task_index(1);
510 tensorflow::Status s = tensorflow::GrpcServer::Create(
511 updated_server_def, tensorflow::Env::Default(), &worker_server);
512 ASSERT_TRUE(s.ok()) << s.error_message();
513 ASSERT_TRUE(worker_server->Start().ok());
514
515 TFE_ContextSetServerDef(ctx, 0, serialized.data(), serialized.size(), status);
516 EXPECT_EQ(TF_OK, TF_GetCode(status)) << TF_Message(status);
517
518 // Create a new tensor_handle.
519 TFE_TensorHandle* h0_task0_new = TestMatrixTensorHandle();
520
521 // Check that copying it to the old remote device (named localhost) fails.
522 TFE_TensorHandleCopyToDevice(h0_task0_new, ctx, remote_device_name, status);
523 EXPECT_NE(TF_OK, TF_GetCode(status)) << TF_Message(status);

Callers 1

TESTFunction · 0.85

Calls 15

DefaultFunction · 0.85
TF_NewStatusFunction · 0.85
TFE_NewContextOptionsFunction · 0.85
TFE_NewContextFunction · 0.85
TF_GetCodeFunction · 0.85
TF_MessageFunction · 0.85
TFE_DeleteContextOptionsFunction · 0.85
TFE_ContextSetServerDefFunction · 0.85

Tested by

no test coverage detected