@@ -39,12 +39,14 @@ C10_DEFINE_SHARED_REGISTRY_WITHOUT_WARNING(
3939 GlooDeviceRegistry,
4040 ::gloo::transport::Device,
4141 const std::string& /* interface */ ,
42- const std::string& /* hostname */ )
42+ const std::string& /* hostname */ ,
43+ bool /* lazyInit */ )
4344
4445#if GLOO_HAVE_TRANSPORT_TCP
4546static std::shared_ptr<::gloo::transport::Device> makeTCPDevice (
4647 const std::string& interfaceName,
47- const std::string& hostname) {
48+ const std::string& hostname,
49+ bool lazyInit) {
4850 TORCH_CHECK (
4951 !interfaceName.empty () || !hostname.empty (),
5052 " GlooDeviceFactory::makeTCPDevice(): interface or hostname "
@@ -56,7 +58,11 @@ static std::shared_ptr<::gloo::transport::Device> makeTCPDevice(
5658 } else {
5759 attr.hostname = hostname;
5860 }
59- return ::gloo::transport::tcp::CreateDevice (attr);
61+ if (lazyInit) {
62+ return ::gloo::transport::tcp::CreateLazyDevice (attr);
63+ } else {
64+ return ::gloo::transport::tcp::CreateDevice (attr);
65+ }
6066}
6167
6268// Registry priority is per key identifier. We register TCP to `LINUX` for
@@ -69,12 +75,15 @@ C10_REGISTER_CREATOR(GlooDeviceRegistry, TCP, makeTCPDevice)
6975#if GLOO_HAVE_TRANSPORT_TCP_TLS
7076static std::shared_ptr<::gloo::transport::Device> makeTCPTLSDevice (
7177 const std::string& interface,
72- const std::string& hostname) {
78+ const std::string& hostname,
79+ bool lazyInit) {
7380 TORCH_CHECK (
7481 !interface.empty () || !hostname.empty (),
7582 " GlooDeviceFactory::makeTCPTLSDevice(): interface or hostname "
7683 " can't be empty" );
7784
85+ TORCH_CHECK (!lazyInit, " TCP_TLS transport does not support lazy init" );
86+
7887 ::gloo::transport::tcp::attr attr;
7988 if (!interface.empty ()) {
8089 attr.iface = interface;
@@ -105,12 +114,15 @@ C10_REGISTER_CREATOR(GlooDeviceRegistry, TCP_TLS, makeTCPTLSDevice)
105114#if GLOO_HAVE_TRANSPORT_UV
106115static std::shared_ptr<::gloo::transport::Device> makeUVDevice (
107116 const std::string& interfaceName,
108- const std::string& hostname) {
117+ const std::string& hostname,
118+ bool lazyInit) {
109119 TORCH_CHECK (
110120 !interfaceName.empty () || !hostname.empty (),
111121 " GlooDeviceFactory::makeUVDevice(): interface or hostname "
112122 " can't be empty" );
113123
124+ TORCH_CHECK (!lazyInit, " UV transport does not support lazy init" );
125+
114126 ::gloo::transport::uv::attr attr;
115127 if (!interfaceName.empty ()) {
116128 attr.iface = interfaceName;
@@ -131,41 +143,45 @@ C10_REGISTER_CREATOR(GlooDeviceRegistry, UV, makeUVDevice)
131143namespace {
132144std::shared_ptr<::gloo::transport::Device> makeGlooDevice (
133145 const std::string& interfaceName,
134- const std::string& hostName) {
146+ const std::string& hostName,
147+ bool lazyInit) {
135148 static auto transportName = c10::utils::get_env (" GLOO_DEVICE_TRANSPORT" );
136149 if (transportName.has_value ()) {
137150 return GlooDeviceRegistry ()->Create (
138- transportName.value ().c_str (), interfaceName, hostName);
151+ transportName.value ().c_str (), interfaceName, hostName, lazyInit );
139152 }
140153
141154#ifdef __linux__
142- return GlooDeviceRegistry ()->Create (" LINUX" , interfaceName, hostName);
155+ return GlooDeviceRegistry ()->Create (
156+ " LINUX" , interfaceName, hostName, lazyInit);
143157#endif
144158
145159#ifdef __APPLE__
146- return GlooDeviceRegistry ()->Create (" APPLE" , interfaceName, hostName);
160+ return GlooDeviceRegistry ()->Create (
161+ " APPLE" , interfaceName, hostName, lazyInit);
147162#endif
148163
149164#ifdef _WIN32
150- return GlooDeviceRegistry ()->Create (" WIN32" , interfaceName, hostName);
165+ return GlooDeviceRegistry ()->Create (
166+ " WIN32" , interfaceName, hostName, lazyInit);
151167#endif
152168
153169 return nullptr ;
154170}
155171} // anonymous namespace
156172
157173std::shared_ptr<::gloo::transport::Device> GlooDeviceFactory::
158- makeDeviceForInterface (const std::string& interfaceName) {
159- auto device = makeGlooDevice (interfaceName, " " );
174+ makeDeviceForInterface (const std::string& interfaceName, bool lazyInit ) {
175+ auto device = makeGlooDevice (interfaceName, " " , lazyInit );
160176 if (!device) {
161177 TORCH_CHECK (false , " makeDeviceForInterface(): unsupported gloo device" );
162178 }
163179 return device;
164180}
165181
166182std::shared_ptr<::gloo::transport::Device> GlooDeviceFactory::
167- makeDeviceForHostname (const std::string& hostname) {
168- auto device = makeGlooDevice (" " , hostname);
183+ makeDeviceForHostname (const std::string& hostname, bool lazyInit ) {
184+ auto device = makeGlooDevice (" " , hostname, lazyInit );
169185 if (!device) {
170186 TORCH_CHECK (false , " makeDeviceForHostname(): unsupported gloo device" );
171187 }
0 commit comments