Skip to content

Commit

Permalink
provide default value for trt_op_types_to_exclude and user can overri…
Browse files Browse the repository at this point in the history
…de it
  • Loading branch information
chilo-ms committed Nov 12, 2024
1 parent e680fe1 commit b030145
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ struct OrtTensorRTProviderOptionsV2 {

const char* trt_engine_cache_prefix{nullptr}; // specify engine cache prefix
int trt_engine_hw_compatible{0}; // Enable hardware compatibility. Default 0 = false, nonzero = true
const char* trt_op_types_to_exclude{nullptr}; // Exclude specific ops from running on TRT e.g. "NonMaxSuppression,NonZero,RoiAlign".
// Adding '~' followed by a op type e.g. '~NonZero', indicates that TRT EP will ensure this op is included for input to the TRT parser.
//const char* trt_dds_ops = "NonMaxSuppression,NonZero,RoiAlign";
const char* trt_op_types_to_exclude{"NonMaxSuppression,NonZero,RoiAlign"}; // Exclude specific ops from running on TRT.
// There is a known performance issue with the DDS ops (NonMaxSuppression, NonZero and RoiAlign) from TRT versions 10.0 to 10.7.
// TRT EP excludes DDS ops from running on TRT by default, user can override default value with empty string to include all ops.
};
19 changes: 2 additions & 17 deletions onnxruntime/core/providers/tensorrt/tensorrt_execution_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2488,27 +2488,12 @@ TensorrtExecutionProvider::GetCapability(const GraphViewer& graph,

std::set<std::string> exclude_set = GetExcludedNodeSet(op_types_to_exclude_);

/*
* There is a known performance issue with the DDS ops (NonMaxSuppression, NonZero and RoiAlign) from TRT versions 10.0 to 10.7.
* TRT EP automatically excludes DDS ops from running on TRT unless the user explicitly specifies that those ops should be included.
*
* Note: "~op_type" means to include the op type.
*/
if (trt_version_ >= 100000 && trt_version_ < 100800) {
if (exclude_set.find("~NonMaxSuppression") == exclude_set.end()) exclude_set.insert("NonMaxSuppression");
if (exclude_set.find("~NonZero") == exclude_set.end()) exclude_set.insert("NonZero");
if (exclude_set.find("~RoiAlign") == exclude_set.end()) exclude_set.insert("RoiAlign");
}

// Print excluded nodes, if any.
std::set<std::string>::iterator it;

Check warning on line 2492 in onnxruntime/core/providers/tensorrt/tensorrt_execution_provider.cc

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Add #include <set> for set<> [build/include_what_you_use] [4] Raw Output: onnxruntime/core/providers/tensorrt/tensorrt_execution_provider.cc:2492: Add #include <set> for set<> [build/include_what_you_use] [4]
for (it = exclude_set.begin(); it != exclude_set.end(); ++it) {
std::string op = *it;
if (op.find("~") == 0) continue;
LOGS_DEFAULT(VERBOSE) << "[TensorRT EP] Exclude " << op << " from running on TRT, if any.";
if (op == "NonMaxSuppression" || op == "NonZero" || op == "RoiAlign") {
LOGS_DEFAULT(VERBOSE) << "[TensorRT EP] Add \"~" << op << "\" in trt_op_types_to_exclude if " << op << " should be included in the input to TRT parser. However, it still depends on TRT parser to determine the eligibility of this op for TRT.";
}
LOGS_DEFAULT(VERBOSE) << "[TensorRT EP] Exclude \"" << op << "\" from running on TRT, if any.";
LOGS_DEFAULT(VERBOSE) << "[TensorRT EP] Remove \"" << op << "\" from trt_op_types_to_exclude or specify trt_op_types_to_exclude with empty string to include the op in the input to TRT parser. However, it still depends on TRT parser to determine the eligibility of this op for TRT.";
}

SubGraphCollection_t parser_nodes_vector, supported_nodes_vector;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ struct TensorrtExecutionProviderInfo {
int ep_context_embed_mode{0};
std::string engine_cache_prefix{""};
bool engine_hw_compatible{false};
std::string op_types_to_exclude{""};
// There is a known performance issue with the DDS ops (NonMaxSuppression, NonZero and RoiAlign) from TRT versions 10.0 to 10.7.
// TRT EP excludes DDS ops from running on TRT by default, user can override default value of trt_op_types_to_exclude with empty string to include all ops.
std::string op_types_to_exclude{"NonMaxSuppression,NonZero,RoiAlign"};

Check warning on line 65 in onnxruntime/core/providers/tensorrt/tensorrt_execution_provider_info.h

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Add #include <string> for string [build/include_what_you_use] [4] Raw Output: onnxruntime/core/providers/tensorrt/tensorrt_execution_provider_info.h:65: Add #include <string> for string [build/include_what_you_use] [4]

static TensorrtExecutionProviderInfo FromProviderOptions(const ProviderOptions& options);
static ProviderOptions ToProviderOptions(const TensorrtExecutionProviderInfo& info);
Expand Down
9 changes: 6 additions & 3 deletions onnxruntime/core/session/provider_bridge_ort.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2293,8 +2293,11 @@ ORT_API_STATUS_IMPL(OrtApis::UpdateTensorRTProviderOptions,
#ifdef USE_TENSORRT
onnxruntime::ProviderOptions provider_options_map;
for (size_t i = 0; i != num_keys; ++i) {
if (provider_options_keys[i] == nullptr || provider_options_keys[i][0] == '\0' ||
provider_options_values[i] == nullptr || provider_options_values[i][0] == '\0') {
// Don't allow key and value to be empty except the value of trt_op_types_to_exclude
if (provider_options_keys[i] == nullptr ||
provider_options_keys[i][0] == '\0' ||
(provider_options_values[i] == nullptr && strcmp("trt_op_types_to_exclude", provider_options_keys[i])) ||
(provider_options_values[i][0] == '\0' && strcmp("trt_op_types_to_exclude", provider_options_keys[i]))) {
return OrtApis::CreateStatus(ORT_INVALID_ARGUMENT, "key/value cannot be empty");
}

Expand Down Expand Up @@ -2409,7 +2412,7 @@ ORT_API(void, OrtApis::ReleaseTensorRTProviderOptions, _Frees_ptr_opt_ OrtTensor
delete[] ptr->trt_profile_opt_shapes;
delete[] ptr->trt_ep_context_file_path;
delete[] ptr->trt_onnx_model_folder_path;
delete[] ptr->trt_op_types_to_exclude;
if (!ptr->trt_op_types_to_exclude) delete[] ptr->trt_op_types_to_exclude;
}

std::unique_ptr<OrtTensorRTProviderOptionsV2> p(ptr);
Expand Down
2 changes: 1 addition & 1 deletion onnxruntime/python/onnxruntime_pybind_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ std::unique_ptr<IExecutionProvider> CreateExecutionProviderInstance(
// and TRT EP instance, so it won't be released.)
std::string calibration_table, cache_path, cache_prefix, timing_cache_path, lib_path, trt_tactic_sources,
trt_extra_plugin_lib_paths, min_profile, max_profile, opt_profile, ep_context_file_path,
onnx_model_folder_path, trt_op_types_to_exclude;
onnx_model_folder_path, trt_op_types_to_exclude{"NonMaxSuppression","NonZero","RoiAlign"};
auto it = provider_options_map.find(type);
if (it != provider_options_map.end()) {
OrtTensorRTProviderOptionsV2 params;
Expand Down

0 comments on commit b030145

Please sign in to comment.