| 361 | } |
| 362 | |
| 363 | Status GrpcSession::ListDevices(std::vector<DeviceAttributes>* response) { |
| 364 | ListDevicesRequest req; |
| 365 | { |
| 366 | mutex_lock l(mu_); |
| 367 | req.set_session_handle(handle_); |
| 368 | } |
| 369 | if (req.session_handle().empty()) { |
| 370 | LOG(WARNING) << "GrpcSession::ListDevices will initialize the session with " |
| 371 | "an empty graph and other defaults because the session has " |
| 372 | "not yet been created."; |
| 373 | GraphDef graph_def; |
| 374 | TF_RETURN_IF_ERROR(Create(graph_def)); |
| 375 | { |
| 376 | mutex_lock l(mu_); |
| 377 | req.set_session_handle(handle_); |
| 378 | } |
| 379 | } |
| 380 | ListDevicesResponse resp; |
| 381 | CallOptions call_options; |
| 382 | call_options.SetTimeout(options_.config.operation_timeout_in_ms()); |
| 383 | Status s = master_->ListDevices(&call_options, &req, &resp); |
| 384 | if (!s.ok()) { |
| 385 | LOG(ERROR) << "Could not list devices: " << s; |
| 386 | return s; |
| 387 | } |
| 388 | |
| 389 | response->clear(); |
| 390 | response->reserve(resp.local_device_size() + resp.remote_device_size()); |
| 391 | for (const auto& device_attr : resp.local_device()) { |
| 392 | response->emplace_back(device_attr); |
| 393 | } |
| 394 | for (const auto& device_attr : resp.remote_device()) { |
| 395 | response->emplace_back(device_attr); |
| 396 | } |
| 397 | return Status::OK(); |
| 398 | } |
| 399 | |
| 400 | void GrpcSession::SetRemoteMaster(std::unique_ptr<MasterInterface> master) { |
| 401 | master_ = std::move(master); |