| 61 | } // namespace |
| 62 | |
| 63 | EagerContext::EagerContext( |
| 64 | const SessionOptions& opts, |
| 65 | ContextDevicePlacementPolicy default_device_placement_policy, |
| 66 | ContextMirroringPolicy default_mirroring_policy, bool async, |
| 67 | const DeviceMgr* device_mgr, bool device_mgr_owned, Rendezvous* rendezvous, |
| 68 | const CustomKernelCreator* custom_kernel_creator, |
| 69 | DistributedFunctionLibraryRuntime* cluster_flr) |
| 70 | : default_device_placement_policy_(default_device_placement_policy), |
| 71 | default_mirroring_policy_(default_mirroring_policy), |
| 72 | devices_(device_mgr->ListDevices()), |
| 73 | rendezvous_(rendezvous), |
| 74 | thread_pool_(NewThreadPoolFromSessionOptions(opts)), |
| 75 | custom_kernel_creator_(custom_kernel_creator), |
| 76 | pflr_(new ProcessFunctionLibraryRuntime( |
| 77 | device_mgr, opts.env, TF_GRAPH_DEF_VERSION, &func_lib_def_, |
| 78 | opts.config.graph_options().optimizer_options(), thread_pool_.get(), |
| 79 | cluster_flr, custom_kernel_creator_)), |
| 80 | log_device_placement_(opts.config.log_device_placement()), |
| 81 | allow_soft_placement_(opts.config.allow_soft_placement()), |
| 82 | num_active_steps_(0), |
| 83 | default_executor_(async), |
| 84 | log_memory_(LogMemory::IsEnabled()), |
| 85 | env_(opts.env), |
| 86 | use_send_tensor_rpc_(false), |
| 87 | pin_small_ops_to_cpu_(ReadBoolFromEnvVar( |
| 88 | "TF_EAGER_ENABLE_SMALL_TENSOR_CPU_PINNING", false)) { |
| 89 | // Starts exporting metrics through a platform-specific monitoring API (if |
| 90 | // provided). For builds using "tensorflow/core/platform/default", this is |
| 91 | // currently a no-op. |
| 92 | eager_context_created->GetCell()->Set(true); |
| 93 | monitoring::StartExporter(); |
| 94 | if (device_mgr_owned) { |
| 95 | local_device_manager_.reset(device_mgr); |
| 96 | local_unowned_device_manager_ = nullptr; |
| 97 | } else { |
| 98 | local_unowned_device_manager_ = device_mgr; |
| 99 | } |
| 100 | InitDeviceMapAndAsync(); |
| 101 | runner_ = [this](std::function<void()> closure) { |
| 102 | this->thread_pool_->Schedule(std::move(closure)); |
| 103 | }; |
| 104 | |
| 105 | #if !defined(IS_MOBILE_PLATFORM) |
| 106 | context_id_ = kInvalidContextId; |
| 107 | #endif // IS_MOBILE_PLATFORM |
| 108 | |
| 109 | std::unique_ptr<DeviceResolverInterface> drl( |
| 110 | new DeviceResolverLocal(local_device_mgr())); |
| 111 | std::unique_ptr<ParamResolverInterface> cprl(new CollectiveParamResolverLocal( |
| 112 | opts.config, local_device_mgr(), drl.get(), |
| 113 | "/job:localhost/replica:0/task:0")); |
| 114 | collective_executor_mgr_.reset(new CollectiveExecutorMgr( |
| 115 | opts.config, local_device_mgr(), std::move(drl), std::move(cprl))); |
| 116 | } |
| 117 | |
| 118 | void EagerContext::InitDeviceMapAndAsync() { |
| 119 | for (auto* device : devices_) { |
no test coverage detected