Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial tensorrt ep commit #921

Merged
merged 13 commits into from
Jun 6, 2024
2 changes: 2 additions & 0 deletions sherpa-onnx/csrc/provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Provider StringToProvider(std::string s) {
return Provider::kXnnpack;
} else if (s == "nnapi") {
return Provider::kNNAPI;
} else if (s == "trt") {
return Provider::kTRT;
} else {
SHERPA_ONNX_LOGE("Unsupported string: %s. Fallback to cpu", s.c_str());
return Provider::kCPU;
Expand Down
1 change: 1 addition & 0 deletions sherpa-onnx/csrc/provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ enum class Provider {
kCoreML = 2, // CoreMLExecutionProvider
kXnnpack = 3, // XnnpackExecutionProvider
kNNAPI = 4, // NnapiExecutionProvider
kTRT = 5, // TensorRTExecutionProvider
};

/**
Expand Down
49 changes: 49 additions & 0 deletions sherpa-onnx/csrc/session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <string>
#include <utility>
#include <vector>
// #include <cuda.h>
manickavela29 marked this conversation as resolved.
Show resolved Hide resolved

#include "sherpa-onnx/csrc/macros.h"
#include "sherpa-onnx/csrc/provider.h"
Expand Down Expand Up @@ -115,6 +116,54 @@ static Ort::SessionOptions GetSessionOptionsImpl(int32_t num_threads,
#endif
break;
}
case Provider::kTRT: {
SHERPA_ONNX_LOGE("Came for TRT");
manickavela29 marked this conversation as resolved.
Show resolved Hide resolved
std::vector<const char*> option_keys = {
"device_id",
"trt_max_workspace_size",
"trt_max_partition_iterations",
"trt_min_subgraph_size",
"trt_fp16_enable",
"trt_int8_enable",
"trt_int8_use_native_calibration_table",
"trt_dump_subgraphs",
"trt_detailed_build_log",
// below options are strongly recommended !
"trt_engine_cache_enable",
"trt_engine_cache_path",
"trt_timing_cache_enable",
"trt_timing_cache_path",
};
std::vector<const char*> option_values = {
"0",
"2147483648",
"10",
"5",
"0",
"0",
"0",
"1",
"1",
"1",
".",
"1",
".", // can be same as the engine cache folder
};
std::vector<std::string> available_providers =
Ort::GetAvailableProviders();
if (std::find(available_providers.begin(), available_providers.end(),
"TensorrtExecutionProvider") != available_providers.end()) {
const auto& api = Ort::GetApi();

OrtTensorRTProviderOptionsV2* tensorrt_options;
manickavela29 marked this conversation as resolved.
Show resolved Hide resolved
Ort::ThrowOnError(api.CreateTensorRTProviderOptions(&tensorrt_options));
manickavela29 marked this conversation as resolved.
Show resolved Hide resolved

Ort::ThrowOnError(api.UpdateTensorRTProviderOptions(tensorrt_options,
option_keys.data(), option_values.data(), option_keys.size()));

sess_opts.AppendExecutionProvider_TensorRT_V2(*tensorrt_options);
}
}
}

return sess_opts;
Expand Down
Loading