From f4659f1c0a41301c54211d31cefe1e733b9eec0c Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Tue, 21 Jul 2026 13:44:48 +0200 Subject: [PATCH] fix: remove lifetime from RuntimeCache RuntimeCache can outlive an engine and be shared between engines. --- trtx/src/runtime_cache.rs | 16 ++++++---------- trtx/src/runtime_config.rs | 8 ++++---- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/trtx/src/runtime_cache.rs b/trtx/src/runtime_cache.rs index f2025ab..84567cc 100644 --- a/trtx/src/runtime_cache.rs +++ b/trtx/src/runtime_cache.rs @@ -2,8 +2,6 @@ //! //! [`RuntimeCache`] wraps [`trtx_sys::nvinfer1::IRuntimeCache`] (C++ [`nvinfer1::IRuntimeCache`](https://docs.nvidia.com/deeplearning/tensorrt-rtx/latest/_static/cpp-api/classnvinfer1_1_1_i_runtime_cache.html). -use std::marker::PhantomData; - use crate::error::{PropertySetAttempt, Result}; use crate::host_memory::HostMemory; use crate::Error; @@ -11,19 +9,18 @@ use cxx::UniquePtr; use trtx_sys::nvinfer1::{self, IRuntimeCache}; /// [`trtx_sys::nvinfer1::IRuntimeCache`] — C++ [`nvinfer1::IRuntimeCache`](https://docs.nvidia.com/deeplearning/tensorrt-rtx/latest/_static/cpp-api/classnvinfer1_1_1_i_runtime_cache.html). -pub struct RuntimeCache<'engine> { +pub struct RuntimeCache { pub(crate) inner: UniquePtr, - _engine: PhantomData<&'engine nvinfer1::ICudaEngine>, } /// # Safety /// /// IRuntimeCache is internally protected by a shared mutex and /// UniquePtr holds after initialization a valid IRuntimeCache (or nullptr in mock mode) -unsafe impl Send for RuntimeCache<'_> {} -unsafe impl Sync for RuntimeCache<'_> {} +unsafe impl Send for RuntimeCache {} +unsafe impl Sync for RuntimeCache {} -impl std::fmt::Debug for RuntimeCache<'_> { +impl std::fmt::Debug for RuntimeCache { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("RuntimeCache") .field("inner", &format!("{:x}", self.inner.as_ptr() as usize)) @@ -31,7 +28,7 @@ impl std::fmt::Debug for RuntimeCache<'_> { } } -impl<'engine> RuntimeCache<'engine> { +impl RuntimeCache { pub(crate) fn new(cache: *mut nvinfer1::IRuntimeCache) -> Result { #[cfg(not(feature = "mock"))] if cache.is_null() { @@ -39,12 +36,11 @@ impl<'engine> RuntimeCache<'engine> { } Ok(Self { inner: unsafe { UniquePtr::from_raw(cache) }, - _engine: Default::default(), }) } /// See [IRuntimeCache::serialize]. - pub fn serialize(&self) -> Result> { + pub fn serialize(&self) -> Result> { #[cfg(not(feature = "mock"))] { let host_mem = unsafe { self.inner.serialize().as_mut() } diff --git a/trtx/src/runtime_config.rs b/trtx/src/runtime_config.rs index b143d7a..e2a8a2d 100644 --- a/trtx/src/runtime_config.rs +++ b/trtx/src/runtime_config.rs @@ -27,8 +27,8 @@ pub struct RuntimeConfig<'engine> { // this also makes it safe when we modify through our mutex, while cpp calls are made through // IExecution calls #[cfg(not(feature = "enterprise"))] - _cache: Option>>>, // Mutex, could now be removed with a - // breaking change to set_runtime_cache + _cache: Option>>, // Mutex, could now be removed with a + // breaking change to set_runtime_cache } impl std::fmt::Debug for RuntimeConfig<'_> { @@ -83,7 +83,7 @@ impl<'engine> RuntimeConfig<'engine> { #[cfg(not(feature = "enterprise"))] /// See [IRuntimeConfig::createRuntimeCache]. - pub fn create_runtime_cache(&self) -> Result> { + pub fn create_runtime_cache(&self) -> Result { #[cfg(not(feature = "mock"))] let cache_ptr = self.inner.createRuntimeCache(); #[cfg(feature = "mock")] @@ -93,7 +93,7 @@ impl<'engine> RuntimeConfig<'engine> { #[cfg(not(feature = "enterprise"))] /// See [IRuntimeConfig::setRuntimeCache]. - pub fn set_runtime_cache(&mut self, cache: Arc>>) -> Result<()> { + pub fn set_runtime_cache(&mut self, cache: Arc>) -> Result<()> { if cfg!(not(feature = "mock")) { if self.inner.pin_mut().setRuntimeCache( cache