| 42 | static thread::ThreadPool* worker_threads; |
| 43 | |
| 44 | void 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 |
no test coverage detected