#![cfg_attr(
any(feature = "mock", feature = "mock_runtime"),
allow(clippy::unnecessary_cast)
)]
#![cfg_attr(any(feature = "mock", feature = "mock_runtime"), allow(unused))]
#![cfg_attr(
any(feature = "mock", feature = "mock_runtime"),
allow(unused_variables)
)]
pub mod axes;
pub mod builder;
pub mod builder_config;
pub mod cuda;
pub mod cuda_engine;
pub mod engine_inspector;
pub mod error;
pub mod execution_context;
#[cfg(feature = "onnxparser")]
pub mod executor;
pub mod host_memory;
pub mod interfaces;
pub mod logger;
pub mod network;
#[cfg(feature = "onnxparser")]
pub mod onnx_parser;
pub mod optimization_profile;
pub mod refitter;
pub mod runtime;
#[cfg(not(feature = "enterprise"))]
pub mod runtime_cache;
pub mod runtime_config;
pub mod tensor;
pub use axes::Axes;
pub use builder::{Builder, BuilderConfig};
pub use cuda::{default_stream, synchronize, DeviceBuffer};
pub use error::{Error, Result};
#[cfg(feature = "onnxparser")]
pub use executor::{run_onnx_with_tensorrt, run_onnx_zeroed};
#[cfg(feature = "onnxparser")]
pub use executor::{TensorInput, TensorOutput};
#[cfg(feature = "dlopen_tensorrt_rtx")]
use libloading::AsFilename;
pub use logger::{LogHandler, Logger, Severity, StderrLogger};
pub use network::{ConvWeights, NetworkDefinition, OwnedConvWeights, OwnedWeights, Tensor};
#[cfg(feature = "onnxparser")]
pub use onnx_parser::OnnxParser;
pub use refitter::Refitter;
#[cfg(not(feature = "enterprise"))]
pub use runtime::RuntimeCache;
pub use runtime::{CudaEngine, EngineInspector, ExecutionContext, Runtime, RuntimeConfig};
#[cfg(feature = "dlopen_tensorrt_rtx")]
#[cfg(not(any(feature = "link_tensorrt_rtx", feature = "mock")))]
pub(crate) static TRTLIB: std::sync::RwLock<Option<libloading::Library>> =
std::sync::RwLock::new(None);
#[cfg(feature = "dlopen_tensorrt_rtx")]
pub fn dynamically_load_tensorrt(_filename: Option<impl AsFilename>) -> Result<()> {
#[cfg(not(any(feature = "link_tensorrt_rtx", feature = "mock")))]
{
use log::{debug, warn};
if TRTLIB.read()?.is_some() {
return Ok(());
}
let mut write = TRTLIB.write()?;
if write.is_none() {
let lib = if let Some(filename) = _filename {
debug!("Loading library TensorRT library");
unsafe { libloading::Library::new(filename) }
} else {
unsafe {
libloading::Library::new({
let filename = if cfg!(unix) {
if cfg!(feature = "enterprise") {
"libnvinfer.so".to_string()
} else {
use trtx_sys::{
get_tensorrt_major_version, get_tensorrt_minor_version,
get_tensorrt_patch_version,
};
format!(
"libtensorrt_rtx.so.{}.{}.{}",
get_tensorrt_major_version(),
get_tensorrt_minor_version(),
get_tensorrt_patch_version()
)
}
} else {
if cfg!(feature = "enterprise") {
"nvinfer.dll".to_string()
} else {
use trtx_sys::{
get_tensorrt_major_version, get_tensorrt_minor_version,
};
format!(
"tensorrt_rtx_{}_{}.dll",
get_tensorrt_major_version(),
get_tensorrt_minor_version()
)
}
};
debug!("Loading library {filename} as TensorRT library");
filename
})
}
}
.inspect_err(|e| warn!("Failed to load TensorRT library: {e:?}"))?;
*write = Some(lib);
}
}
Ok(())
}
#[cfg(feature = "dlopen_tensorrt_onnxparser")]
#[cfg(not(any(feature = "link_tensorrt_onnxparser", feature = "mock")))]
pub(crate) static TRT_ONNXPARSER_LIB: std::sync::RwLock<Option<libloading::Library>> =
std::sync::RwLock::new(None);
#[cfg(feature = "dlopen_tensorrt_onnxparser")]
pub fn dynamically_load_tensorrt_onnxparser(_filename: Option<impl AsFilename>) -> Result<()> {
#[cfg(not(any(feature = "link_tensorrt_onnxparser", feature = "mock")))]
{
use log::{debug, warn};
let mut write = TRT_ONNXPARSER_LIB.write()?;
if write.is_some() {
return Ok(());
}
let lib = if let Some(filename) = _filename {
debug!("Loading library TensorRT onnxparser library",);
unsafe { libloading::Library::new(filename) }
} else {
unsafe {
libloading::Library::new({
let filename = if cfg!(unix) {
if cfg!(feature = "enterprise") {
"libnvonnxparser.so".to_string()
} else {
use trtx_sys::{
get_tensorrt_major_version, get_tensorrt_minor_version,
get_tensorrt_patch_version,
};
format!(
"libtensorrt_onnxparser_rtx.so.{}.{}.{}",
get_tensorrt_major_version(),
get_tensorrt_minor_version(),
get_tensorrt_patch_version()
)
}
} else {
if cfg!(feature = "enterprise") {
"nvonnxparser.dll".to_string()
} else {
use trtx_sys::{
get_tensorrt_major_version, get_tensorrt_minor_version,
};
format!(
"tensorrt_onnxparser_rtx_{}_{}.dll",
get_tensorrt_major_version(),
get_tensorrt_minor_version()
)
}
};
debug!("Loading library {filename} as TensorRT onnxparser library");
filename
})
}
}
.inspect_err(|e| warn!("Failed to load TensorRT onnxparser library: {e:?}"))?;
*write = Some(lib);
}
Ok(())
}
pub use trtx_sys::{
self, ActivationType, AttentionNormalizationOp, BuilderFlag, CumulativeOperation, DataType,
DeviceType, ElementWiseOperation, EngineCapability, ExecutionContextAllocationStrategy,
FillOperation, GatherMode, HardwareCompatibilityLevel, InterpolationMode, KVCacheMode,
LayerInformationFormat, LayerType, LoopOutput, MatrixOperation, MemoryPoolType,
OptProfileSelector, PaddingMode, PoolingType, PreviewFeature, ProfilingVerbosity,
ReduceOperation, ResizeCoordinateTransformation, ResizeMode, ResizeRoundMode, ResizeSelector,
RuntimePlatform, SampleMode, ScaleMode, ScatterMode, SeekPosition, SerializationFlag,
TensorFormat, TensorIOMode, TensorLocation, TilingOptimizationLevel, TopKOperation, TripLimit,
UnaryOperation, WeightsRole,
};
#[cfg(not(feature = "enterprise"))]
pub use trtx_sys::{
ComputeCapability, CudaGraphStrategy, DynamicShapesKernelSpecializationStrategy,
};
#[cfg(feature = "v_1_4")]
pub use trtx_sys::{CollectiveOperation, MoEActType};
#[cfg(feature = "v_1_5")]
pub use trtx_sys::{AttentionIOForm, CausalMaskKind};