Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion trtx/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use crate::error::{Error, Result};
use crate::host_memory::HostMemory;
use crate::interfaces::{ErrorRecorder, RecordError};
use crate::interfaces::{ErrorRecorder, GpuAllocator, RecordError};
use crate::logger::Logger;
use crate::network::NetworkDefinition;
use crate::optimization_profile::OptimizationProfile;
Expand Down Expand Up @@ -35,6 +35,7 @@ pub struct Builder<'a> {
inner: UniquePtr<IBuilder>,
_logger: PhantomData<&'a Logger>,
error_recorder: Option<Pin<Box<ErrorRecorder>>>,
gpu_allocator: Option<Pin<Box<GpuAllocator>>>,
}

impl std::fmt::Debug for Builder<'_> {
Expand Down Expand Up @@ -100,13 +101,15 @@ impl<'builder> Builder<'builder> {
inner: unsafe { UniquePtr::from_raw(builder_ptr) },
error_recorder: None,
_logger: Default::default(),
gpu_allocator: None,
})
}
#[cfg(feature = "mock")]
Ok(Builder {
inner: UniquePtr::null(),
_logger: Default::default(),
error_recorder: None,
gpu_allocator: None,
})
}

Expand Down Expand Up @@ -198,4 +201,17 @@ impl<'builder> Builder<'builder> {
};
Ok(())
}

/// See [IBuilder::setGpuAllocator]
pub fn set_gpu_allocator(&mut self, allocator: Pin<Box<GpuAllocator>>) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could also change that together with the runtime to Box<dyn AllocateGpu> or Arc<dyn AllocateGpu>

#[cfg(not(feature = "mock_runtime"))]
// SAFETY: `GpuAllocator` owns the C++ allocator bridge, and storing it below
// keeps that bridge valid for the complete lifetime of this builder.
unsafe {
self.inner
.pin_mut()
.setGpuAllocator(allocator.as_ref().get_ref().as_trt_gpu_allocator());
}
self.gpu_allocator = Some(allocator);
}
}
Loading