From 71c098ca7b7b37671a29d5ea3174a514345cabdd Mon Sep 17 00:00:00 2001
From: Neil Evers <neil@oddity.ai>
Date: Thu, 25 Apr 2024 17:17:13 +0200
Subject: [PATCH 1/9] Fixed compilation with TensorRT 10

---
 src/ffi/builder_config.rs | 6 ++++++
 src/ffi/pre/helpers.rs    | 4 ++++
 src/ffi/sync/engine.rs    | 4 ++--
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/ffi/builder_config.rs b/src/ffi/builder_config.rs
index 3b455da..f11839c 100644
--- a/src/ffi/builder_config.rs
+++ b/src/ffi/builder_config.rs
@@ -61,7 +61,13 @@ impl BuilderConfig {
         cpp!(unsafe [
             internal as "void*"
         ] {
+            #if NV_TENSORRT_MAJOR > 9
+            ((IBuilderConfig*) internal)->setFlag(BuilderFlag::kPREFER_PRECISION_CONSTRAINTS);
+            ((IBuilderConfig*) internal)->setFlag(BuilderFlag::kDIRECT_IO);
+            ((IBuilderConfig*) internal)->setFlag(BuilderFlag::kREJECT_EMPTY_ALGORITHMS);
+            #else
             ((IBuilderConfig*) internal)->setFlag(BuilderFlag::kSTRICT_TYPES);
+            #endif
         });
         self
     }
diff --git a/src/ffi/pre/helpers.rs b/src/ffi/pre/helpers.rs
index 7e884db..4e2f531 100644
--- a/src/ffi/pre/helpers.rs
+++ b/src/ffi/pre/helpers.rs
@@ -9,7 +9,11 @@ cpp! {{
     void destroy(T* destroyable) {
         #pragma GCC diagnostic push
         #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+        #if NV_TENSORRT_MAJOR > 9
+        destroyable->~T();
+        #else
         destroyable->destroy();
+        #endif
         #pragma GCC diagnostic pop
     }
 }}
diff --git a/src/ffi/sync/engine.rs b/src/ffi/sync/engine.rs
index 359ec9a..385b433 100644
--- a/src/ffi/sync/engine.rs
+++ b/src/ffi/sync/engine.rs
@@ -85,7 +85,7 @@ impl Engine {
         let tensor_dimensions = cpp!(unsafe [
             internal as "const void*",
             tensor_name_ptr as "const char*"
-        ] -> Dims as "Dims32" {
+        ] -> Dims as "Dims64" {
             return ((const ICudaEngine*) internal)->getTensorShape(tensor_name_ptr);
         });
 
@@ -340,5 +340,5 @@ impl TensorIoMode {
 #[allow(non_snake_case)]
 struct Dims {
     pub nbDims: i32,
-    pub d: [i32; 8usize],
+    pub d: [i64; 8usize],
 }

From 29c6161c9ab039faf3068232eba63ecf74b52d3f Mon Sep 17 00:00:00 2001
From: Gerwin van der Lugt <gerwin3@users.noreply.github.com>
Date: Thu, 25 Apr 2024 18:39:09 +0200
Subject: [PATCH 2/9] make it a bit more clear that they have been removed from
 TensorRT 10 upwards

---
 src/ffi/builder_config.rs | 2 +-
 src/ffi/pre/helpers.rs    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/ffi/builder_config.rs b/src/ffi/builder_config.rs
index f11839c..1c57968 100644
--- a/src/ffi/builder_config.rs
+++ b/src/ffi/builder_config.rs
@@ -61,7 +61,7 @@ impl BuilderConfig {
         cpp!(unsafe [
             internal as "void*"
         ] {
-            #if NV_TENSORRT_MAJOR > 9
+            #if NV_TENSORRT_MAJOR >= 10
             ((IBuilderConfig*) internal)->setFlag(BuilderFlag::kPREFER_PRECISION_CONSTRAINTS);
             ((IBuilderConfig*) internal)->setFlag(BuilderFlag::kDIRECT_IO);
             ((IBuilderConfig*) internal)->setFlag(BuilderFlag::kREJECT_EMPTY_ALGORITHMS);
diff --git a/src/ffi/pre/helpers.rs b/src/ffi/pre/helpers.rs
index 4e2f531..6a93bf8 100644
--- a/src/ffi/pre/helpers.rs
+++ b/src/ffi/pre/helpers.rs
@@ -9,7 +9,7 @@ cpp! {{
     void destroy(T* destroyable) {
         #pragma GCC diagnostic push
         #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-        #if NV_TENSORRT_MAJOR > 9
+        #if NV_TENSORRT_MAJOR >= 10
         destroyable->~T();
         #else
         destroyable->destroy();

From 4b120fb020b018b174b5b7a710345d4b1d8a0726 Mon Sep 17 00:00:00 2001
From: Neil Evers <neil@oddity.ai>
Date: Fri, 26 Apr 2024 09:43:06 +0200
Subject: [PATCH 3/9] Use delete to destroy pointer

---
 src/ffi/pre/helpers.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/ffi/pre/helpers.rs b/src/ffi/pre/helpers.rs
index 6a93bf8..f51bd36 100644
--- a/src/ffi/pre/helpers.rs
+++ b/src/ffi/pre/helpers.rs
@@ -10,7 +10,7 @@ cpp! {{
         #pragma GCC diagnostic push
         #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
         #if NV_TENSORRT_MAJOR >= 10
-        destroyable->~T();
+        delete destroyable;
         #else
         destroyable->destroy();
         #endif

From 52dee6503363560ac0116b887f58d1df6772bf6c Mon Sep 17 00:00:00 2001
From: Gerwin van der Lugt <account+git@gerwin3.com>
Date: Mon, 29 Apr 2024 17:11:21 +0200
Subject: [PATCH 4/9] backwards compatibility with tensorrt < 10 for nbDims

---
 src/ffi/mod.rs         |  1 +
 src/ffi/pre/shims.rs   | 13 +++++++++++++
 src/ffi/sync/engine.rs | 12 +++++++++++-
 3 files changed, 25 insertions(+), 1 deletion(-)
 create mode 100644 src/ffi/pre/shims.rs

diff --git a/src/ffi/mod.rs b/src/ffi/mod.rs
index 66c0f70..30651ce 100644
--- a/src/ffi/mod.rs
+++ b/src/ffi/mod.rs
@@ -4,6 +4,7 @@
 #[rustfmt::skip]
 mod pre {
     mod includes;
+    mod shims;
     mod helpers;
     mod logger;
 }
diff --git a/src/ffi/pre/shims.rs b/src/ffi/pre/shims.rs
new file mode 100644
index 0000000..a520267
--- /dev/null
+++ b/src/ffi/pre/shims.rs
@@ -0,0 +1,13 @@
+use cpp::cpp;
+
+cpp! {{
+    #if NV_TENSORRT_MAJOR < 10
+    class Dims64
+    {
+    public:
+        static constexpr int32_t MAX_DIMS{8};
+        int32_t nbDims;
+        int64_t d[MAX_DIMS];
+    };
+    #endif
+}}
diff --git a/src/ffi/sync/engine.rs b/src/ffi/sync/engine.rs
index 385b433..dac5461 100644
--- a/src/ffi/sync/engine.rs
+++ b/src/ffi/sync/engine.rs
@@ -86,7 +86,17 @@ impl Engine {
             internal as "const void*",
             tensor_name_ptr as "const char*"
         ] -> Dims as "Dims64" {
+            #if NV_TENSORRT_MAJOR >= 10
             return ((const ICudaEngine*) internal)->getTensorShape(tensor_name_ptr);
+            #else
+            Dims32 dims32 = ((const ICudaEngine*) internal)->getTensorShape(tensor_name_ptr);
+            Dims64 dims64;
+            dims64.nbDims = dims32.nbDims;
+            for (int i = 0; i < dims32.nbDims; i++) {
+                dims64.d[i] = dims32.d[i];
+            }
+            return dims64;
+            #endif
         });
 
         let mut dimensions = Vec::with_capacity(tensor_dimensions.nbDims as usize);
@@ -334,7 +344,7 @@ impl TensorIoMode {
     }
 }
 
-/// Internal representation of the `Dims32` struct in TensorRT.
+/// Internal representation of the `Dims64` struct in TensorRT.
 #[repr(C)]
 #[derive(Debug, Copy, Clone)]
 #[allow(non_snake_case)]

From 3f3a1ef5c2792aed53878a01aaaa7df6f52d22f5 Mon Sep 17 00:00:00 2001
From: Gerwin van der Lugt <account+git@gerwin3.com>
Date: Fri, 23 Aug 2024 16:31:56 +0200
Subject: [PATCH 5/9] bump version to 0.8 and support for TensorRT 10

---
 Cargo.toml | 2 +-
 README.md  | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml
index 58e654e..b06daad 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -5,7 +5,7 @@ keywords = ["async", "nvidia", "cuda", "gpu", "tensorrt"]
 readme = "README.md"
 categories = ["asynchronous"]
 edition = "2021"
-version = "0.7.0"
+version = "0.8.0"
 authors = ["Oddity.ai Developers <hello@oddity.ai>"]
 repository = "https://github.com/oddity-ai/async-tensorrt"
 license = "MIT OR Apache-2.0"
diff --git a/README.md b/README.md
index 742fced..70ac93d 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
 <h1 align="center">
   <code>async-tensorrt</code>
 </h1>
-<p align="center">Asynchronous wrapper for TensorRT 8.</p>
+<p align="center">Asynchronous wrapper for TensorRT.</p>
 <div align="center">
 
 [![version](https://img.shields.io/crates/v/async-tensorrt)](https://crates.io/crates/async-tensorrt)
@@ -29,7 +29,7 @@ Make sure you have the necessary dependencies installed:
 Then, add the following to your dependencies in `Cargo.toml`:
 
 ```toml
-async-tensorrt = "0.7"
+async-tensorrt = "0.8"
 ```
 
 ## ⚠️ Safety warning

From af890e04b38ea95c3bcc0ebcbdce0ead9b67e103 Mon Sep 17 00:00:00 2001
From: Gerwin van der Lugt <account+git@gerwin3.com>
Date: Mon, 4 Nov 2024 11:19:06 +0100
Subject: [PATCH 6/9] bump version to 0.9 with async-cuda 0.6

---
 Cargo.toml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml
index b06daad..94085f9 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -5,13 +5,13 @@ keywords = ["async", "nvidia", "cuda", "gpu", "tensorrt"]
 readme = "README.md"
 categories = ["asynchronous"]
 edition = "2021"
-version = "0.8.0"
+version = "0.9.0"
 authors = ["Oddity.ai Developers <hello@oddity.ai>"]
 repository = "https://github.com/oddity-ai/async-tensorrt"
 license = "MIT OR Apache-2.0"
 
 [dependencies]
-async-cuda = "0.5.4"
+async-cuda = "0.6.0"
 cpp = "0.5"
 tracing = "0.1"
 

From 67e0e69543432ada4cac970459df86f0ac12eac9 Mon Sep 17 00:00:00 2001
From: "Micah Chambers (minerva)" <mchambers@anduril.com>
Date: Thu, 10 Apr 2025 16:11:04 -0700
Subject: [PATCH 7/9] add option to link to different tensorrt

---
 build.rs | 70 +++++++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 54 insertions(+), 16 deletions(-)

diff --git a/build.rs b/build.rs
index 7206204..e1db1cb 100644
--- a/build.rs
+++ b/build.rs
@@ -1,37 +1,75 @@
-fn main() {
-    let cuda_path = std::env::var("CUDA_PATH").map(std::path::PathBuf::from);
+fn search_for_path(
+    base_env: &str,
+    default_base: Option<&str>,
+    include_env: &str,
+    lib_env: &str,
+) -> (std::path::PathBuf, std::path::PathBuf) {
+    let base_path = if let Some(default_base) = default_base {
+        std::env::var(base_env)
+            .map(std::path::PathBuf::from)
+            .unwrap_or_else(|_| std::path::PathBuf::from(default_base))
+    } else {
+        std::env::var(base_env)
+            .map(std::path::PathBuf::from)
+            .expect(&format!("Missing environment variable `{base_env}`."))
+    };
 
-    #[cfg(not(windows))]
-    let cuda_path = cuda_path.unwrap_or_else(|_| std::path::PathBuf::from("/usr/local/cuda"));
-    #[cfg(windows)]
-    let cuda_path = cuda_path.expect("Missing environment variable `CUDA_PATH`.");
-
-    let cuda_include_path = std::env::var("CUDA_INCLUDE_PATH")
+    let include_path = std::env::var(include_env)
         .map(std::path::PathBuf::from)
-        .unwrap_or_else(|_| cuda_path.join("include"));
+        .unwrap_or_else(|_| base_path.join("include"));
 
-    let cuda_lib_path = std::env::var("CUDA_LIB_PATH")
+    let lib_path = std::env::var(lib_env)
         .map(std::path::PathBuf::from)
         .unwrap_or_else(|_| {
             #[cfg(not(windows))]
             {
-                cuda_path.join("lib64")
+                base_path.join("lib64")
             }
             #[cfg(windows)]
             {
-                cuda_path.join("lib").join("x64")
+                base_path.join("lib").join("x64")
             }
         });
 
+    (include_path, lib_path)
+}
+
+fn main() {
+    #[cfg(not(windows))]
+    let (cuda_include_path, cuda_lib_path) = search_for_path(
+        "CUDA_PATH",
+        Some("/usr/local/cuda"),
+        "CUDA_INCLUDE_PATH",
+        "CUDA_LIB_PATH",
+    );
+
+    #[cfg(windows)]
+    let (cuda_include_path, cuda_lib_path) =
+        search_for_path("CUDA_PATH", None, "CUDA_INCLUDE_PATH", "CUDA_LIB_PATH");
+
+    #[cfg(not(windows))]
+    let (tensorrt_include_path, tensorrt_lib_path) = search_for_path(
+        "TENSORRT_PATH",
+        Some("/usr/local/tensorrt"),
+        "TENSORRT_INCLUDE_PATH",
+        "TENSORRT_LIB_PATH",
+    );
+
+    #[cfg(windows)]
+    let (tensorrt_include_path, tensorrt_lib_path) = search_for_path(
+        "TENSORRT_PATH",
+        None,
+        "TENSORRT_INCLUDE_PATH",
+        "TENSORRT_LIB_PATH",
+    );
+
     let mut cpp_build_config = cpp_build::Config::new();
     cpp_build_config.include(cuda_include_path);
-    #[cfg(not(windows))]
-    cpp_build_config.include("/usr/local/tensorrt/include");
+    cpp_build_config.include(tensorrt_include_path);
     cpp_build_config.build("src/lib.rs");
 
     println!("cargo:rustc-link-search={}", cuda_lib_path.display());
-    #[cfg(not(windows))]
-    println!("cargo:rustc-link-search=/usr/local/tensorrt/lib64");
+    println!("cargo:rustc-link-search={}", tensorrt_lib_path.display());
 
     println!("cargo:rustc-link-lib=nvinfer");
     println!("cargo:rustc-link-lib=nvonnxparser");

From ed4cecb2f24d2dd6796a89151a3f64b14ee4314e Mon Sep 17 00:00:00 2001
From: Gerwin van der Lugt <account+git@gerwin3.com>
Date: Wed, 16 Jul 2025 11:05:17 +0200
Subject: [PATCH 8/9] relax the serialized_engine test

---
 flake.lock    | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/engine.rs |  3 +--
 2 files changed, 49 insertions(+), 2 deletions(-)
 create mode 100644 flake.lock

diff --git a/flake.lock b/flake.lock
new file mode 100644
index 0000000..7d94af9
--- /dev/null
+++ b/flake.lock
@@ -0,0 +1,48 @@
+{
+  "nodes": {
+    "nixpkgs": {
+      "locked": {
+        "lastModified": 1752480373,
+        "narHash": "sha256-JHQbm+OcGp32wAsXTE/FLYGNpb+4GLi5oTvCxwSoBOA=",
+        "owner": "nixos",
+        "repo": "nixpkgs",
+        "rev": "62e0f05ede1da0d54515d4ea8ce9c733f12d9f08",
+        "type": "github"
+      },
+      "original": {
+        "owner": "nixos",
+        "ref": "nixos-unstable",
+        "repo": "nixpkgs",
+        "type": "github"
+      }
+    },
+    "root": {
+      "inputs": {
+        "nixpkgs": "nixpkgs",
+        "rust-overlay": "rust-overlay"
+      }
+    },
+    "rust-overlay": {
+      "inputs": {
+        "nixpkgs": [
+          "nixpkgs"
+        ]
+      },
+      "locked": {
+        "lastModified": 1752633862,
+        "narHash": "sha256-Bj7ozT1+5P7NmvDcuAXJvj56txcXuAhk3Vd9FdWFQzk=",
+        "owner": "oxalica",
+        "repo": "rust-overlay",
+        "rev": "8668ca94858206ac3db0860a9dec471de0d995f8",
+        "type": "github"
+      },
+      "original": {
+        "owner": "oxalica",
+        "repo": "rust-overlay",
+        "type": "github"
+      }
+    }
+  },
+  "root": "root",
+  "version": 7
+}
diff --git a/src/engine.rs b/src/engine.rs
index bc3d54f..3da79d5 100644
--- a/src/engine.rs
+++ b/src/engine.rs
@@ -195,8 +195,7 @@ mod tests {
         let engine = simple_engine!();
         let serialized_engine = engine.serialize().unwrap();
         let serialized_engine_bytes = serialized_engine.as_bytes();
-        assert!(serialized_engine_bytes.len() > 1800);
-        assert!(serialized_engine_bytes.len() < 2500);
+        assert!(serialized_engine_bytes.len() > 0);
         assert_eq!(
             &serialized_engine_bytes[..8],
             &[102_u8, 116_u8, 114_u8, 116_u8, 0_u8, 0_u8, 0_u8, 0_u8],

From 05146f93fee979c42838ca37ffd72dab295d8067 Mon Sep 17 00:00:00 2001
From: "Micah Chambers (eos)" <mchambers@anduril.com>
Date: Wed, 6 Aug 2025 10:23:59 -0700
Subject: [PATCH 9/9] add version

---
 src/ffi/mod.rs     |  1 +
 src/ffi/version.rs | 16 ++++++++++++++++
 2 files changed, 17 insertions(+)
 create mode 100644 src/ffi/version.rs

diff --git a/src/ffi/mod.rs b/src/ffi/mod.rs
index 30651ce..72fdccc 100644
--- a/src/ffi/mod.rs
+++ b/src/ffi/mod.rs
@@ -16,6 +16,7 @@ pub mod network;
 pub mod optimization_profile;
 pub mod parser;
 pub mod sync;
+pub mod version;
 
 /// Convenience macro for turning TensorRT error code into a `std::result::Result`.
 ///
diff --git a/src/ffi/version.rs b/src/ffi/version.rs
new file mode 100644
index 0000000..5a037a2
--- /dev/null
+++ b/src/ffi/version.rs
@@ -0,0 +1,16 @@
+use cpp::cpp;
+
+/// Returns (Major, Minor, Patch, Build) version of tensorrt
+pub fn get_tensorrt_version() -> (u32, u32, u32) {
+    (
+        cpp!(unsafe [] -> u32 as "uint32_t" {
+            return NV_TENSORRT_MAJOR;
+        }),
+        cpp!(unsafe [] -> u32 as "uint32_t" {
+            return NV_TENSORRT_MINOR;
+        }),
+        cpp!(unsafe [] -> u32 as "uint32_t" {
+            return NV_TENSORRT_PATCH;
+        }),
+    )
+}
