diff --git a/tensorflow/c/eager/c_api.cc b/tensorflow/c/eager/c_api.cc index 291bc10b109..ff16eaf322d 100644 --- a/tensorflow/c/eager/c_api.cc +++ b/tensorflow/c/eager/c_api.cc @@ -122,7 +122,7 @@ tensorflow::Status GetAllRemoteDevices( n.WaitForNotification(); } std::unique_ptr remote_device_mgr( - new tensorflow::DeviceMgr(std::move(remote_devices))); + new tensorflow::StaticDeviceMgr(std::move(remote_devices))); TF_RETURN_IF_ERROR(status); @@ -385,7 +385,7 @@ TFE_Context* TFE_NewContext(const TFE_ContextOptions* opts, TF_Status* status) { &devices); if (!status->status.ok()) return nullptr; std::unique_ptr device_mgr( - new tensorflow::DeviceMgr(std::move(devices))); + new tensorflow::StaticDeviceMgr(std::move(devices))); tensorflow::Rendezvous* r = new tensorflow::IntraProcessRendezvous(device_mgr.get()); diff --git a/tensorflow/compiler/jit/encapsulate_subgraphs_pass.cc b/tensorflow/compiler/jit/encapsulate_subgraphs_pass.cc index e0c0c0b18cc..71f423af4ec 100644 --- a/tensorflow/compiler/jit/encapsulate_subgraphs_pass.cc +++ b/tensorflow/compiler/jit/encapsulate_subgraphs_pass.cc @@ -1193,7 +1193,7 @@ Status EncapsulateSubgraphsPass::Run( } std::unique_ptr device_mgr = - absl::make_unique(std::move(devices)); + absl::make_unique(std::move(devices)); OptimizerOptions opts; std::unique_ptr pflr( new ProcessFunctionLibraryRuntime(device_mgr.get(), diff --git a/tensorflow/compiler/jit/encapsulate_subgraphs_pass_test.cc b/tensorflow/compiler/jit/encapsulate_subgraphs_pass_test.cc index f1979514053..9573c4d3b93 100644 --- a/tensorflow/compiler/jit/encapsulate_subgraphs_pass_test.cc +++ b/tensorflow/compiler/jit/encapsulate_subgraphs_pass_test.cc @@ -510,7 +510,7 @@ Status Encapsulate(GraphDef* graphdef, FunctionDefLibrary* library, TF_CHECK_OK(DeviceFactory::AddDevices( session_options, "/job:localhost/replica:0/task:0", &devices)); OptimizerOptions opts; - auto device_mgr = absl::make_unique(std::move(devices)); + auto device_mgr = absl::make_unique(std::move(devices)); auto pflr = absl::make_unique( device_mgr.get(), Env::Default(), TF_GRAPH_DEF_VERSION, lib_def.get(), opts, /*default_thread_pool=*/nullptr, /*cluster_flr=*/nullptr); diff --git a/tensorflow/compiler/jit/extract_outside_compilation_pass_test.cc b/tensorflow/compiler/jit/extract_outside_compilation_pass_test.cc index 904ca5e4482..fa3ba3bfc4a 100644 --- a/tensorflow/compiler/jit/extract_outside_compilation_pass_test.cc +++ b/tensorflow/compiler/jit/extract_outside_compilation_pass_test.cc @@ -232,7 +232,7 @@ class ExtractOutsideCompilationForFunctionTest : public ::testing::Test { std::vector> devices; TF_CHECK_OK(DeviceFactory::AddDevices( session_options, "/job:localhost/replica:0/task:0", &devices)); - device_mgr_ = absl::make_unique(std::move(devices)); + device_mgr_ = absl::make_unique(std::move(devices)); } Status ExtractOutsideCompilationTest( diff --git a/tensorflow/compiler/jit/xla_kernel_creator_test.cc b/tensorflow/compiler/jit/xla_kernel_creator_test.cc index de930bb2ad4..6ad11c4e028 100644 --- a/tensorflow/compiler/jit/xla_kernel_creator_test.cc +++ b/tensorflow/compiler/jit/xla_kernel_creator_test.cc @@ -71,7 +71,7 @@ class XlaKernelCreatorTest : public ::testing::Test { lib_def_ = absl::make_unique( OpRegistry::Global(), proto); OptimizerOptions opts; - device_mgr_ = absl::make_unique(std::move(devices)); + device_mgr_ = absl::make_unique(std::move(devices)); pflr_ = absl::make_unique( device_mgr_.get(), Env::Default(), TF_GRAPH_DEF_VERSION, lib_def_.get(), opts, /*default_thread_pool=*/nullptr, /*cluster_flr=*/nullptr); diff --git a/tensorflow/compiler/tests/randomized_tests.cc b/tensorflow/compiler/tests/randomized_tests.cc index 7623ab79371..5a2bda93942 100644 --- a/tensorflow/compiler/tests/randomized_tests.cc +++ b/tensorflow/compiler/tests/randomized_tests.cc @@ -3456,7 +3456,7 @@ int main(int argc, char** argv) { std::vector> devices; TF_CHECK_OK(tensorflow::DeviceFactory::AddDevices( tensorflow::SessionOptions(), "", &devices)); - tensorflow::DeviceMgr device_mgr(std::move(devices)); + tensorflow::StaticDeviceMgr device_mgr(std::move(devices)); tensorflow::Device* ignored; TF_QCHECK_OK( diff --git a/tensorflow/compiler/tf2xla/xla_compiler.h b/tensorflow/compiler/tf2xla/xla_compiler.h index 37eb78fbd03..6ab8bde542d 100644 --- a/tensorflow/compiler/tf2xla/xla_compiler.h +++ b/tensorflow/compiler/tf2xla/xla_compiler.h @@ -474,7 +474,7 @@ class XlaCompiler { int64 next_step_id_; XlaCompilationDevice* device_; // Owned by device_mgr_ - DeviceMgr device_mgr_; + StaticDeviceMgr device_mgr_; // To avoid copying the client's function library, use a local function // library and runtime for functions created as part of the functionalize diff --git a/tensorflow/core/common_runtime/buf_rendezvous_test.cc b/tensorflow/core/common_runtime/buf_rendezvous_test.cc index 055cf7d3261..c9a27b53384 100644 --- a/tensorflow/core/common_runtime/buf_rendezvous_test.cc +++ b/tensorflow/core/common_runtime/buf_rendezvous_test.cc @@ -47,7 +47,7 @@ class BufRendezvousTest : public ::testing::Test { const uint64 incarnation) { std::vector> devices; devices.push_back(NewDevice(device, type, incarnation)); - dev_mgr_ = absl::make_unique(std::move(devices)); + dev_mgr_ = absl::make_unique(std::move(devices)); br_ = absl::make_unique(123, dev_mgr_.get()); } diff --git a/tensorflow/core/common_runtime/collective_executor_mgr_test.cc b/tensorflow/core/common_runtime/collective_executor_mgr_test.cc index 3eef5ed0a0c..784ea4adda1 100644 --- a/tensorflow/core/common_runtime/collective_executor_mgr_test.cc +++ b/tensorflow/core/common_runtime/collective_executor_mgr_test.cc @@ -40,7 +40,7 @@ class CollectiveExecutorMgrTest : public ::testing::Test { device_count->insert({"CPU", NUM_DEVS}); std::vector> devices; TF_CHECK_OK(DeviceFactory::AddDevices(options, task_name, &devices)); - device_mgr_.reset(new DeviceMgr(std::move(devices))); + device_mgr_ = absl::make_unique(std::move(devices)); std::unique_ptr drl( new DeviceResolverLocal(device_mgr_.get())); std::unique_ptr prl( diff --git a/tensorflow/core/common_runtime/collective_param_resolver_local_test.cc b/tensorflow/core/common_runtime/collective_param_resolver_local_test.cc index e7bae008a4b..ef85a1eed93 100644 --- a/tensorflow/core/common_runtime/collective_param_resolver_local_test.cc +++ b/tensorflow/core/common_runtime/collective_param_resolver_local_test.cc @@ -39,7 +39,7 @@ class CollectiveParamResolverLocalTest : public ::testing::Test { device_count->insert({"CPU", NUM_DEVS}); std::vector> devices; TF_CHECK_OK(DeviceFactory::AddDevices(options, task_name, &devices)); - device_mgr_.reset(new DeviceMgr(std::move(devices))); + device_mgr_ = absl::make_unique(std::move(devices)); drl_.reset(new DeviceResolverLocal(device_mgr_.get())); prl_.reset(new CollectiveParamResolverLocal(cp, device_mgr_.get(), drl_.get(), task_name)); diff --git a/tensorflow/core/common_runtime/collective_rma_local_test.cc b/tensorflow/core/common_runtime/collective_rma_local_test.cc index 6024359643b..b7b85e3de66 100644 --- a/tensorflow/core/common_runtime/collective_rma_local_test.cc +++ b/tensorflow/core/common_runtime/collective_rma_local_test.cc @@ -46,7 +46,7 @@ class CollectiveRemoteAccessLocalTest : public ::testing::Test { device_count->insert({"CPU", NUM_DEVS}); std::vector> devices; TF_CHECK_OK(DeviceFactory::AddDevices(options, kTaskName, &devices)); - device_mgr_ = absl::make_unique(std::move(devices)); + device_mgr_ = absl::make_unique(std::move(devices)); drl_ = absl::make_unique(device_mgr_.get()); prl_ = absl::make_unique( cp, device_mgr_.get(), drl_.get(), kTaskName); diff --git a/tensorflow/core/common_runtime/data/standalone.cc b/tensorflow/core/common_runtime/data/standalone.cc index 21becb37ed5..75177a1384a 100644 --- a/tensorflow/core/common_runtime/data/standalone.cc +++ b/tensorflow/core/common_runtime/data/standalone.cc @@ -47,7 +47,7 @@ Status Dataset::FromGraph(Params params, const GraphDef& graph_def, TF_RETURN_IF_ERROR(ImportGraphDef({}, graph_def, &graph, nullptr)); // Instantiate enough of the TF runtime to run `graph` on a single CPU device. - auto device_mgr = absl::make_unique(DeviceFactory::NewDevice( + auto device_mgr = absl::make_unique(DeviceFactory::NewDevice( "CPU", params.session_options, "/job:localhost/replica:0/task:0")); Device* device = device_mgr->ListDevices()[0]; // Clone the `FunctionLibraryDefinition` to extend its lifetime extends beyond diff --git a/tensorflow/core/common_runtime/device_mgr.cc b/tensorflow/core/common_runtime/device_mgr.cc index 56ac71d7d09..e9512d06c98 100644 --- a/tensorflow/core/common_runtime/device_mgr.cc +++ b/tensorflow/core/common_runtime/device_mgr.cc @@ -25,7 +25,9 @@ limitations under the License. namespace tensorflow { -DeviceMgr::DeviceMgr(std::vector> devices) +DeviceMgr::~DeviceMgr() {} + +StaticDeviceMgr::StaticDeviceMgr(std::vector> devices) : devices_(std::move(devices)), name_backing_store_(128) { for (auto& d : devices_) { // Register under the (1) full name and (2) canonical name. @@ -42,14 +44,14 @@ DeviceMgr::DeviceMgr(std::vector> devices) } } -DeviceMgr::DeviceMgr(std::unique_ptr device) - : DeviceMgr([&device] { +StaticDeviceMgr::StaticDeviceMgr(std::unique_ptr device) + : StaticDeviceMgr([&device] { std::vector> vector; vector.push_back(std::move(device)); return vector; }()) {} -DeviceMgr::~DeviceMgr() { +StaticDeviceMgr::~StaticDeviceMgr() { // Release resources ahead of destroying the device manager as the resource // destructors (e.g. ~IteratorResource) assume devices still exist. for (auto& device : devices_) { @@ -57,14 +59,14 @@ DeviceMgr::~DeviceMgr() { } } -StringPiece DeviceMgr::CopyToBackingStore(StringPiece s) { +StringPiece StaticDeviceMgr::CopyToBackingStore(StringPiece s) { size_t n = s.size(); char* space = name_backing_store_.Alloc(n); memcpy(space, s.data(), n); return StringPiece(space, n); } -void DeviceMgr::ListDeviceAttributes( +void StaticDeviceMgr::ListDeviceAttributes( std::vector* devices) const { devices->reserve(devices_.size()); for (const auto& dev : devices_) { @@ -72,7 +74,7 @@ void DeviceMgr::ListDeviceAttributes( } } -std::vector DeviceMgr::ListDevices() const { +std::vector StaticDeviceMgr::ListDevices() const { std::vector devices(devices_.size()); for (size_t i = 0; i < devices_.size(); ++i) { devices[i] = devices_[i].get(); @@ -80,7 +82,7 @@ std::vector DeviceMgr::ListDevices() const { return devices; } -string DeviceMgr::DebugString() const { +string StaticDeviceMgr::DebugString() const { string out; for (const auto& dev : devices_) { strings::StrAppend(&out, dev->name(), "\n"); @@ -88,7 +90,7 @@ string DeviceMgr::DebugString() const { return out; } -string DeviceMgr::DeviceMappingString() const { +string StaticDeviceMgr::DeviceMappingString() const { string out; for (const auto& dev : devices_) { if (!dev->attributes().physical_device_desc().empty()) { @@ -99,7 +101,7 @@ string DeviceMgr::DeviceMappingString() const { return out; } -Status DeviceMgr::LookupDevice(StringPiece name, Device** device) const { +Status StaticDeviceMgr::LookupDevice(StringPiece name, Device** device) const { auto iter = device_map_.find(name); if (iter == device_map_.end()) { std::vector device_names; @@ -114,7 +116,8 @@ Status DeviceMgr::LookupDevice(StringPiece name, Device** device) const { return Status::OK(); } -void DeviceMgr::ClearContainers(gtl::ArraySlice containers) const { +void StaticDeviceMgr::ClearContainers( + gtl::ArraySlice containers) const { Status s; for (const auto& dev : devices_) { if (containers.empty()) { @@ -131,7 +134,7 @@ void DeviceMgr::ClearContainers(gtl::ArraySlice containers) const { } } -int DeviceMgr::NumDeviceType(const string& type) const { +int StaticDeviceMgr::NumDeviceType(const string& type) const { auto iter = device_type_counts_.find(type); if (iter != device_type_counts_.end()) return iter->second; return 0; diff --git a/tensorflow/core/common_runtime/device_mgr.h b/tensorflow/core/common_runtime/device_mgr.h index 3cef631bd0a..d29653773cd 100644 --- a/tensorflow/core/common_runtime/device_mgr.h +++ b/tensorflow/core/common_runtime/device_mgr.h @@ -33,38 +33,57 @@ namespace tensorflow { class DeviceAttributes; +// Represents a set of devices. class DeviceMgr { public: - // Constructs a DeviceMgr from a list of devices. - // TODO(zhifengc): Other initialization information. - explicit DeviceMgr(std::vector> devices); - - // Constructs a DeviceMgr managing a single device. - explicit DeviceMgr(std::unique_ptr device); - - ~DeviceMgr(); + DeviceMgr() = default; + virtual ~DeviceMgr(); // Returns attributes of all devices. - void ListDeviceAttributes(std::vector* devices) const; + virtual void ListDeviceAttributes( + std::vector* devices) const = 0; // Returns raw pointers to the underlying devices. - std::vector ListDevices() const; + virtual std::vector ListDevices() const = 0; // Returns a string listing all devices. - string DebugString() const; + virtual string DebugString() const = 0; // Returns a string of all the device mapping. - string DeviceMappingString() const; + virtual string DeviceMappingString() const = 0; // Assigns *device with pointer to Device of the given name. // Accepts either a full device name, or just the replica-local suffix. - Status LookupDevice(StringPiece name, Device** device) const; + virtual Status LookupDevice(StringPiece name, Device** device) const = 0; // Clears given containers of all devices if 'container' is // non-empty. Otherwise, clears default containers of all devices. - void ClearContainers(gtl::ArraySlice containers) const; + virtual void ClearContainers(gtl::ArraySlice containers) const = 0; - int NumDeviceType(const string& type) const; + virtual int NumDeviceType(const string& type) const = 0; + + TF_DISALLOW_COPY_AND_ASSIGN(DeviceMgr); +}; + +// Represents a static set of devices. +class StaticDeviceMgr : public DeviceMgr { + public: + // Constructs a StaticDeviceMgr from a list of devices. + explicit StaticDeviceMgr(std::vector> devices); + + // Constructs a StaticDeviceMgr managing a single device. + explicit StaticDeviceMgr(std::unique_ptr device); + + ~StaticDeviceMgr() override; + + void ListDeviceAttributes( + std::vector* devices) const override; + std::vector ListDevices() const override; + string DebugString() const override; + string DeviceMappingString() const override; + Status LookupDevice(StringPiece name, Device** device) const override; + void ClearContainers(gtl::ArraySlice containers) const override; + int NumDeviceType(const string& type) const override; private: const std::vector> devices_; @@ -75,9 +94,8 @@ class DeviceMgr { core::Arena name_backing_store_; // Storage for keys in device_map_ std::unordered_map device_type_counts_; - TF_DISALLOW_COPY_AND_ASSIGN(DeviceMgr); + TF_DISALLOW_COPY_AND_ASSIGN(StaticDeviceMgr); }; - } // namespace tensorflow #endif // TENSORFLOW_CORE_COMMON_RUNTIME_DEVICE_MGR_H_ diff --git a/tensorflow/core/common_runtime/device_resolver_local_test.cc b/tensorflow/core/common_runtime/device_resolver_local_test.cc index 45c74184b28..0ddf36907d8 100644 --- a/tensorflow/core/common_runtime/device_resolver_local_test.cc +++ b/tensorflow/core/common_runtime/device_resolver_local_test.cc @@ -37,7 +37,7 @@ class DeviceResolverLocalTest : public ::testing::Test { device_count->insert({"CPU", NUM_DEVS}); std::vector> devices; TF_CHECK_OK(DeviceFactory::AddDevices(options, task_name, &devices)); - device_mgr_.reset(new DeviceMgr(std::move(devices))); + device_mgr_ = absl::make_unique(std::move(devices)); drl_.reset(new DeviceResolverLocal(device_mgr_.get())); } diff --git a/tensorflow/core/common_runtime/direct_session.cc b/tensorflow/core/common_runtime/direct_session.cc index c95a23bfdcf..fb414b59605 100644 --- a/tensorflow/core/common_runtime/direct_session.cc +++ b/tensorflow/core/common_runtime/direct_session.cc @@ -188,8 +188,8 @@ class DirectSessionFactory : public SessionFactory { TF_RETURN_IF_ERROR(DeviceFactory::AddDevices( options, "/job:localhost/replica:0/task:0", &devices)); - DirectSession* session = - new DirectSession(options, new DeviceMgr(std::move(devices)), this); + DirectSession* session = new DirectSession( + options, new StaticDeviceMgr(std::move(devices)), this); { mutex_lock l(sessions_lock_); sessions_.push_back(session); diff --git a/tensorflow/core/common_runtime/eager/kernel_and_device_test.cc b/tensorflow/core/common_runtime/eager/kernel_and_device_test.cc index 7925a417bf3..94c524d8427 100644 --- a/tensorflow/core/common_runtime/eager/kernel_and_device_test.cc +++ b/tensorflow/core/common_runtime/eager/kernel_and_device_test.cc @@ -45,7 +45,7 @@ class TestEnv { devices.push_back( DeviceFactory::NewDevice("CPU", {}, "/job:a/replica:0/task:0")); cpu_device_ = devices.back().get(); - device_mgr_ = absl::make_unique(std::move(devices)); + device_mgr_ = absl::make_unique(std::move(devices)); OptimizerOptions opts; pflr_ = tensorflow::MakeUnique( device_mgr_.get(), Env::Default(), TF_GRAPH_DEF_VERSION, &flib_def_, diff --git a/tensorflow/core/common_runtime/function_test.cc b/tensorflow/core/common_runtime/function_test.cc index 2f5cef30a6e..7b6c1b6113e 100644 --- a/tensorflow/core/common_runtime/function_test.cc +++ b/tensorflow/core/common_runtime/function_test.cc @@ -162,7 +162,7 @@ class FunctionLibraryRuntimeTest : public ::testing::Test { for (const auto& fdef : flib) *(proto.add_function()) = fdef; lib_def_.reset(new FunctionLibraryDefinition(OpRegistry::Global(), proto)); OptimizerOptions opts; - device_mgr_ = absl::make_unique(std::move(devices)); + device_mgr_ = absl::make_unique(std::move(devices)); pflr_.reset(new ProcessFunctionLibraryRuntime( device_mgr_.get(), Env::Default(), TF_GRAPH_DEF_VERSION, lib_def_.get(), opts)); diff --git a/tensorflow/core/common_runtime/function_threadpool_test.cc b/tensorflow/core/common_runtime/function_threadpool_test.cc index 81432918343..fdacacc11ce 100644 --- a/tensorflow/core/common_runtime/function_threadpool_test.cc +++ b/tensorflow/core/common_runtime/function_threadpool_test.cc @@ -62,7 +62,7 @@ class FunctionLibraryRuntimeTest : public ::testing::Test { for (const auto& fdef : flib) *(proto.add_function()) = fdef; lib_def_.reset(new FunctionLibraryDefinition(OpRegistry::Global(), proto)); OptimizerOptions opts; - device_mgr_.reset(new DeviceMgr(std::move(devices))); + device_mgr_ = absl::make_unique(std::move(devices)); pflr_.reset(new ProcessFunctionLibraryRuntime( device_mgr_.get(), Env::Default(), TF_GRAPH_DEF_VERSION, lib_def_.get(), opts, default_thread_pool)); diff --git a/tensorflow/core/common_runtime/hierarchical_tree_broadcaster_test.cc b/tensorflow/core/common_runtime/hierarchical_tree_broadcaster_test.cc index c00645a3ec3..bd8ce352389 100644 --- a/tensorflow/core/common_runtime/hierarchical_tree_broadcaster_test.cc +++ b/tensorflow/core/common_runtime/hierarchical_tree_broadcaster_test.cc @@ -247,7 +247,7 @@ class HierarchicalTreeBroadcasterTest : public ::testing::Test { } } if (!dev_mgr_ || device_type == DEVICE_CPU) { - dev_mgr_ = absl::make_unique(std::move(local_devices)); + dev_mgr_ = absl::make_unique(std::move(local_devices)); } if (!gpu_ring_order_) { gpu_ring_order_ = absl::make_unique(); diff --git a/tensorflow/core/common_runtime/partitioning_utils_test.cc b/tensorflow/core/common_runtime/partitioning_utils_test.cc index 9a3f3a68e34..86fa68d03d7 100644 --- a/tensorflow/core/common_runtime/partitioning_utils_test.cc +++ b/tensorflow/core/common_runtime/partitioning_utils_test.cc @@ -47,7 +47,7 @@ class PartitioningUtilsTest : public ::testing::Test { &devices)); device0_ = devices[0].get(); device1_ = devices[1].get(); - device_mgr_.reset(new DeviceMgr(std::move(devices))); + device_mgr_ = absl::make_unique(std::move(devices)); for (auto d : device_mgr_->ListDevices()) { device_set_.AddDevice(d); diff --git a/tensorflow/core/common_runtime/process_function_library_runtime_test.cc b/tensorflow/core/common_runtime/process_function_library_runtime_test.cc index f231bc1624b..0294168dfa0 100644 --- a/tensorflow/core/common_runtime/process_function_library_runtime_test.cc +++ b/tensorflow/core/common_runtime/process_function_library_runtime_test.cc @@ -94,7 +94,7 @@ class ProcessFunctionLibraryRuntimeTest : public ::testing::Test { std::vector> devices; TF_CHECK_OK(DeviceFactory::AddDevices(options, "/job:a/replica:0/task:0", &devices)); - device_mgr_.reset(new DeviceMgr(std::move(devices))); + device_mgr_ = absl::make_unique(std::move(devices)); TF_CHECK_OK(device_mgr_->LookupDevice( "/job:a/replica:0/task:0/device:CPU:0", &device0_)); TF_CHECK_OK(device_mgr_->LookupDevice( diff --git a/tensorflow/core/common_runtime/ring_gatherer_test.cc b/tensorflow/core/common_runtime/ring_gatherer_test.cc index a5648684906..0e3cbf7356d 100644 --- a/tensorflow/core/common_runtime/ring_gatherer_test.cc +++ b/tensorflow/core/common_runtime/ring_gatherer_test.cc @@ -167,7 +167,7 @@ class RingGathererTest : public ::testing::Test { if (!dev_mgr_ || device_type == DEVICE_CPU) { LOG(ERROR) << "resetting dev_mgr for " << local_devices.size() << " devices: "; - dev_mgr_ = absl::make_unique(std::move(local_devices)); + dev_mgr_ = absl::make_unique(std::move(local_devices)); } if (!gpu_ring_order_) { gpu_ring_order_ = absl::make_unique(); diff --git a/tensorflow/core/common_runtime/ring_reducer_test.cc b/tensorflow/core/common_runtime/ring_reducer_test.cc index 6141d332dd0..921b3c97e29 100644 --- a/tensorflow/core/common_runtime/ring_reducer_test.cc +++ b/tensorflow/core/common_runtime/ring_reducer_test.cc @@ -189,7 +189,7 @@ class RingReducerTest : public ::testing::Test { if (!dev_mgr_ || device_type == DEVICE_CPU) { LOG(INFO) << "resetting dev_mgr for " << local_devices.size() << " devices: "; - dev_mgr_ = absl::make_unique(std::move(local_devices)); + dev_mgr_ = absl::make_unique(std::move(local_devices)); } if (!gpu_ring_order_) { gpu_ring_order_ = absl::make_unique(); diff --git a/tensorflow/core/distributed_runtime/collective_param_resolver_distributed_test.cc b/tensorflow/core/distributed_runtime/collective_param_resolver_distributed_test.cc index b4869dcb8be..aba84864f08 100644 --- a/tensorflow/core/distributed_runtime/collective_param_resolver_distributed_test.cc +++ b/tensorflow/core/distributed_runtime/collective_param_resolver_distributed_test.cc @@ -165,7 +165,7 @@ class DeviceResDistTest : public ::testing::Test { device_type, strings::StrCat(worker_name, "/device:", device_type, ":", i))); } - DeviceMgr* dev_mgr = new DeviceMgr(std::move(devices)); + DeviceMgr* dev_mgr = new StaticDeviceMgr(std::move(devices)); device_mgrs_.push_back(dev_mgr); std::vector* dv = &dev_by_task_[worker_name]; for (auto* d : dev_mgr->ListDevices()) { diff --git a/tensorflow/core/distributed_runtime/collective_rma_distributed_test.cc b/tensorflow/core/distributed_runtime/collective_rma_distributed_test.cc index 1462c38645b..fd6517ed41f 100644 --- a/tensorflow/core/distributed_runtime/collective_rma_distributed_test.cc +++ b/tensorflow/core/distributed_runtime/collective_rma_distributed_test.cc @@ -222,7 +222,7 @@ class CollRMADistTest : public ::testing::Test { device_type, strings::StrCat(worker_name, "/device:", device_type, ":", i))); } - DeviceMgr* dev_mgr = new DeviceMgr(std::move(devices)); + DeviceMgr* dev_mgr = new StaticDeviceMgr(std::move(devices)); device_mgrs_.push_back(dev_mgr); std::vector* dv = &dev_by_task_[worker_name]; dv->clear(); diff --git a/tensorflow/core/distributed_runtime/device_resolver_distributed_test.cc b/tensorflow/core/distributed_runtime/device_resolver_distributed_test.cc index 1a0d1f51591..3d7523f945c 100644 --- a/tensorflow/core/distributed_runtime/device_resolver_distributed_test.cc +++ b/tensorflow/core/distributed_runtime/device_resolver_distributed_test.cc @@ -163,7 +163,7 @@ class DeviceResDistTest : public ::testing::Test { strings::StrCat(worker_name, "/device:", device_type, ":", i), i, device_incarnation_base + i)); } - DeviceMgr* dev_mgr = new DeviceMgr(std::move(devices)); + DeviceMgr* dev_mgr = new StaticDeviceMgr(std::move(devices)); TestableDeviceResolverDistributed* dev_res = new TestableDeviceResolverDistributed(dev_mgr, &wc_, worker_name); resolvers_[worker_name] = dev_res; diff --git a/tensorflow/core/distributed_runtime/eager/eager_service_impl_test.cc b/tensorflow/core/distributed_runtime/eager/eager_service_impl_test.cc index ad6da5a97ff..d278f56b99c 100644 --- a/tensorflow/core/distributed_runtime/eager/eager_service_impl_test.cc +++ b/tensorflow/core/distributed_runtime/eager/eager_service_impl_test.cc @@ -85,7 +85,7 @@ class EagerServiceImplTest : public ::testing::Test { worker_env_.rendezvous_mgr = &rendezvous_mgr_; worker_env_.session_mgr = session_mgr_.get(); - device_mgr_ = absl::make_unique(DeviceFactory::NewDevice( + device_mgr_ = absl::make_unique(DeviceFactory::NewDevice( "CPU", {}, "/job:localhost/replica:0/task:0/device:CPU:0")); worker_env_.local_devices = device_mgr_->ListDevices(); worker_env_.device_mgr = device_mgr_.get(); diff --git a/tensorflow/core/distributed_runtime/eager/remote_mgr_test.cc b/tensorflow/core/distributed_runtime/eager/remote_mgr_test.cc index 772b36897bb..58f88a1dffd 100644 --- a/tensorflow/core/distributed_runtime/eager/remote_mgr_test.cc +++ b/tensorflow/core/distributed_runtime/eager/remote_mgr_test.cc @@ -48,7 +48,7 @@ class RemoteMgrTest : public ::testing::Test { devices.push_back( DeviceFactory::NewDevice("CPU", {}, "/job:worker/replica:0/task:0")); remote_device_ = devices.back().get(); - auto device_mgr = absl::make_unique(std::move(devices)); + auto device_mgr = absl::make_unique(std::move(devices)); context_id_ = random::New64(); tensorflow::Rendezvous* rendezvous = new tensorflow::IntraProcessRendezvous(device_mgr.get()); diff --git a/tensorflow/core/distributed_runtime/rpc/grpc_server_lib.cc b/tensorflow/core/distributed_runtime/rpc/grpc_server_lib.cc index c8eeaa9ddef..ce76320cce5 100644 --- a/tensorflow/core/distributed_runtime/rpc/grpc_server_lib.cc +++ b/tensorflow/core/distributed_runtime/rpc/grpc_server_lib.cc @@ -163,7 +163,7 @@ Status GrpcServer::Init(const GrpcServerOptions& opts) { std::vector> devices; TF_RETURN_IF_ERROR( DeviceFactory::AddDevices(sess_opts, name_prefix, &devices)); - worker_env_.device_mgr = new DeviceMgr(std::move(devices)); + worker_env_.device_mgr = new StaticDeviceMgr(std::move(devices)); master_env_.local_devices = worker_env_.device_mgr->ListDevices(); worker_env_.local_devices = worker_env_.device_mgr->ListDevices(); worker_env_.rendezvous_mgr = opts.rendezvous_mgr_func == nullptr diff --git a/tensorflow/core/distributed_runtime/rpc_collective_executor_mgr_test.cc b/tensorflow/core/distributed_runtime/rpc_collective_executor_mgr_test.cc index 1c87fe9d928..d49b040d59f 100644 --- a/tensorflow/core/distributed_runtime/rpc_collective_executor_mgr_test.cc +++ b/tensorflow/core/distributed_runtime/rpc_collective_executor_mgr_test.cc @@ -44,7 +44,7 @@ class RpcCollectiveExecutorMgrTest : public ::testing::Test { device_count->insert({"CPU", NUM_DEVS}); std::vector> devices; TF_CHECK_OK(DeviceFactory::AddDevices(options, task_name, &devices)); - device_mgr_.reset(new DeviceMgr(std::move(devices))); + device_mgr_ = absl::make_unique(std::move(devices)); std::unique_ptr dr(new DeviceResolverDistributed( device_mgr_.get(), worker_cache, task_name)); std::unique_ptr cpr( diff --git a/tensorflow/core/distributed_runtime/session_mgr.cc b/tensorflow/core/distributed_runtime/session_mgr.cc index 0319e61aec0..7fe3c685a93 100644 --- a/tensorflow/core/distributed_runtime/session_mgr.cc +++ b/tensorflow/core/distributed_runtime/session_mgr.cc @@ -101,7 +101,7 @@ Status SessionMgr::CreateSession( renamed_devices.push_back(RenamedDevice::NewRenamedDevice( worker_name, d, false, isolate_session_state)); } - auto device_mgr = MakeUnique(std::move(renamed_devices)); + auto device_mgr = MakeUnique(std::move(renamed_devices)); LookupLocalDevice cb = [&device_mgr](StringPiece name, Device** device) { return device_mgr->LookupDevice(name, device); }; @@ -109,7 +109,7 @@ Status SessionMgr::CreateSession( &cluster_devices); std::unique_ptr remote_devices; if (!cluster_device_attributes.empty()) - remote_devices = MakeUnique(std::move(cluster_devices)); + remote_devices = MakeUnique(std::move(cluster_devices)); auto graph_mgr = MakeUnique(worker_env_, device_mgr.get()); worker_session.reset( @@ -122,7 +122,7 @@ Status SessionMgr::CreateSession( &cluster_devices); std::unique_ptr remote_devices; if (!cluster_device_attributes.empty()) - remote_devices = MakeUnique(std::move(cluster_devices)); + remote_devices = MakeUnique(std::move(cluster_devices)); // Borrow the WorkerEnv's DeviceMgr for the WorkerSession, so // that resources using it can use its devices after the // WorkerSession has been deleted. diff --git a/tensorflow/core/distributed_runtime/session_mgr_test.cc b/tensorflow/core/distributed_runtime/session_mgr_test.cc index a66acffb3c7..30a102b310f 100644 --- a/tensorflow/core/distributed_runtime/session_mgr_test.cc +++ b/tensorflow/core/distributed_runtime/session_mgr_test.cc @@ -46,7 +46,7 @@ class SessionMgrTest : public ::testing::Test { SessionMgrTest() : mgr_(&env_, "/job:mnist/replica:0/task:0", std::unique_ptr(), factory_) { - device_mgr_ = absl::make_unique( + device_mgr_ = absl::make_unique( FakeDevice::MakeCPU("/job:mnist/replica:0/task:0/device:fakecpu:0")); env_.local_devices = device_mgr_->ListDevices(); env_.device_mgr = device_mgr_.get(); diff --git a/tensorflow/core/grappler/grappler_item_builder.cc b/tensorflow/core/grappler/grappler_item_builder.cc index 6d49b2f29d0..49958bd15b7 100644 --- a/tensorflow/core/grappler/grappler_item_builder.cc +++ b/tensorflow/core/grappler/grappler_item_builder.cc @@ -239,7 +239,7 @@ Status RuntimeGraphOptimizer(const GraphDef& graph_def_arg, TF_RETURN_IF_ERROR(cpu_factory->CreateDevices( options, "/job:localhost/replica:0/task:0", &devices)); Device* cpu_device = devices[0].get(); - std::unique_ptr dvc_mgr(new DeviceMgr(std::move(devices))); + auto dvc_mgr = absl::make_unique(std::move(devices)); FunctionLibraryDefinition function_library(OpRegistry::Global(), graph_def.library()); Env* env = Env::Default(); diff --git a/tensorflow/core/kernels/collective_nccl_test.cc b/tensorflow/core/kernels/collective_nccl_test.cc index b77fe2b9547..8000f5386ae 100644 --- a/tensorflow/core/kernels/collective_nccl_test.cc +++ b/tensorflow/core/kernels/collective_nccl_test.cc @@ -117,7 +117,8 @@ class NcclTestBase : public ::testing::Test { device_names.push_back(device->name()); VLOG(2) << device->name(); } - if (!dev_mgr_) dev_mgr_.reset(new DeviceMgr(std::move(local_devices))); + if (!dev_mgr_) + dev_mgr_ = absl::make_unique(std::move(local_devices)); col_exec_ = new BaseCollectiveExecutor( &col_exec_mgr_, /*remote_access=*/nullptr, kStepId, dev_mgr_.get(), /*gpu_ring_order=*/nullptr); diff --git a/tensorflow/core/kernels/data/dataset_test_base.cc b/tensorflow/core/kernels/data/dataset_test_base.cc index aecdef33160..15b673e38b1 100644 --- a/tensorflow/core/kernels/data/dataset_test_base.cc +++ b/tensorflow/core/kernels/data/dataset_test_base.cc @@ -415,7 +415,7 @@ Status DatasetOpsTestBase::InitFunctionLibraryRuntime( std::vector> devices; TF_RETURN_IF_ERROR(DeviceFactory::AddDevices( options, "/job:localhost/replica:0/task:0", &devices)); - device_mgr_ = absl::make_unique(std::move(devices)); + device_mgr_ = absl::make_unique(std::move(devices)); resource_mgr_ = absl::make_unique("default_container"); FunctionDefLibrary proto; diff --git a/tensorflow/core/kernels/data/iterator_ops.cc b/tensorflow/core/kernels/data/iterator_ops.cc index 08d9d936537..053026c5c08 100644 --- a/tensorflow/core/kernels/data/iterator_ops.cc +++ b/tensorflow/core/kernels/data/iterator_ops.cc @@ -355,9 +355,10 @@ FunctionLibraryRuntime* IteratorHandleOp::CreatePrivateFLR( // in its resource manager. The existing device will outlive the // IteratorResource, because we are storing the IteratorResource // in that device's resource manager. - *device_mgr = absl::make_unique(RenamedDevice::NewRenamedDevice( - ctx->device()->name(), down_cast(ctx->device()), - false /* owns_underlying */, false /* isolate_session_state */)); + *device_mgr = + absl::make_unique(RenamedDevice::NewRenamedDevice( + ctx->device()->name(), down_cast(ctx->device()), + false /* owns_underlying */, false /* isolate_session_state */)); *flib_def = absl::make_unique( *ctx->function_library()->GetFunctionLibraryDefinition()); *pflr = absl::make_unique( diff --git a/tensorflow/core/kernels/ops_testutil.cc b/tensorflow/core/kernels/ops_testutil.cc index c6ba93b546d..59e695159f3 100644 --- a/tensorflow/core/kernels/ops_testutil.cc +++ b/tensorflow/core/kernels/ops_testutil.cc @@ -27,7 +27,7 @@ void OpsTestBase::SetDevice(const DeviceType& device_type, CHECK(device_) << "No device provided"; device_ = device.get(); - device_mgr_ = absl::make_unique(std::move(device)); + device_mgr_ = absl::make_unique(std::move(device)); pflr_ = absl::make_unique( device_mgr_.get(), Env::Default(), TF_GRAPH_DEF_VERSION, flib_def_.get(), OptimizerOptions()); diff --git a/tensorflow/core/kernels/ops_testutil.h b/tensorflow/core/kernels/ops_testutil.h index 6baf463eb63..b13c1127b70 100644 --- a/tensorflow/core/kernels/ops_testutil.h +++ b/tensorflow/core/kernels/ops_testutil.h @@ -78,7 +78,7 @@ class OpsTestBase : public ::testing::Test { CHECK(device) << "Could not create CPU device"; device_ = device.get(); - device_mgr_ = absl::make_unique(std::move(device)); + device_mgr_ = absl::make_unique(std::move(device)); allocator_ = device_->GetAllocator(AllocatorAttributes()); diff --git a/tensorflow/lite/delegates/flex/delegate_data.cc b/tensorflow/lite/delegates/flex/delegate_data.cc index 3a84c9cf60d..bed38bdffdd 100644 --- a/tensorflow/lite/delegates/flex/delegate_data.cc +++ b/tensorflow/lite/delegates/flex/delegate_data.cc @@ -39,7 +39,7 @@ tensorflow::Status DelegateData::Prepare( session_options, "/job:localhost/replica:0/task:0", &devices)); auto device_mgr = - absl::make_unique(std::move(devices)); + absl::make_unique(std::move(devices)); // Note that Rendezvous is ref-counted so it will be automatically deleted. tensorflow::Rendezvous* rendezvous = new tensorflow::IntraProcessRendezvous(device_mgr.get()); diff --git a/tensorflow/lite/toco/import_tensorflow.cc b/tensorflow/lite/toco/import_tensorflow.cc index 29c8d9629a9..f351c907fef 100644 --- a/tensorflow/lite/toco/import_tensorflow.cc +++ b/tensorflow/lite/toco/import_tensorflow.cc @@ -2234,7 +2234,7 @@ bool InlineAllFunctions(GraphDef* graphdef) { tensorflow::FunctionLibraryDefinition fld(tensorflow::OpRegistry::Global(), graphdef_copy.library()); - tensorflow::DeviceMgr device_mgr(std::move(devices)); + tensorflow::StaticDeviceMgr device_mgr(std::move(devices)); tensorflow::OptimizerOptions o_opts; tensorflow::ProcessFunctionLibraryRuntime pflr( &device_mgr, tensorflow::Env::Default(), TF_GRAPH_DEF_VERSION, &fld,