Skip to content

Commit d66cff1

Browse files
vrasparsnnngedoensmax
authored
Cherry-picks into rel-1.22.0 (#24624)
### Description Cherry pick the following into [rel-1.22.0](https://github.com/microsoft/onnxruntime/tree/rel-1.22.0) - (#24608) - (#24545) --------- Co-authored-by: Changming Sun <[email protected]> Co-authored-by: Maximilian Müller <[email protected]>
1 parent cf92d98 commit d66cff1

19 files changed

+300
-214
lines changed

onnxruntime/core/providers/nv_tensorrt_rtx/nv_execution_provider.cc

+118-82
Large diffs are not rendered by default.

onnxruntime/core/providers/nv_tensorrt_rtx/nv_execution_provider_custom_ops.cc

+7-7
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,17 @@ common::Status CreateTensorRTCustomOpDomainList(std::vector<OrtCustomOpDomain*>&
5858
while (std::getline(extra_plugin_libs, lib, ';')) {
5959
auto status = LoadDynamicLibrary(ToPathString(lib));
6060
if (status == Status::OK()) {
61-
LOGS_DEFAULT(VERBOSE) << "[Nv EP] Successfully load " << lib;
61+
LOGS_DEFAULT(VERBOSE) << "[NvTensorRTRTX EP] Successfully load " << lib;
6262
} else {
63-
LOGS_DEFAULT(WARNING) << "[Nv EP]" << status.ToString();
63+
LOGS_DEFAULT(WARNING) << "[NvTensorRTRTX EP]" << status.ToString();
6464
}
6565
}
6666
is_loaded = true;
6767
}
6868

6969
try {
7070
// Get all registered TRT plugins from registry
71-
LOGS_DEFAULT(VERBOSE) << "[Nv EP] Getting all registered TRT plugins from TRT plugin registry ...";
71+
LOGS_DEFAULT(VERBOSE) << "[NvTensorRTRTX EP] Getting all registered TRT plugins from TRT plugin registry ...";
7272
TensorrtLogger trt_logger = GetTensorrtLogger(false);
7373
void* library_handle = nullptr;
7474
const auto& env = onnxruntime::GetDefaultEnv();
@@ -79,14 +79,14 @@ common::Status CreateTensorRTCustomOpDomainList(std::vector<OrtCustomOpDomain*>&
7979
bool (*dyn_initLibNvInferPlugins)(void* logger, char const* libNamespace);
8080
ORT_THROW_IF_ERROR(env.GetSymbolFromLibrary(library_handle, "initLibNvInferPlugins", (void**)&dyn_initLibNvInferPlugins));
8181
dyn_initLibNvInferPlugins(&trt_logger, "");
82-
LOGS_DEFAULT(INFO) << "[Nv EP] Default plugins successfully loaded.";
82+
LOGS_DEFAULT(INFO) << "[NvTensorRTRTX EP] Default plugins successfully loaded.";
8383

8484
#if defined(_MSC_VER)
8585
#pragma warning(push)
8686
#pragma warning(disable : 4996) // Ignore warning C4996: 'nvinfer1::*' was declared deprecated
8787
#endif
8888
} catch (const std::exception&) {
89-
LOGS_DEFAULT(INFO) << "[Nv EP] Default plugin library is not on the path and is therefore ignored";
89+
LOGS_DEFAULT(INFO) << "[NvTensorRTRTX EP] Default plugin library is not on the path and is therefore ignored";
9090
}
9191
try {
9292
int num_plugin_creator = 0;
@@ -96,7 +96,7 @@ common::Status CreateTensorRTCustomOpDomainList(std::vector<OrtCustomOpDomain*>&
9696
for (int i = 0; i < num_plugin_creator; i++) {
9797
auto plugin_creator = plugin_creators[i];
9898
std::string plugin_name(plugin_creator->getPluginName());
99-
LOGS_DEFAULT(VERBOSE) << "[Nv EP] " << plugin_name << ", version : " << plugin_creator->getPluginVersion();
99+
LOGS_DEFAULT(VERBOSE) << "[NvTensorRTRTX EP] " << plugin_name << ", version : " << plugin_creator->getPluginVersion();
100100

101101
// plugin has different versions and we only register once
102102
if (registered_plugin_names.find(plugin_name) != registered_plugin_names.end()) {
@@ -116,7 +116,7 @@ common::Status CreateTensorRTCustomOpDomainList(std::vector<OrtCustomOpDomain*>&
116116
custom_op_domain->domain_ = "trt.plugins";
117117
domain_list.push_back(custom_op_domain.get());
118118
} catch (const std::exception&) {
119-
LOGS_DEFAULT(WARNING) << "[Nv EP] Failed to get TRT plugins from TRT plugin registration. Therefore, TRT EP can't create custom ops for TRT plugins";
119+
LOGS_DEFAULT(WARNING) << "[NvTensorRTRTX EP] Failed to get TRT plugins from TRT plugin registration. Therefore, TRT EP can't create custom ops for TRT plugins";
120120
}
121121
return Status::OK();
122122
}

onnxruntime/core/providers/nv_tensorrt_rtx/nv_execution_provider_helper.cc

+8-8
Original file line numberDiff line numberDiff line change
@@ -169,31 +169,31 @@ void NvExecutionProvider::SetGraphOuterScopeValuesAndInputs(Graph& graph_build,
169169
}
170170
std::string unique_graph_name = GetUniqueGraphName(*top_level_graph);
171171
if (subgraph_context_map_.find(unique_graph_name) == subgraph_context_map_.end()) {
172-
LOGS_DEFAULT(ERROR) << "[Nv EP] Can't find top-level graph context. \
172+
LOGS_DEFAULT(ERROR) << "[NvTensorRTRTX EP] Can't find top-level graph context. \
173173
Please check BuildSubGraphContext() has built the graph context correctly.";
174174
return;
175175
}
176176

177177
SubGraphContext* context = subgraph_context_map_.at(unique_graph_name).get();
178178

179-
LOGS_DEFAULT(VERBOSE) << "[Nv EP] Subgraph name is " << graph_build.Name();
180-
LOGS_DEFAULT(VERBOSE) << "[Nv EP] Its parent node is " << graph.ParentNode()->Name();
181-
LOGS_DEFAULT(VERBOSE) << "[Nv EP] Its parent node's implicit inputs:";
179+
LOGS_DEFAULT(VERBOSE) << "[NvTensorRTRTX EP] Subgraph name is " << graph_build.Name();
180+
LOGS_DEFAULT(VERBOSE) << "[NvTensorRTRTX EP] Its parent node is " << graph.ParentNode()->Name();
181+
LOGS_DEFAULT(VERBOSE) << "[NvTensorRTRTX EP] Its parent node's implicit inputs:";
182182

183183
// Iterate all the implicit inputs to set outer scope value for the newly built subgraph
184184
for (const auto& input : graph.ParentNode()->ImplicitInputDefs()) {
185-
LOGS_DEFAULT(VERBOSE) << "[Nv EP] \t" << input->Name();
185+
LOGS_DEFAULT(VERBOSE) << "[NvTensorRTRTX EP] \t" << input->Name();
186186

187187
// The node arg in parent node's implicit inputs could be used for parent node's other subgraph, for example
188188
// "If" op has two subgraphs. So we need to make sure that the node arg is used in current subgraph only.
189189
// (GetNodeArg searches for specific node arg in all node args in the graph)
190190
if (graph_build.GetNodeArg(input->Name())) {
191191
graph_build.AddOuterScopeNodeArg(input->Name());
192-
LOGS_DEFAULT(VERBOSE) << "[Nv EP] \t" << input->Name() << " is used in this subgraph";
192+
LOGS_DEFAULT(VERBOSE) << "[NvTensorRTRTX EP] \t" << input->Name() << " is used in this subgraph";
193193

194194
if (context &&
195195
(context->manually_added_graph_inputs.find(input->Name()) != context->manually_added_graph_inputs.end())) {
196-
LOGS_DEFAULT(VERBOSE) << "[Nv EP] \t" << input->Name() << " is already been added as an explicit input to graph";
196+
LOGS_DEFAULT(VERBOSE) << "[NvTensorRTRTX EP] \t" << input->Name() << " is already been added as an explicit input to graph";
197197
continue;
198198
}
199199

@@ -213,7 +213,7 @@ void NvExecutionProvider::SetGraphOuterScopeValuesAndInputs(Graph& graph_build,
213213
type_proto->copy_from(input->TypeAsProto());
214214
auto& n_input = top_level_graph->GetOrCreateNodeArg(name, type_proto.get());
215215
context->manually_added_graph_inputs[n_input.Name()] = &n_input;
216-
LOGS_DEFAULT(VERBOSE) << "[Nv EP] \t" << n_input.Name() << " is added as an explicit input into the newly built graph";
216+
LOGS_DEFAULT(VERBOSE) << "[NvTensorRTRTX EP] \t" << n_input.Name() << " is added as an explicit input into the newly built graph";
217217
}
218218
}
219219
}

onnxruntime/core/providers/nv_tensorrt_rtx/nv_execution_provider_info.cc

+22-1
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
#include "core/providers/nv_tensorrt_rtx/nv_execution_provider_info.h"
55
#include "core/providers/nv_tensorrt_rtx/nv_provider_options.h"
66

7+
#include "core/session/onnxruntime_session_options_config_keys.h"
78
#include "core/common/make_string.h"
89
#include "core/common/parse_string.h"
910
#include "core/framework/provider_options_utils.h"
1011
#include "core/providers/cuda/cuda_common.h"
1112

1213
namespace onnxruntime {
13-
NvExecutionProviderInfo NvExecutionProviderInfo::FromProviderOptions(const ProviderOptions& options) {
14+
NvExecutionProviderInfo NvExecutionProviderInfo::FromProviderOptions(const ProviderOptions& options,
15+
const ConfigOptions& session_options) {
1416
NvExecutionProviderInfo info{};
1517
void* user_compute_stream = nullptr;
1618
void* onnx_bytestream = nullptr;
@@ -58,6 +60,25 @@ NvExecutionProviderInfo NvExecutionProviderInfo::FromProviderOptions(const Provi
5860
info.user_compute_stream = user_compute_stream;
5961
info.has_user_compute_stream = (user_compute_stream != nullptr);
6062
info.onnx_bytestream = onnx_bytestream;
63+
64+
// EP context settings
65+
const auto embed_enable = session_options.GetConfigOrDefault(kOrtSessionOptionEpContextEnable, "0");
66+
if (embed_enable == "0") {
67+
info.dump_ep_context_model = false;
68+
} else if (embed_enable == "1") {
69+
info.dump_ep_context_model = true;
70+
} else {
71+
ORT_THROW("Invalid ", kOrtSessionOptionEpContextEnable, " must 0 or 1");
72+
}
73+
info.ep_context_file_path = session_options.GetConfigOrDefault(kOrtSessionOptionEpContextFilePath, "");
74+
75+
const auto embed_mode = std::stoi(session_options.GetConfigOrDefault(kOrtSessionOptionEpContextEmbedMode, "1"));
76+
if (0 <= embed_mode || embed_mode < 2) {
77+
info.ep_context_embed_mode = embed_mode;
78+
} else {
79+
ORT_THROW("Invalid ", kOrtSessionOptionEpContextEmbedMode, " must 0 or 1");
80+
}
81+
6182
return info;
6283
}
6384

onnxruntime/core/providers/nv_tensorrt_rtx/nv_execution_provider_info.h

+4-17
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
#include "core/framework/ortdevice.h"
99
#include "core/framework/provider_options.h"
1010
#include "core/framework/framework_provider_common.h"
11-
#include "core/session/onnxruntime_c_api.h"
1211
#include "core/framework/library_handles.h"
12+
#include "core/session/onnxruntime_c_api.h"
13+
#include "core/providers/shared_library/provider_api.h"
1314

1415
#define TRT_DEFAULT_OPTIMIZER_LEVEL 3
1516

@@ -19,18 +20,10 @@ struct NvExecutionProviderInfo {
1920
int device_id{0};
2021
bool has_user_compute_stream{false};
2122
void* user_compute_stream{nullptr};
22-
bool has_trt_options{false};
2323
int max_partition_iterations{1000};
2424
int min_subgraph_size{1};
2525
size_t max_workspace_size{0};
26-
bool fp16_enable{false};
27-
bool int8_enable{false};
28-
std::string int8_calibration_table_name{""};
29-
bool int8_use_native_calibration_table{false};
30-
bool dla_enable{false};
31-
int dla_core{0};
3226
bool dump_subgraphs{false};
33-
bool engine_cache_enable{false};
3427
std::string engine_cache_path{""};
3528
bool weight_stripped_engine_enable{false};
3629
std::string onnx_model_folder_path{""};
@@ -40,16 +33,10 @@ struct NvExecutionProviderInfo {
4033
std::string engine_decryption_lib_path{""};
4134
bool force_sequential_engine_build{false};
4235
bool context_memory_sharing_enable{false};
43-
bool layer_norm_fp32_fallback{false};
44-
bool timing_cache_enable{false};
4536
std::string timing_cache_path{""};
46-
bool force_timing_cache{false};
4737
bool detailed_build_log{false};
48-
bool build_heuristics_enable{false};
4938
bool sparsity_enable{false};
50-
int builder_optimization_level{3};
5139
int auxiliary_streams{-1};
52-
std::string tactic_sources{""};
5340
std::string extra_plugin_lib_paths{""};
5441
std::string profile_min_shapes{""};
5542
std::string profile_max_shapes{""};
@@ -59,10 +46,10 @@ struct NvExecutionProviderInfo {
5946
std::string ep_context_file_path{""};
6047
int ep_context_embed_mode{0};
6148
std::string engine_cache_prefix{""};
62-
bool engine_hw_compatible{false};
6349
std::string op_types_to_exclude{""};
6450

65-
static NvExecutionProviderInfo FromProviderOptions(const ProviderOptions& options);
51+
static NvExecutionProviderInfo FromProviderOptions(const ProviderOptions& options,
52+
const ConfigOptions& session_options);
6653
static ProviderOptions ToProviderOptions(const NvExecutionProviderInfo& info);
6754
std::vector<OrtCustomOpDomain*> custom_op_domain_list;
6855
};

0 commit comments

Comments
 (0)