| 28 | } |
| 29 | |
| 30 | tensorflow::Status DelegateData::Prepare( |
| 31 | const tensorflow::SessionOptions& session_options) { |
| 32 | if (eager_context_) { |
| 33 | return tensorflow::Status(); |
| 34 | } |
| 35 | |
| 36 | std::vector<std::unique_ptr<tensorflow::Device>> devices; |
| 37 | |
| 38 | TF_RETURN_IF_ERROR(tensorflow::DeviceFactory::AddDevices( |
| 39 | session_options, "/job:localhost/replica:0/task:0", &devices)); |
| 40 | |
| 41 | auto device_mgr = |
| 42 | absl::make_unique<tensorflow::DeviceMgr>(std::move(devices)); |
| 43 | // Note that Rendezvous is ref-counted so it will be automatically deleted. |
| 44 | tensorflow::Rendezvous* rendezvous = |
| 45 | new tensorflow::IntraProcessRendezvous(device_mgr.get()); |
| 46 | eager_context_ = new tensorflow::EagerContext( |
| 47 | session_options, |
| 48 | tensorflow::ContextDevicePlacementPolicy::DEVICE_PLACEMENT_SILENT, |
| 49 | tensorflow::ContextMirroringPolicy::MIRRORING_NONE, |
| 50 | /*async=*/false, device_mgr.release(), /*device_mgr_owned*/ true, |
| 51 | rendezvous, nullptr); |
| 52 | return tensorflow::Status(); |
| 53 | } |
| 54 | |
| 55 | } // namespace flex |
| 56 | } // namespace tflite |