From 8f882cf01766d8d0387fa809c0cb55a35d7cbc29 Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Thu, 16 Jul 2026 10:06:49 +0200 Subject: [PATCH 1/2] trtexec-rs,ci: make RustNN optional --- trtexec-rs/Cargo.toml | 6 ++- trtexec-rs/src/main.rs | 94 +++++++++++------------------------------- 2 files changed, 29 insertions(+), 71 deletions(-) diff --git a/trtexec-rs/Cargo.toml b/trtexec-rs/Cargo.toml index 1d0adc2..3ece600 100644 --- a/trtexec-rs/Cargo.toml +++ b/trtexec-rs/Cargo.toml @@ -9,7 +9,7 @@ repository.workspace = true [dependencies] rustnn = { git = "https://github.com/rustnn/rustnn/", features = [ "trtx-runtime", -], default-features = false, branch = "main" } +], default-features = false, branch = "main", optional = true } nvidia-nvtx = { version = "0.2", git = "https://github.com/NVIDIA/NVTX", branch = "release-v3" } log = "0.4" @@ -29,3 +29,7 @@ cudarc = { version = "0.19", features = ["cuda-13020"] } tracing = { version = "0.1.44", features = ["attributes"] } tracing-subscriber = { version = "0.3.23", features = ["env-filter"] } serde_json = "1.0" + +[features] +default = ["rustnn"] +rustnn = ["dep:rustnn"] diff --git a/trtexec-rs/src/main.rs b/trtexec-rs/src/main.rs index 66f754c..6f4ac98 100644 --- a/trtexec-rs/src/main.rs +++ b/trtexec-rs/src/main.rs @@ -6,7 +6,9 @@ use cudarc::driver::CudaContext; use cudarc::driver::CudaSlice; use cudarc::driver::DevicePtrMut; use log::{debug, info}; +#[cfg(feature = "rustnn")] use rustnn::load_graph_from_path; +#[cfg(feature = "rustnn")] use rustnn::{GraphInfo, OperandKind}; use std::ffi::c_void; use std::fs::File; @@ -91,6 +93,7 @@ fn validate_weights_as_inputs(enabled: bool, inputs: &[impl AsRef]) -> Res Ok(()) } +#[cfg(feature = "rustnn")] fn promote_constants_to_inputs(graph: &mut GraphInfo) -> Result<()> { let constant_ids: Vec = graph .operands @@ -255,8 +258,12 @@ fn main() -> Result<()> { continue; } + #[cfg(feature = "rustnn")] let mut _graph = None; + #[cfg(feature = "rustnn")] let mut network = builder.create_network(0)?; + #[cfg(not(feature = "rustnn"))] + let network = builder.create_network(0)?; let mut _parser = None; let network = if is_webnn_path(onnx_path) { info!("Processing as RustNN file: {onnx_path:?}"); @@ -265,16 +272,24 @@ fn main() -> Result<()> { graph_path = onnx_path.to_string_lossy().to_string() ); let _enter = _span.enter(); - let mut graph = load_graph_from_path(onnx_path)?; - if args.weights_as_inputs { - promote_constants_to_inputs(&mut graph)?; + #[cfg(not(feature = "rustnn"))] + { + bail!("`rustnn` feature is disabled! Can't process webnn files"); + } + + #[cfg(feature = "rustnn")] + { + let mut graph = load_graph_from_path(onnx_path)?; + if args.weights_as_inputs { + promote_constants_to_inputs(&mut graph)?; + } + _graph = Some(graph); + rustnn::converters::TrtxConverter::build_network( + _graph.as_ref().unwrap(), + &mut network, + )?; + &mut network } - _graph = Some(graph); - rustnn::converters::TrtxConverter::build_network( - _graph.as_ref().unwrap(), - &mut network, - )?; - &mut network } else { debug!("Processing as ONNX file: {onnx_path:?}"); let mut parser = OnnxParser::new(network, &logger)?; @@ -479,64 +494,3 @@ fn main() -> Result<()> { Ok(()) } - -#[cfg(test)] -mod tests { - use super::*; - use rustnn::graph::Dimension; - use rustnn::{ConstantData, DataType, Operand, OperandDescriptor}; - use std::collections::HashMap; - use std::path::PathBuf; - - #[test] - fn promotes_constants_to_sorted_inputs() { - let mut constants = HashMap::new(); - constants.insert( - 1, - ConstantData { - data: vec![0; 8], - label: None, - }, - ); - let descriptor = OperandDescriptor { - data_type: DataType::Float32, - shape: vec![Dimension::Static(2)], - pending_permutation: Vec::new(), - }; - let mut graph = GraphInfo { - operands: vec![ - Operand { - kind: OperandKind::Input, - descriptor: descriptor.clone(), - name: Some("input".into()), - }, - Operand { - kind: OperandKind::Constant, - descriptor, - name: Some("old-name".into()), - }, - ], - input_operands: vec![0], - constant_operand_ids_to_handles: constants, - ..GraphInfo::default() - }; - - promote_constants_to_inputs(&mut graph).unwrap(); - - assert_eq!(graph.operands[1].kind, OperandKind::Input); - assert_eq!(graph.operands[1].name.as_deref(), Some("1")); - assert_eq!(graph.input_operands, vec![0, 1]); - assert!(graph.constant_operand_ids_to_handles.is_empty()); - } - - #[test] - fn weights_as_inputs_rejects_non_webnn_inputs() { - assert!(validate_weights_as_inputs(true, &[PathBuf::from("model.onnx")]).is_err()); - assert!(validate_weights_as_inputs(true, &[] as &[PathBuf]).is_err()); - assert!(validate_weights_as_inputs( - true, - &[PathBuf::from("one.webnn"), PathBuf::from("two.json")] - ) - .is_ok()); - } -} From 0e279eec2a53379015046a365ddc11e03c1076c5 Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Fri, 17 Jul 2026 13:40:54 +0200 Subject: [PATCH 2/2] ci: allow long path names on Windows --- .github/workflows/ci.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 807b1a4..2d053c7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,6 +22,13 @@ jobs: - name: Checkout code uses: actions/checkout@v6 + # Needed for RustNN snapshots for long test names + - name: Allow Windows long paths + if: ${{ matrix.os == 'windows-latest' }} + run: | + New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force + git config --system core.longpaths true + - name: Install Rust uses: dtolnay/rust-toolchain@master with: