Skip to content

Commit ad07c2c

Browse files
authored
Update trt-ep setting (#229)
1 parent 449a161 commit ad07c2c

3 files changed

Lines changed: 42 additions & 1 deletion

File tree

src/config/impl_ep.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,13 @@ impl Config {
122122
impl_ep_field!(tensorrt, max_workspace_size, usize);
123123
impl_ep_field!(tensorrt, min_subgraph_size, usize);
124124
impl_ep_field!(tensorrt, fp16, bool);
125+
impl_ep_field!(tensorrt, int8, bool);
125126
impl_ep_field!(tensorrt, engine_cache, bool);
126127
impl_ep_field!(tensorrt, timing_cache, bool);
128+
impl_ep_field!(tensorrt, dla, bool);
129+
impl_ep_field!(tensorrt, dla_core, u32);
130+
impl_ep_field!(tensorrt, int8_use_native_calibration_table, bool);
131+
impl_ep_field!(tensorrt, detailed_build_log, bool);
127132

128133
// ---------------- coreml -----------------------
129134
impl_ep_field!(coreml, static_input_shapes, bool);

src/ort/engine.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,13 +641,20 @@ impl Engine {
641641
let cache_path =
642642
crate::Dir::Cache.crate_dir_default_with_subs(&["caches", "tensorrt"])?;
643643

644-
let ep = ort::execution_providers::TensorRTExecutionProvider::default()
644+
let mut ep = ort::execution_providers::TensorRTExecutionProvider::default()
645645
.with_device_id(id as i32)
646646
.with_max_workspace_size(config.ep.tensorrt.max_workspace_size)
647647
.with_builder_optimization_level(
648648
config.ep.tensorrt.builder_optimization_level,
649649
)
650+
.with_dla_core(config.ep.tensorrt.dla_core)
651+
.with_dla(config.ep.tensorrt.dla)
652+
.with_detailed_build_log(config.ep.tensorrt.detailed_build_log)
650653
.with_fp16(config.ep.tensorrt.fp16)
654+
.with_int8(config.ep.tensorrt.int8)
655+
.with_int8_use_native_calibration_table(
656+
config.ep.tensorrt.int8_use_native_calibration_table,
657+
)
651658
.with_engine_cache(config.ep.tensorrt.engine_cache)
652659
.with_timing_cache(config.ep.tensorrt.timing_cache)
653660
.with_dump_ep_context_model(config.ep.tensorrt.dump_ep_context_model)
@@ -659,6 +666,13 @@ impl Engine {
659666
.with_profile_min_shapes(spec_min)
660667
.with_profile_opt_shapes(spec_opt)
661668
.with_profile_max_shapes(spec_max);
669+
if config.ep.tensorrt.int8
670+
&& !config.ep.tensorrt.int8_calibration_table_name.is_empty()
671+
{
672+
ep = ep.with_int8_calibration_table_name(
673+
config.ep.tensorrt.int8_calibration_table_name.clone(),
674+
);
675+
}
662676

663677
match ep.is_available() {
664678
Ok(true) => {

src/ort/ep_config.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,27 +45,49 @@ impl Default for CudaConfig {
4545
/// NVIDIA TensorRT execution provider configuration.
4646
#[derive(Debug, Clone, Serialize, Deserialize)]
4747
pub struct TensorRtConfig {
48+
pub detailed_build_log: bool,
4849
pub fp16: bool,
50+
pub int8: bool,
51+
/// Description: specify INT8 calibration table file for non-QDQ models in INT8 mode.
52+
/// Note: calibration table should not be provided for QDQ model
53+
/// because TensorRT doesn’t allow calibration table to be loded if there is any Q/DQ node in the model.
54+
/// By default the name is empty.
55+
pub int8_calibration_table_name: String,
56+
/// Description: select what calibration table is used for non-QDQ models in INT8 mode.
57+
/// If True, native TensorRT generated calibration table is used;
58+
/// If False, ONNXRUNTIME tool generated calibration table is used.
59+
/// Note: Please copy up-to-date calibration table file to trt_engine_cache_path before inference.
60+
/// Calibration table is specific to models and calibration data sets.
61+
/// Whenever new calibration table is generated, old file in the path should be cleaned up or be replaced.
62+
pub int8_use_native_calibration_table: bool,
4963
pub engine_cache: bool,
5064
pub timing_cache: bool,
5165
pub dump_ep_context_model: bool,
5266
pub dump_subgraphs: bool,
5367
pub builder_optimization_level: u8,
5468
pub max_workspace_size: usize,
5569
pub min_subgraph_size: usize,
70+
pub dla_core: u32,
71+
pub dla: bool,
5672
}
5773

5874
impl Default for TensorRtConfig {
5975
fn default() -> Self {
6076
Self {
77+
detailed_build_log: true,
6178
fp16: true,
79+
int8: false,
80+
int8_calibration_table_name: "".to_string(),
81+
int8_use_native_calibration_table: true,
6282
engine_cache: true,
6383
timing_cache: false,
6484
dump_ep_context_model: false, // TODO
6585
dump_subgraphs: false,
6686
builder_optimization_level: 3, // 3, 0-5
6787
max_workspace_size: 1073741824, // 1G
6888
min_subgraph_size: 1,
89+
dla_core: 0,
90+
dla: false,
6991
}
7092
}
7193
}

0 commit comments

Comments
 (0)