10#include "utility/example_shared.h"
12#include <nv/index/iindex.h>
19#include "utility/app_rendering_context.h"
21#include <nv/index/app/forwarding_logger.h>
22#include <nv/index/app/string_dict.h>
23#include <nv/index/app/time_functions.h>
24#include <nv/index/app/index_connect_.h>
30class Cluster_rendering_remotehost_index_connect:
31 public nv::index::app::Index_connect
34 Cluster_rendering_remotehost_index_connect()
41 virtual ~Cluster_rendering_remotehost_index_connect()
49 virtual bool initialize_networking(
50 mi::neuraylib::INetwork_configuration* network_configuration,
51 nv::index::app::String_dict& options) CPP11_OVERRIDE
56 const bool is_unittest = nv::index::app::get_bool(options.get(
"unittest"));
59 info_cout(
"NETWORK: disabled networking mode.", options);
60 network_configuration->set_mode(mi::neuraylib::INetwork_configuration:
:MODE_OFF);
63 return initialize_networking_as_default_udp(network_configuration, options);
67 virtual bool register_serializable_classes(
68 mi::neuraylib::IDice_configuration* configuration_interface,
69 nv::index::app::String_dict& options) CPP11_OVERRIDE
79 virtual bool initialize_debug_configuration(
80 mi::neuraylib::IDebug_configuration* debug_configuration,
81 nv::index::app::String_dict& options) CPP11_OVERRIDE
84 if (options.is_defined(
"dice::idebug_config::retention"))
86 bool conv_stat =
false;
87 const std::string retension = options.get(
"dice::idebug_config::retention");
88 const mi::Sint32 debug_retention = nv::index::app::get_sint32(retension, &conv_stat);
91 ERROR_LOG <<
"initialize_index_debug_configuration: failed integer conversion of dice::idebug_config::retention: "
96 if(debug_retention > 0)
98 std::stringstream sstr;
99 sstr <<
"retention=" << debug_retention;
100 debug_configuration->set_option(sstr.str().c_str());
101 INFO_LOG <<
"Set IDebug_configuration: " << sstr.str();
109 virtual bool initialize_general_configuration(
110 mi::neuraylib::IGeneral_configuration* general_configuration,
111 nv::index::app::String_dict& options) CPP11_OVERRIDE
114 general_configuration->set_host_property(
"sub_cluster_id",
"0");
126bool remote_rendering_loop(
127 Cluster_rendering_remotehost_index_connect& index_connect,
128 App_rendering_context& arc,
129 nv::index::app::String_dict& sdict)
131 mi::base::Handle<nv::index::ICluster_configuration> rendering_properties_query(
132 index_connect.get_index_interface()->get_api_component<nv::index::ICluster_configuration>());
133 check_success(rendering_properties_query.is_valid_interface());
135 mi::Uint32 number_of_hosts = rendering_properties_query->get_number_of_hosts();
137 std::stringstream sstr;
138 sstr <<
"**********************************************************************\n"
139 <<
"info: NVIDIA IndeX remote service running and waiting for connections,\n"
140 <<
"info: Cluster host id = " << rendering_properties_query->get_local_host_id() <<
"\n"
141 <<
"info: ****************************************************************";
142 INFO_LOG << sstr.str();
146 const bool is_unittest = nv::index::app::get_bool(sdict.get(
"unittest",
"false"));
147 const mi::Sint32 remote_max_iter_when_unittest = 8;
149 for(mi::Sint32 i = 0;
true; ++i)
151 const mi::Uint32 new_number_of_hosts = rendering_properties_query->get_number_of_hosts();
154 if (new_number_of_hosts < number_of_hosts)
156 std::stringstream sstr;
157 sstr <<
"Leaving the NVIDIA IndeX remote service loop because at least one other cluster host has left. "
158 <<
"Previously, the cluster was composed by "
159 << number_of_hosts <<
" hosts. Now, only "
160 << new_number_of_hosts <<
" cluster hosts are left.";
161 INFO_LOG << sstr.str();
167 if (is_unittest&& (i>= remote_max_iter_when_unittest))
169 INFO_LOG <<
"The unit test exits because the test has reached the maximum number of iterations.";
174 number_of_hosts = new_number_of_hosts;
175 nv::index::app::util::time::sleep(0.1f);
178 INFO_LOG <<
"Finished the NVIDIA IndeX remote service loop.";
189bool setup_remote_host(
190 Cluster_rendering_remotehost_index_connect& index_connect,
191 App_rendering_context& arc)
193 arc.m_database = index_connect.get_index_interface()->get_api_component<mi::neuraylib::IDatabase>();
196 arc.m_global_scope = arc.m_database->get_global_scope();
207void config_network_parameters(
208 Cluster_rendering_remotehost_index_connect& index_connect,
209 nv::index::app::String_dict& sdict)
211 if (sdict.get(
"dice::network::additional_unicast_sockets",
"0") !=
"0")
213 mi::base::Handle<mi::neuraylib::IDebug_configuration> debug_configuration(
214 index_connect.get_index_interface()->get_api_component<mi::neuraylib::IDebug_configuration>());
217 std::stringstream sstr;
218 sstr <<
"dice::network::additional_unicast_sockets="
219 << sdict.get(
"dice::network::additional_unicast_sockets",
"<undef>");
220 const std::string additional_unicast_sockets = sstr.str();
221 debug_configuration->set_option(additional_unicast_sockets.c_str());
229int main(
int argc,
char* argv[])
231 const std::string com_name(argv[0]);
232 nv::index::app::String_dict sdict;
233 sdict.insert(
"dice::verbose",
"3");
234 sdict.insert(
"dice::network::mode",
"UDP");
235 sdict.insert(
"dice::network::multicast_address",
"239.43.1.1");
236 sdict.insert(
"dice::network::additional_unicast_sockets",
"0");
237 sdict.insert(
"unittest",
"0");
238 sdict.insert(
"dice::idebug_config::retention",
"0");
239 sdict.insert(
"is_dump_comparison_image_when_failed",
"1");
240 sdict.insert(
"is_call_from_test",
"0");
242 Cluster_rendering_remotehost_index_connect index_connect;
243 index_connect.process_command_line_arguments(argc, argv, sdict);
245 if (nv::index::app::get_bool(sdict.get(
"unittest",
"false")))
248 mi::Uint32 cur_time =
static_cast<mi::Uint32
>(nv::index::app::util::time::get_time() * 10000);
250 mi::Sint64 r1 = (rand() % 254) + 1;
251 mi::Sint64 r2 = (rand() % 254) + 1;
252 std::stringstream sstr;
253 sstr <<
"239.43." << r1 <<
"." << r2;
254 std::string mc_addr = sstr.str();
256 std::stringstream sstr2;
257 sstr2 <<
"Cur_time: " << cur_time <<
", Using multicast address: " << mc_addr;
258 info_cout(sstr2.str(), sdict);
260 sdict.insert(
"dice::network::multicast_address", mc_addr);
262 if (nv::index::app::get_bool(sdict.get(
"is_call_from_test",
"false")))
264 sdict.insert(
"is_dump_comparison_image_when_failed",
"0");
266 sdict.get(
"dice::verbose",
"2");
268 info_cout(
"running " + com_name, sdict);
269 info_cout(
"dice::verbose = " + sdict.get(
"dice::verbose"), sdict);
272 if (sdict.is_defined(
"h") || sdict.is_defined(
"help"))
275 <<
"info: Usage: " << com_name <<
" [option]\n"
277 <<
" printout this message\n"
279 <<
" [-dice::verbose severity_level]\n"
280 <<
" verbose severity level (3 is info.).\n"
281 <<
" (default: " + sdict.get(
"dice::verbose",
"<undef>") +
")\n"
283 <<
" [-dice::network::multicast_address address]\n"
284 <<
" set multicast address.\n"
285 <<
" (default: " << sdict.get(
"dice::network::multicast_address",
"<undef>") <<
")\n"
287 <<
" [-dice::network::additional_unicast_sockets int]\n"
288 <<
" set number of unicast sockets for remote host.\n"
289 <<
" (default: " << sdict.get(
"dice::network::additional_unicast_sockets",
"<undef>") <<
").\n"
291 <<
" [-unittest bool]\n"
292 <<
" when test true, unit test mode.\n"
293 <<
" (default: " << sdict.get(
"unittest",
"<undef>") <<
")"
295 <<
" [-dice::idebug_config::retention int]\n"
296 <<
" when set, set this idebug configuration option. not set when 0.\n"
297 <<
" (default: " << sdict.get(
"dice::idebug_config::retention",
"<undef>") <<
")"
303 sdict.insert(
"index::config::set_monitor_performance_values",
"true");
304 sdict.insert(
"index::service",
"rendering_and_compositing");
305 sdict.insert(
"index::cuda_debug_checks",
"false");
308 sdict.insert(
"index::app::components::application_layer::component_name_list",
309 "canvas_infrastructure data_analysis_and_processing image io");
311 sdict.insert(
"index::app::plugins::base_importer::enabled",
"true");
315 config_network_parameters(index_connect, sdict);
318 info_cout(std::string(
"start IndeX via index_connect"), sdict);
319 index_connect.initialize(sdict);
323 App_rendering_context arc;
327 remote_rendering_loop(index_connect, arc, sdict);
329 printf(
"Shutting down the NVIDIA IndeX library.\n");
333 printf(
"Terminating the NVIDIA IndeX remote service.\n");
int main(int argc, char *argv[])
#define check_success(expr)