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

Function MakeGRPCCluster

tensorflow/core/distributed_runtime/rpcbench_test.cc:44–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42static thread::ThreadPool* worker_threads;
43
44void MakeGRPCCluster(const SessionOptions& options, int n,
45 std::vector<string>* workers,
46 std::vector<DeviceAttributes>* devices) {
47 CHECK_GE(n, 1);
48
49 workers->clear();
50 std::vector<int> port(n);
51 for (int i = 0; i < n; ++i) {
52 port[i] = testing::PickUnusedPortOrDie();
53 workers->push_back(strings::StrCat("grpc://localhost:", port[i]));
54 }
55
56 int num_cpus = 1;
57 int num_gpus = 0;
58 auto iter = options.config.device_count().find("CPU");
59 if (iter != options.config.device_count().end()) {
60 num_cpus = iter->second;
61 }
62 iter = options.config.device_count().find("GPU");
63 if (iter != options.config.device_count().end()) {
64 num_gpus = iter->second;
65 }
66
67 worker_threads = new thread::ThreadPool(Env::Default(), "worker_threads", n);
68 for (int worker_idx = 0; worker_idx < n; ++worker_idx) {
69 worker_threads->Schedule([worker_idx, n, num_cpus, num_gpus, &port] {
70 ServerDef server;
71 server.set_protocol("grpc");
72 server.set_job_name("localhost");
73 server.set_task_index(worker_idx);
74
75 auto job_def = server.mutable_cluster()->add_job();
76 job_def->set_name("localhost");
77 for (int i = 0; i < n; i++) {
78 (*(job_def->mutable_tasks()))[i] =
79 strings::StrCat("localhost:", port[i]);
80 }
81
82 auto config = server.mutable_default_session_config();
83 (*config->mutable_device_count())["CPU"] = num_cpus;
84 (*config->mutable_device_count())["GPU"] = num_gpus;
85
86 std::unique_ptr<ServerInterface> svr;
87 TF_CHECK_OK(NewServer(server, &svr));
88 TF_CHECK_OK(svr->Start());
89 TF_CHECK_OK(svr->Join());
90 });
91 }
92
93 // Get attributes for all devices.
94 LOG(ERROR) << "W '" << (*workers)[0] << "'";
95 SessionOptions options_copy(options);
96 options_copy.target = (*workers)[0];
97 std::unique_ptr<GrpcSession> session;
98 TF_CHECK_OK(GrpcSession::Create(options_copy, &session));
99 TF_CHECK_OK(session->ListDevices(devices));
100}
101

Callers 1

ClusterMethod · 0.85

Calls 15

DefaultFunction · 0.85
NewServerFunction · 0.85
PickUnusedPortOrDieFunction · 0.50
StrCatFunction · 0.50
CreateFunction · 0.50
clearMethod · 0.45
push_backMethod · 0.45
findMethod · 0.45
device_countMethod · 0.45
endMethod · 0.45
ScheduleMethod · 0.45
set_nameMethod · 0.45

Tested by

no test coverage detected