From b097a109151bf4ef0415d1bae1811de52326119b Mon Sep 17 00:00:00 2001 From: oandreeva-nv Date: Mon, 21 Aug 2023 16:30:18 -0700 Subject: [PATCH] Refactoring and clean up --- src/command_line_parser.cc | 946 ++++++++++++++++++------------------- src/command_line_parser.h | 13 +- 2 files changed, 465 insertions(+), 494 deletions(-) diff --git a/src/command_line_parser.cc b/src/command_line_parser.cc index ad18c19ba7..554863d113 100644 --- a/src/command_line_parser.cc +++ b/src/command_line_parser.cc @@ -70,7 +70,9 @@ getopt_long( if (key == curr_longopt->name_) { if (curr_longopt->has_arg_ == required_argument) { if (found == std::string::npos) { - *longind = optind - 1; + if (longind != NULL) { + *longind = optind - 1; + } optind++; if (optind >= argc) { std::cerr << argv[0] << ": option '" << argv_str @@ -82,7 +84,9 @@ getopt_long( optarg = (argv[optind] + found + 1); } } - *longind = optind - 1; + if (longind != NULL) { + *longind = optind - 1; + } optind++; return curr_longopt->val_; } @@ -150,24 +154,18 @@ StringTo(const std::string& arg) // (i.e. parse "1.4" to 'int' will return 1 but we want to report error). template T -ParseOption(const std::string& arg, const std::string& opt_name = "") +ParseOption(const std::string& arg) { try { return StringTo(arg); } catch (const std::invalid_argument& ia) { std::stringstream ss; - if (!opt_name.empty()) { - ss << "Option: \"" << opt_name << "\" : "; - } ss << "Invalid option value. Got " << arg << std::endl; throw ParseException(ss.str()); } catch (const std::out_of_range& oor) { std::stringstream ss; - if (!opt_name.empty()) { - ss << "Option: \"" << opt_name << "\" : "; - } ss << "Provided option value is out of bound. Got " << arg << std::endl; throw ParseException(ss.str()); } @@ -175,7 +173,7 @@ ParseOption(const std::string& arg, const std::string& opt_name = "") template <> bool -ParseOption(const std::string& arg, const std::string& opt_name) +ParseOption(const std::string& arg) { // 'arg' need to comply with template declaration std::string larg = arg; @@ -197,7 +195,7 @@ ParseOption(const std::string& arg, const std::string& opt_name) // be defined but not used otherwise. #ifdef TRITON_ENABLE_LOGGING int -ParseIntBoolOption(std::string arg, const std::string& opt_name = "") +ParseIntBoolOption(std::string arg) { std::transform(arg.begin(), arg.end(), arg.begin(), [](unsigned char c) { return std::tolower(c); @@ -210,7 +208,7 @@ ParseIntBoolOption(std::string arg, const std::string& opt_name = "") return 0; } - return ParseOption(arg, opt_name); + return ParseOption(arg); } #endif // TRITON_ENABLE_LOGGING @@ -234,9 +232,7 @@ PairsToJsonStr(std::vector> settings) template std::pair -ParsePairOption( - const std::string& arg, const std::string& delim_str, - const std::string& opt_name = "") +ParsePairOption(const std::string& arg, const std::string& delim_str) { int delim = arg.find(delim_str); @@ -255,9 +251,7 @@ ParsePairOption( // Specific conversion from key-value string to actual key-value type, // should be extracted out of this function if we need to parse // more pair option of different types. - return { - ParseOption(first_string, opt_name), - ParseOption(second_string, opt_name)}; + return {ParseOption(first_string), ParseOption(second_string)}; } #ifdef TRITON_ENABLE_GRPC @@ -1161,19 +1155,6 @@ TritonServerParameters::BuildTritonServerOptions() return managed_ptr; } -std::string -TritonParser::GetOptionName(const struct option* long_option) -{ - if (long_option != nullptr) { -#ifdef _WIN32 - return long_option->name_; -#else - return long_option->name; -#endif - } - return ""; -} - std::pair> TritonParser::Parse(int argc, char** argv) { @@ -1235,442 +1216,427 @@ TritonParser::Parse(int argc, char** argv) int flag; while ((flag = getopt_long( argc, argv, "", &long_options[0], &option_index)) != -1) { - switch (flag) { - case OPTION_HELP: - // [FIXME] how help is printed? - case '?': - // [FIXME] fall through when seeing this, currently consumes all options - // [FIXME] disable stderr output of `getopt_long` - throw ParseException(); + try { + switch (flag) { + case OPTION_HELP: + // [FIXME] how help is printed? + case '?': + // [FIXME] fall through when seeing this, currently consumes all + // options [FIXME] disable stderr output of `getopt_long` + throw ParseException(); #ifdef TRITON_ENABLE_LOGGING - case OPTION_LOG_VERBOSE: - lparams.log_verbose_ = ParseIntBoolOption( - optarg, GetOptionName(&long_options[option_index])); - break; - case OPTION_LOG_INFO: - lparams.log_info_ = ParseOption(optarg); - break; - case OPTION_LOG_WARNING: - lparams.log_warn_ = ParseOption(optarg); - break; - case OPTION_LOG_ERROR: - lparams.log_error_ = ParseOption(optarg); - break; - case OPTION_LOG_FORMAT: { - std::string format_str(optarg); - if (format_str == "default") { - lparams.log_format_ = triton::common::Logger::Format::kDEFAULT; - } else if (format_str == "ISO8601") { - lparams.log_format_ = triton::common::Logger::Format::kISO8601; - } else { - throw ParseException("invalid argument for --log-format"); + case OPTION_LOG_VERBOSE: + lparams.log_verbose_ = ParseIntBoolOption(optarg); + break; + case OPTION_LOG_INFO: + lparams.log_info_ = ParseOption(optarg); + break; + case OPTION_LOG_WARNING: + lparams.log_warn_ = ParseOption(optarg); + break; + case OPTION_LOG_ERROR: + lparams.log_error_ = ParseOption(optarg); + break; + case OPTION_LOG_FORMAT: { + std::string format_str(optarg); + if (format_str == "default") { + lparams.log_format_ = triton::common::Logger::Format::kDEFAULT; + } else if (format_str == "ISO8601") { + lparams.log_format_ = triton::common::Logger::Format::kISO8601; + } else { + throw ParseException("invalid argument for --log-format"); + } + break; } - break; - } - case OPTION_LOG_FILE: - lparams.log_file_ = optarg; - break; + case OPTION_LOG_FILE: + lparams.log_file_ = optarg; + break; #endif // TRITON_ENABLE_LOGGING - case OPTION_ID: - lparams.server_id_ = optarg; - break; - case OPTION_MODEL_REPOSITORY: - lparams.model_repository_paths_.insert(optarg); - break; - case OPTION_EXIT_ON_ERROR: - lparams.exit_on_error_ = ParseOption(optarg); - break; - case OPTION_DISABLE_AUTO_COMPLETE_CONFIG: - disable_auto_complete_config = true; - break; - case OPTION_STRICT_MODEL_CONFIG: - std::cerr << "Warning: '--strict-model-config' has been deprecated! " - "Please use '--disable-auto-complete-config' instead." - << std::endl; - strict_model_config_present = true; - lparams.strict_model_config_ = ParseOption(optarg); - break; - case OPTION_STRICT_READINESS: - lparams.strict_readiness_ = ParseOption(optarg); - break; + case OPTION_ID: + lparams.server_id_ = optarg; + break; + case OPTION_MODEL_REPOSITORY: + lparams.model_repository_paths_.insert(optarg); + break; + case OPTION_EXIT_ON_ERROR: + lparams.exit_on_error_ = ParseOption(optarg); + break; + case OPTION_DISABLE_AUTO_COMPLETE_CONFIG: + disable_auto_complete_config = true; + break; + case OPTION_STRICT_MODEL_CONFIG: + std::cerr << "Warning: '--strict-model-config' has been deprecated! " + "Please use '--disable-auto-complete-config' instead." + << std::endl; + strict_model_config_present = true; + lparams.strict_model_config_ = ParseOption(optarg); + break; + case OPTION_STRICT_READINESS: + lparams.strict_readiness_ = ParseOption(optarg); + break; #ifdef TRITON_ENABLE_HTTP - case OPTION_ALLOW_HTTP: - lparams.allow_http_ = ParseOption(optarg); - break; - case OPTION_HTTP_PORT: - lparams.http_port_ = ParseOption( - optarg, GetOptionName(&long_options[option_index])); - break; - case OPTION_REUSE_HTTP_PORT: - lparams.reuse_http_port_ = ParseOption( - optarg, GetOptionName(&long_options[option_index])); - break; - case OPTION_HTTP_ADDRESS: - lparams.http_address_ = optarg; - break; - case OPTION_HTTP_HEADER_FORWARD_PATTERN: - lparams.http_forward_header_pattern_ = optarg; - break; - break; - case OPTION_HTTP_THREAD_COUNT: - lparams.http_thread_cnt_ = ParseOption( - optarg, GetOptionName(&long_options[option_index])); - break; + case OPTION_ALLOW_HTTP: + lparams.allow_http_ = ParseOption(optarg); + break; + case OPTION_HTTP_PORT: + lparams.http_port_ = ParseOption(optarg); + break; + case OPTION_REUSE_HTTP_PORT: + lparams.reuse_http_port_ = ParseOption(optarg); + break; + case OPTION_HTTP_ADDRESS: + lparams.http_address_ = optarg; + break; + case OPTION_HTTP_HEADER_FORWARD_PATTERN: + lparams.http_forward_header_pattern_ = optarg; + break; + break; + case OPTION_HTTP_THREAD_COUNT: + lparams.http_thread_cnt_ = ParseOption(optarg); + break; #endif // TRITON_ENABLE_HTTP #ifdef TRITON_ENABLE_SAGEMAKER - case OPTION_ALLOW_SAGEMAKER: - lparams.allow_sagemaker_ = ParseOption(optarg); - break; - case OPTION_SAGEMAKER_PORT: - lparams.sagemaker_port_ = ParseOption( - optarg, GetOptionName(&long_options[option_index])); - break; - case OPTION_SAGEMAKER_SAFE_PORT_RANGE: - lparams.sagemaker_safe_range_set_ = true; - lparams.sagemaker_safe_range_ = ParsePairOption( - optarg, "-", GetOptionName(&long_options[option_index])); - break; - case OPTION_SAGEMAKER_THREAD_COUNT: - lparams.sagemaker_thread_cnt_ = ParseOption( - optarg, GetOptionName(&long_options[option_index])); - break; + case OPTION_ALLOW_SAGEMAKER: + lparams.allow_sagemaker_ = ParseOption(optarg); + break; + case OPTION_SAGEMAKER_PORT: + lparams.sagemaker_port_ = ParseOption(optarg); + break; + case OPTION_SAGEMAKER_SAFE_PORT_RANGE: + lparams.sagemaker_safe_range_set_ = true; + lparams.sagemaker_safe_range_ = + ParsePairOption(optarg, "-"); + break; + case OPTION_SAGEMAKER_THREAD_COUNT: + lparams.sagemaker_thread_cnt_ = ParseOption(optarg); + break; #endif // TRITON_ENABLE_SAGEMAKER #ifdef TRITON_ENABLE_VERTEX_AI - case OPTION_ALLOW_VERTEX_AI: - lparams.allow_vertex_ai_ = ParseOption(optarg); - break; - case OPTION_VERTEX_AI_PORT: - lparams.vertex_ai_port_ = ParseOption( - optarg, GetOptionName(&long_options[option_index])); - break; - case OPTION_VERTEX_AI_THREAD_COUNT: - lparams.vertex_ai_thread_cnt_ = ParseOption( - optarg, GetOptionName(&long_options[option_index])); - break; - case OPTION_VERTEX_AI_DEFAULT_MODEL: - lparams.vertex_ai_default_model_ = optarg; - break; + case OPTION_ALLOW_VERTEX_AI: + lparams.allow_vertex_ai_ = ParseOption(optarg); + break; + case OPTION_VERTEX_AI_PORT: + lparams.vertex_ai_port_ = ParseOption(optarg); + break; + case OPTION_VERTEX_AI_THREAD_COUNT: + lparams.vertex_ai_thread_cnt_ = ParseOption(optarg); + break; + case OPTION_VERTEX_AI_DEFAULT_MODEL: + lparams.vertex_ai_default_model_ = optarg; + break; #endif // TRITON_ENABLE_VERTEX_AI #ifdef TRITON_ENABLE_GRPC - case OPTION_ALLOW_GRPC: - lparams.allow_grpc_ = ParseOption(optarg); - break; - case OPTION_GRPC_PORT: - lgrpc_options.socket_.port_ = ParseOption( - optarg, GetOptionName(&long_options[option_index])); - break; - case OPTION_REUSE_GRPC_PORT: - lgrpc_options.socket_.reuse_port_ = ParseOption( - optarg, GetOptionName(&long_options[option_index])); - break; - case OPTION_GRPC_ADDRESS: - lgrpc_options.socket_.address_ = optarg; - break; - case OPTION_GRPC_INFER_ALLOCATION_POOL_SIZE: - lgrpc_options.infer_allocation_pool_size_ = ParseOption( - optarg, GetOptionName(&long_options[option_index])); - break; - case OPTION_GRPC_USE_SSL: - lgrpc_options.ssl_.use_ssl_ = ParseOption(optarg); - break; - case OPTION_GRPC_USE_SSL_MUTUAL: - lgrpc_options.ssl_.use_mutual_auth_ = ParseOption(optarg); - lgrpc_options.ssl_.use_ssl_ = true; - break; - case OPTION_GRPC_SERVER_CERT: - lgrpc_options.ssl_.server_cert_ = optarg; - break; - case OPTION_GRPC_SERVER_KEY: - lgrpc_options.ssl_.server_key_ = optarg; - break; - case OPTION_GRPC_ROOT_CERT: - lgrpc_options.ssl_.root_cert_ = optarg; - break; - case OPTION_GRPC_RESPONSE_COMPRESSION_LEVEL: { - std::string mode_str(optarg); - std::transform( - mode_str.begin(), mode_str.end(), mode_str.begin(), ::tolower); - if (mode_str == "none") { - lgrpc_options.infer_compression_level_ = GRPC_COMPRESS_LEVEL_NONE; - } else if (mode_str == "low") { - lgrpc_options.infer_compression_level_ = GRPC_COMPRESS_LEVEL_LOW; - } else if (mode_str == "medium") { - lgrpc_options.infer_compression_level_ = GRPC_COMPRESS_LEVEL_MED; - } else if (mode_str == "high") { - lgrpc_options.infer_compression_level_ = GRPC_COMPRESS_LEVEL_HIGH; - } else { - throw ParseException( - "invalid argument for --grpc_infer_response_compression_level"); + case OPTION_ALLOW_GRPC: + lparams.allow_grpc_ = ParseOption(optarg); + break; + case OPTION_GRPC_PORT: + lgrpc_options.socket_.port_ = ParseOption(optarg); + break; + case OPTION_REUSE_GRPC_PORT: + lgrpc_options.socket_.reuse_port_ = ParseOption(optarg); + break; + case OPTION_GRPC_ADDRESS: + lgrpc_options.socket_.address_ = optarg; + break; + case OPTION_GRPC_INFER_ALLOCATION_POOL_SIZE: + lgrpc_options.infer_allocation_pool_size_ = ParseOption(optarg); + break; + case OPTION_GRPC_USE_SSL: + lgrpc_options.ssl_.use_ssl_ = ParseOption(optarg); + break; + case OPTION_GRPC_USE_SSL_MUTUAL: + lgrpc_options.ssl_.use_mutual_auth_ = ParseOption(optarg); + lgrpc_options.ssl_.use_ssl_ = true; + break; + case OPTION_GRPC_SERVER_CERT: + lgrpc_options.ssl_.server_cert_ = optarg; + break; + case OPTION_GRPC_SERVER_KEY: + lgrpc_options.ssl_.server_key_ = optarg; + break; + case OPTION_GRPC_ROOT_CERT: + lgrpc_options.ssl_.root_cert_ = optarg; + break; + case OPTION_GRPC_RESPONSE_COMPRESSION_LEVEL: { + std::string mode_str(optarg); + std::transform( + mode_str.begin(), mode_str.end(), mode_str.begin(), ::tolower); + if (mode_str == "none") { + lgrpc_options.infer_compression_level_ = GRPC_COMPRESS_LEVEL_NONE; + } else if (mode_str == "low") { + lgrpc_options.infer_compression_level_ = GRPC_COMPRESS_LEVEL_LOW; + } else if (mode_str == "medium") { + lgrpc_options.infer_compression_level_ = GRPC_COMPRESS_LEVEL_MED; + } else if (mode_str == "high") { + lgrpc_options.infer_compression_level_ = GRPC_COMPRESS_LEVEL_HIGH; + } else { + throw ParseException( + "invalid argument for --grpc_infer_response_compression_level"); + } + break; } - break; - } - case OPTION_GRPC_ARG_KEEPALIVE_TIME_MS: - lgrpc_options.keep_alive_.keepalive_time_ms_ = ParseOption( - optarg, GetOptionName(&long_options[option_index])); - break; - case OPTION_GRPC_ARG_KEEPALIVE_TIMEOUT_MS: - lgrpc_options.keep_alive_.keepalive_timeout_ms_ = ParseOption( - optarg, GetOptionName(&long_options[option_index])); - break; - case OPTION_GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS: - lgrpc_options.keep_alive_.keepalive_permit_without_calls_ = - ParseOption(optarg); - break; - case OPTION_GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA: - lgrpc_options.keep_alive_.http2_max_pings_without_data_ = - ParseOption( - optarg, GetOptionName(&long_options[option_index])); - break; - case OPTION_GRPC_ARG_HTTP2_MIN_RECV_PING_INTERVAL_WITHOUT_DATA_MS: - lgrpc_options.keep_alive_ - .http2_min_recv_ping_interval_without_data_ms_ = ParseOption( - optarg, GetOptionName(&long_options[option_index])); - break; - case OPTION_GRPC_ARG_HTTP2_MAX_PING_STRIKES: - lgrpc_options.keep_alive_.http2_max_ping_strikes_ = ParseOption( - optarg, GetOptionName(&long_options[option_index])); - break; - case OPTION_GRPC_RESTRICTED_PROTOCOL: { - const auto& parsed_tuple = ParseGrpcRestrictedProtocolOption(optarg); - const auto& protocols = SplitOptions(std::get<0>(parsed_tuple), ","); - const auto& key = std::get<1>(parsed_tuple); - const auto& value = std::get<2>(parsed_tuple); - grpc::ProtocolGroup pg; - for (const auto& p : protocols) { - pg.protocols_.emplace(p); + case OPTION_GRPC_ARG_KEEPALIVE_TIME_MS: + lgrpc_options.keep_alive_.keepalive_time_ms_ = + ParseOption(optarg); + break; + case OPTION_GRPC_ARG_KEEPALIVE_TIMEOUT_MS: + lgrpc_options.keep_alive_.keepalive_timeout_ms_ = + ParseOption(optarg); + break; + case OPTION_GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS: + lgrpc_options.keep_alive_.keepalive_permit_without_calls_ = + ParseOption(optarg); + break; + case OPTION_GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA: + lgrpc_options.keep_alive_.http2_max_pings_without_data_ = + ParseOption(optarg); + break; + case OPTION_GRPC_ARG_HTTP2_MIN_RECV_PING_INTERVAL_WITHOUT_DATA_MS: + lgrpc_options.keep_alive_ + .http2_min_recv_ping_interval_without_data_ms_ = + ParseOption(optarg); + break; + case OPTION_GRPC_ARG_HTTP2_MAX_PING_STRIKES: + lgrpc_options.keep_alive_.http2_max_ping_strikes_ = + ParseOption(optarg); + break; + case OPTION_GRPC_RESTRICTED_PROTOCOL: { + const auto& parsed_tuple = ParseGrpcRestrictedProtocolOption(optarg); + const auto& protocols = SplitOptions(std::get<0>(parsed_tuple), ","); + const auto& key = std::get<1>(parsed_tuple); + const auto& value = std::get<2>(parsed_tuple); + grpc::ProtocolGroup pg; + for (const auto& p : protocols) { + pg.protocols_.emplace(p); + } + pg.restricted_key_ = std::make_pair(key, value); + lgrpc_options.protocol_groups_.emplace_back(pg); + break; } - pg.restricted_key_ = std::make_pair(key, value); - lgrpc_options.protocol_groups_.emplace_back(pg); - break; - } - case OPTION_GRPC_HEADER_FORWARD_PATTERN: - lgrpc_options.forward_header_pattern_ = optarg; - break; + case OPTION_GRPC_HEADER_FORWARD_PATTERN: + lgrpc_options.forward_header_pattern_ = optarg; + break; #endif // TRITON_ENABLE_GRPC #ifdef TRITON_ENABLE_METRICS - case OPTION_ALLOW_METRICS: - lparams.allow_metrics_ = ParseOption(optarg); - break; - case OPTION_ALLOW_GPU_METRICS: - lparams.allow_gpu_metrics_ = ParseOption(optarg); - break; - case OPTION_ALLOW_CPU_METRICS: - lparams.allow_cpu_metrics_ = ParseOption(optarg); - break; - case OPTION_METRICS_ADDRESS: - lparams.metrics_address_ = optarg; - break; - case OPTION_METRICS_PORT: - lparams.metrics_port_ = ParseOption( - optarg, GetOptionName(&long_options[option_index])); - break; - case OPTION_METRICS_INTERVAL_MS: - lparams.metrics_interval_ms_ = ParseOption( - optarg, GetOptionName(&long_options[option_index])); - break; - case OPTION_METRICS_CONFIG: - lparams.metrics_config_settings_.push_back( - ParseMetricsConfigOption(optarg)); - break; + case OPTION_ALLOW_METRICS: + lparams.allow_metrics_ = ParseOption(optarg); + break; + case OPTION_ALLOW_GPU_METRICS: + lparams.allow_gpu_metrics_ = ParseOption(optarg); + break; + case OPTION_ALLOW_CPU_METRICS: + lparams.allow_cpu_metrics_ = ParseOption(optarg); + break; + case OPTION_METRICS_ADDRESS: + lparams.metrics_address_ = optarg; + break; + case OPTION_METRICS_PORT: + lparams.metrics_port_ = ParseOption(optarg); + break; + case OPTION_METRICS_INTERVAL_MS: + lparams.metrics_interval_ms_ = ParseOption(optarg); + break; + case OPTION_METRICS_CONFIG: + lparams.metrics_config_settings_.push_back( + ParseMetricsConfigOption(optarg)); + break; #endif // TRITON_ENABLE_METRICS #ifdef TRITON_ENABLE_TRACING - case OPTION_TRACE_FILEPATH: { - std::cerr << "Warning: '--trace-file' has been deprecated and will be" - " removed in future releases. Please use " - "'--trace-config triton,file= instead." - << std::endl; - trace_filepath_present = true; - lparams.trace_filepath_ = optarg; - break; - } - case OPTION_TRACE_LEVEL: { - std::cerr << "Warning: '--trace-level' has been deprecated and will be" - " removed in future releases. Please use " - "'--trace-config level= instead." - << std::endl; - trace_level_present = true; - auto parsed_level = ParseTraceLevelOption(optarg); - explicit_disable_trace |= - (parsed_level == TRITONSERVER_TRACE_LEVEL_DISABLED); - lparams.trace_level_ = static_cast( - lparams.trace_level_ | parsed_level); - break; - } - case OPTION_TRACE_RATE: - std::cerr << "Warning: '--trace-rate' has been deprecated and will be" - " removed in future releases. Please use " - "'--trace-config rate= instead." - << std::endl; - trace_rate_present = true; - lparams.trace_rate_ = ParseOption( - optarg, GetOptionName(&long_options[option_index])); - break; - - case OPTION_TRACE_COUNT: - std::cerr << "Warning: '--trace-count' has been deprecated and will be" - " removed in future releases. Please use " - "'--trace-config count= instead." - << std::endl; - trace_count_present = true; - lparams.trace_count_ = ParseOption( - optarg, GetOptionName(&long_options[option_index])); - break; - case OPTION_TRACE_LOG_FREQUENCY: - std::cerr << "Warning: '--trace-log-frequency' has been deprecated and " - "will be" - " removed in future releases. Please use " - "'--trace-config triton,log-frequency= instead." - << std::endl; - trace_log_frequency_present = true; - lparams.trace_log_frequency_ = ParseOption( - optarg, GetOptionName(&long_options[option_index])); - break; - case OPTION_TRACE_CONFIG: { - auto trace_config_setting = ParseTraceConfigOption(optarg); - triton::server::TraceConfig& tc = - lparams - .trace_config_map_[std::get<0>(trace_config_setting).c_str()]; - tc.push_back(std::make_pair( - std::get<1>(trace_config_setting).c_str(), - std::get<2>(trace_config_setting).c_str())); - break; - } + case OPTION_TRACE_FILEPATH: { + std::cerr << "Warning: '--trace-file' has been deprecated and will be" + " removed in future releases. Please use " + "'--trace-config triton,file= instead." + << std::endl; + trace_filepath_present = true; + lparams.trace_filepath_ = optarg; + break; + } + case OPTION_TRACE_LEVEL: { + std::cerr + << "Warning: '--trace-level' has been deprecated and will be" + " removed in future releases. Please use " + "'--trace-config level= instead." + << std::endl; + trace_level_present = true; + auto parsed_level = ParseTraceLevelOption(optarg); + explicit_disable_trace |= + (parsed_level == TRITONSERVER_TRACE_LEVEL_DISABLED); + lparams.trace_level_ = static_cast( + lparams.trace_level_ | parsed_level); + break; + } + case OPTION_TRACE_RATE: + std::cerr << "Warning: '--trace-rate' has been deprecated and will be" + " removed in future releases. Please use " + "'--trace-config rate= instead." + << std::endl; + trace_rate_present = true; + lparams.trace_rate_ = ParseOption(optarg); + break; + + case OPTION_TRACE_COUNT: + std::cerr + << "Warning: '--trace-count' has been deprecated and will be" + " removed in future releases. Please use " + "'--trace-config count= instead." + << std::endl; + trace_count_present = true; + lparams.trace_count_ = ParseOption(optarg); + break; + case OPTION_TRACE_LOG_FREQUENCY: + std::cerr + << "Warning: '--trace-log-frequency' has been deprecated and " + "will be" + " removed in future releases. Please use " + "'--trace-config triton,log-frequency= instead." + << std::endl; + trace_log_frequency_present = true; + lparams.trace_log_frequency_ = ParseOption(optarg); + break; + case OPTION_TRACE_CONFIG: { + auto trace_config_setting = ParseTraceConfigOption(optarg); + triton::server::TraceConfig& tc = + lparams + .trace_config_map_[std::get<0>(trace_config_setting).c_str()]; + tc.push_back(std::make_pair( + std::get<1>(trace_config_setting).c_str(), + std::get<2>(trace_config_setting).c_str())); + break; + } #endif // TRITON_ENABLE_TRACING - case OPTION_POLL_REPO_SECS: - lparams.repository_poll_secs_ = ParseOption( - optarg, GetOptionName(&long_options[option_index])); - break; - case OPTION_STARTUP_MODEL: - lparams.startup_models_.insert(optarg); - break; - case OPTION_MODEL_CONTROL_MODE: { - std::string mode_str(optarg); - std::transform( - mode_str.begin(), mode_str.end(), mode_str.begin(), ::tolower); - if (mode_str == "none") { - lparams.control_mode_ = TRITONSERVER_MODEL_CONTROL_NONE; - } else if (mode_str == "poll") { - lparams.control_mode_ = TRITONSERVER_MODEL_CONTROL_POLL; - } else if (mode_str == "explicit") { - lparams.control_mode_ = TRITONSERVER_MODEL_CONTROL_EXPLICIT; - } else { - throw ParseException("invalid argument for --model-control-mode"); + case OPTION_POLL_REPO_SECS: + lparams.repository_poll_secs_ = ParseOption(optarg); + break; + case OPTION_STARTUP_MODEL: + lparams.startup_models_.insert(optarg); + break; + case OPTION_MODEL_CONTROL_MODE: { + std::string mode_str(optarg); + std::transform( + mode_str.begin(), mode_str.end(), mode_str.begin(), ::tolower); + if (mode_str == "none") { + lparams.control_mode_ = TRITONSERVER_MODEL_CONTROL_NONE; + } else if (mode_str == "poll") { + lparams.control_mode_ = TRITONSERVER_MODEL_CONTROL_POLL; + } else if (mode_str == "explicit") { + lparams.control_mode_ = TRITONSERVER_MODEL_CONTROL_EXPLICIT; + } else { + throw ParseException("invalid argument for --model-control-mode"); + } + break; } - break; - } - case OPTION_RATE_LIMIT: { - std::string rate_limit_str(optarg); - std::transform( - rate_limit_str.begin(), rate_limit_str.end(), - rate_limit_str.begin(), ::tolower); - if (rate_limit_str == "execution_count") { - lparams.rate_limit_mode_ = TRITONSERVER_RATE_LIMIT_EXEC_COUNT; - } else if (rate_limit_str == "off") { - lparams.rate_limit_mode_ = TRITONSERVER_RATE_LIMIT_OFF; - } else { - throw ParseException("invalid argument for --rate-limit"); + case OPTION_RATE_LIMIT: { + std::string rate_limit_str(optarg); + std::transform( + rate_limit_str.begin(), rate_limit_str.end(), + rate_limit_str.begin(), ::tolower); + if (rate_limit_str == "execution_count") { + lparams.rate_limit_mode_ = TRITONSERVER_RATE_LIMIT_EXEC_COUNT; + } else if (rate_limit_str == "off") { + lparams.rate_limit_mode_ = TRITONSERVER_RATE_LIMIT_OFF; + } else { + throw ParseException("invalid argument for --rate-limit"); + } + break; } - break; - } - case OPTION_RATE_LIMIT_RESOURCE: { - std::string rate_limit_resource_str(optarg); - std::transform( - rate_limit_resource_str.begin(), rate_limit_resource_str.end(), - rate_limit_resource_str.begin(), ::tolower); - // [FIXME] directly throw ParseException from parse helper - try { + case OPTION_RATE_LIMIT_RESOURCE: { + std::string rate_limit_resource_str(optarg); + std::transform( + rate_limit_resource_str.begin(), rate_limit_resource_str.end(), + rate_limit_resource_str.begin(), ::tolower); lparams.rate_limit_resources_.push_back( ParseRateLimiterResourceOption(optarg)); + break; } - catch (const std::invalid_argument& ia) { - throw ParseException( - std::string("failed to parse '") + optarg + - "' as ::"); + case OPTION_PINNED_MEMORY_POOL_BYTE_SIZE: + lparams.pinned_memory_pool_byte_size_ = ParseOption(optarg); + break; + case OPTION_CUDA_MEMORY_POOL_BYTE_SIZE: + lparams.cuda_pools_.push_back( + ParsePairOption(optarg, ":")); + break; + case OPTION_RESPONSE_CACHE_BYTE_SIZE: { + cache_size_present = true; + const auto byte_size = std::to_string(ParseOption(optarg)); + lparams.cache_config_settings_["local"] = {{"size", byte_size}}; + std::cerr + << "Warning: '--response-cache-byte-size' has been deprecated! " + "This will default to the 'local' cache implementation with " + "the provided byte size for its config. Please use " + "'--cache-config' instead. The equivalent " + "--cache-config CLI args would be: " + "'--cache-config=local,size=" + + byte_size + "'" + << std::endl; + break; } - break; - } - case OPTION_PINNED_MEMORY_POOL_BYTE_SIZE: - lparams.pinned_memory_pool_byte_size_ = ParseOption( - optarg, GetOptionName(&long_options[option_index])); - break; - case OPTION_CUDA_MEMORY_POOL_BYTE_SIZE: - lparams.cuda_pools_.push_back(ParsePairOption( - optarg, ":", GetOptionName(&long_options[option_index]))); - break; - case OPTION_RESPONSE_CACHE_BYTE_SIZE: { - cache_size_present = true; - const auto byte_size = std::to_string(ParseOption( - optarg, GetOptionName(&long_options[option_index]))); - lparams.cache_config_settings_["local"] = {{"size", byte_size}}; - std::cerr - << "Warning: '--response-cache-byte-size' has been deprecated! " - "This will default to the 'local' cache implementation with " - "the provided byte size for its config. Please use " - "'--cache-config' instead. The equivalent " - "--cache-config CLI args would be: " - "'--cache-config=local,size=" + - byte_size + "'" - << std::endl; - break; + case OPTION_CACHE_CONFIG: { + cache_config_present = true; + const auto cache_setting = ParseCacheConfigOption(optarg); + const auto& cache_name = std::get<0>(cache_setting); + const auto& key = std::get<1>(cache_setting); + const auto& value = std::get<2>(cache_setting); + lparams.cache_config_settings_[cache_name].push_back({key, value}); + break; + } + case OPTION_CACHE_DIR: + lparams.cache_dir_ = optarg; + break; + case OPTION_MIN_SUPPORTED_COMPUTE_CAPABILITY: + lparams.min_supported_compute_capability_ = + ParseOption(optarg); + break; + case OPTION_EXIT_TIMEOUT_SECS: + lparams.exit_timeout_secs_ = ParseOption(optarg); + break; + case OPTION_BACKEND_DIR: + lparams.backend_dir_ = optarg; + break; + case OPTION_REPOAGENT_DIR: + lparams.repoagent_dir_ = optarg; + break; + case OPTION_BUFFER_MANAGER_THREAD_COUNT: + lparams.buffer_manager_thread_count_ = ParseOption(optarg); + break; + case OPTION_MODEL_LOAD_THREAD_COUNT: + lparams.model_load_thread_count_ = ParseOption(optarg); + break; + case OPTION_BACKEND_CONFIG: + lparams.backend_config_settings_.push_back( + ParseBackendConfigOption(optarg)); + break; + case OPTION_HOST_POLICY: + lparams.host_policies_.push_back(ParseHostPolicyOption(optarg)); + break; + case OPTION_MODEL_LOAD_GPU_LIMIT: + lparams.load_gpu_limit_.emplace( + ParsePairOption(optarg, ":")); + break; + case OPTION_MODEL_NAMESPACING: + lparams.enable_model_namespacing_ = ParseOption(optarg); + break; } - case OPTION_CACHE_CONFIG: { - cache_config_present = true; - const auto cache_setting = ParseCacheConfigOption(optarg); - const auto& cache_name = std::get<0>(cache_setting); - const auto& key = std::get<1>(cache_setting); - const auto& value = std::get<2>(cache_setting); - lparams.cache_config_settings_[cache_name].push_back({key, value}); - break; + } + catch (const ParseException& pe) { + if ((pe.what() != NULL) && (strlen(pe.what()) != 0)) { + std::stringstream ss; + ss << "Bad option: \"--" << long_options[option_index].name << "\".\n" + << pe.what() << std::endl; + throw ParseException(ss.str()); + } else { + // In case of `Unrecognized option` or `Help` option, just throw a + // ParseException + throw ParseException(); } - case OPTION_CACHE_DIR: - lparams.cache_dir_ = optarg; - break; - case OPTION_MIN_SUPPORTED_COMPUTE_CAPABILITY: - lparams.min_supported_compute_capability_ = ParseOption( - optarg, GetOptionName(&long_options[option_index])); - break; - case OPTION_EXIT_TIMEOUT_SECS: - lparams.exit_timeout_secs_ = ParseOption( - optarg, GetOptionName(&long_options[option_index])); - break; - case OPTION_BACKEND_DIR: - lparams.backend_dir_ = optarg; - break; - case OPTION_REPOAGENT_DIR: - lparams.repoagent_dir_ = optarg; - break; - case OPTION_BUFFER_MANAGER_THREAD_COUNT: - lparams.buffer_manager_thread_count_ = ParseOption( - optarg, GetOptionName(&long_options[option_index])); - break; - case OPTION_MODEL_LOAD_THREAD_COUNT: - lparams.model_load_thread_count_ = ParseOption( - optarg, GetOptionName(&long_options[option_index])); - break; - case OPTION_BACKEND_CONFIG: - lparams.backend_config_settings_.push_back( - ParseBackendConfigOption(optarg)); - break; - case OPTION_HOST_POLICY: - lparams.host_policies_.push_back(ParseHostPolicyOption(optarg)); - break; - case OPTION_MODEL_LOAD_GPU_LIMIT: - lparams.load_gpu_limit_.emplace(ParsePairOption( - optarg, ":", GetOptionName(&long_options[option_index]))); - break; - case OPTION_MODEL_NAMESPACING: - lparams.enable_model_namespacing_ = ParseOption( - optarg, GetOptionName(&long_options[option_index])); - break; } } @@ -1890,17 +1856,12 @@ TritonParser::ParseRateLimiterResourceOption(const std::string& arg) } name_string = arg.substr(0, delim_first); count = ParseOption( - arg.substr(delim_first + 1, delim_second - delim_first - 1), - std::string("--rate-limit-resource ") + name_string); - device_id = ParseOption( - arg.substr(delim_second + 1), - std::string("--rate-limit-resource ") + name_string); + arg.substr(delim_first + 1, delim_second - delim_first - 1)); + device_id = ParseOption(arg.substr(delim_second + 1)); } else if (delim_first != std::string::npos) { // Handle format `:' name_string = arg.substr(0, delim_first); - count = ParseOption( - arg.substr(delim_first + 1), - std::string("--rate-limit-resource ") + name_string); + count = ParseOption(arg.substr(delim_first + 1)); } else { // If no colons found throw ParseException(error_string); @@ -2107,38 +2068,44 @@ TritonParser::SetGlobalTraceArgs( bool explicit_disable_trace) { for (const auto& global_setting : lparams.trace_config_map_[""]) { - if (global_setting.first == "rate") { - if (trace_rate_present) { - std::cerr << "Warning: Overriding deprecated '--trace-rate' " - "in favor of provided rate value in --trace-config!" - << std::endl; + try { + if (global_setting.first == "rate") { + if (trace_rate_present) { + std::cerr << "Warning: Overriding deprecated '--trace-rate' " + "in favor of provided rate value in --trace-config!" + << std::endl; + } + lparams.trace_rate_ = ParseOption(global_setting.second); } - lparams.trace_rate_ = ParseOption( - global_setting.second, std::string("trace-config rate")); - } - if (global_setting.first == "level") { - if (trace_level_present) { - std::cerr << "Warning: Overriding deprecated '--trace-level' " - "in favor of provided level in --trace-config!" - << std::endl; + if (global_setting.first == "level") { + if (trace_level_present) { + std::cerr << "Warning: Overriding deprecated '--trace-level' " + "in favor of provided level in --trace-config!" + << std::endl; + } + auto parsed_level_config = ParseTraceLevelOption(global_setting.second); + explicit_disable_trace |= + (parsed_level_config == TRITONSERVER_TRACE_LEVEL_DISABLED); + lparams.trace_level_ = static_cast( + lparams.trace_level_ | parsed_level_config); } - auto parsed_level_config = ParseTraceLevelOption(global_setting.second); - explicit_disable_trace |= - (parsed_level_config == TRITONSERVER_TRACE_LEVEL_DISABLED); - lparams.trace_level_ = static_cast( - lparams.trace_level_ | parsed_level_config); - } - if (global_setting.first == "mode") { - lparams.trace_mode_ = ParseTraceModeOption(global_setting.second); - } - if (global_setting.first == "count") { - if (trace_count_present) { - std::cerr << "Warning: Overriding deprecated '--trace-count' " - "in favor of provided count in --trace-config!" - << std::endl; + if (global_setting.first == "mode") { + lparams.trace_mode_ = ParseTraceModeOption(global_setting.second); + } + if (global_setting.first == "count") { + if (trace_count_present) { + std::cerr << "Warning: Overriding deprecated '--trace-count' " + "in favor of provided count in --trace-config!" + << std::endl; + } + lparams.trace_count_ = ParseOption(global_setting.second); } - lparams.trace_count_ = ParseOption( - global_setting.second, std::string("trace-config count")); + } + catch (const ParseException& pe) { + std::stringstream ss; + ss << "Bad option: \"--trace-config " << global_setting.first << "\".\n" + << pe.what() << std::endl; + throw ParseException(ss.str()); } } } @@ -2150,22 +2117,29 @@ TritonParser::SetTritonTraceArgs( { for (const auto& mode_setting : lparams.trace_config_map_[std::to_string(TRACE_MODE_TRITON)]) { - if (mode_setting.first == "file") { - if (trace_filepath_present) { - std::cerr << "Warning: Overriding deprecated '--trace-file' " - "in favor of provided file in --trace-config!" - << std::endl; - } - lparams.trace_filepath_ = mode_setting.second; - } else if (mode_setting.first == "log-frequency") { - if (trace_log_frequency_present) { - std::cerr << "Warning: Overriding deprecated '--trace-file' " - "in favor of provided file in --trace-config!" - << std::endl; + try { + if (mode_setting.first == "file") { + if (trace_filepath_present) { + std::cerr << "Warning: Overriding deprecated '--trace-file' " + "in favor of provided file in --trace-config!" + << std::endl; + } + lparams.trace_filepath_ = mode_setting.second; + } else if (mode_setting.first == "log-frequency") { + if (trace_log_frequency_present) { + std::cerr << "Warning: Overriding deprecated '--trace-file' " + "in favor of provided file in --trace-config!" + << std::endl; + } + lparams.trace_log_frequency_ = ParseOption(mode_setting.second); } - lparams.trace_log_frequency_ = ParseOption( - mode_setting.second, - std::string("trace-config=triton,log-frequency")); + } + catch (const ParseException& pe) { + std::stringstream ss; + ss << "Bad option: \"--trace-config triton," << mode_setting.first + << "\".\n" + << pe.what() << std::endl; + throw ParseException(ss.str()); } } } diff --git a/src/command_line_parser.h b/src/command_line_parser.h index 329d0ef316..efffcff94e 100644 --- a/src/command_line_parser.h +++ b/src/command_line_parser.h @@ -62,13 +62,13 @@ #define no_argument 2 struct option { option(const char* name, int has_arg, int* flag, int val) - : name_(name), has_arg_(has_arg), flag_(flag), val_(val) + : name(name), has_arg(has_arg), flag(flag), val(val) { } - const char* name_; - int has_arg_; - int* flag_; - int val_; + const char* name; + int has_arg; + int* flag; + int val; }; #endif #ifdef TRITON_ENABLE_TRACING @@ -315,9 +315,6 @@ class TritonParser { // Initialize option group mappings void SetupOptionGroups(); - // Retrieve option name - std::string GetOptionName(const struct option* long_option); - // Sum of option groups: vector to maintain insertion order for Usage() std::vector&>> option_groups_; // Individual option groups