Don't use pinned memory when unnecessary (#17832)

Reports of excessive GPU memory usage and errors
from cudaHostRegister. There are some cases where pinning is
not required.
This commit is contained in:
sakridge
2021-06-14 16:10:04 +02:00
committed by GitHub
parent d4cc975fe9
commit eeee75c5be
10 changed files with 47 additions and 7 deletions

View File

@ -146,6 +146,10 @@ impl<'a, T: Clone + Send + Sync + Default + Sized> IntoParallelIterator for &'a
}
impl<T: Clone + Default + Sized> PinnedVec<T> {
pub fn reserve(&mut self, size: usize) {
self.x.reserve(size);
}
pub fn reserve_and_pin(&mut self, size: usize) {
if self.x.capacity() < size {
if self.pinned {

View File

@ -28,11 +28,22 @@ impl Packets {
Packets { packets }
}
pub fn new_unpinned_with_recycler(
recycler: PacketsRecycler,
size: usize,
name: &'static str,
) -> Self {
let mut packets = recycler.allocate(name);
packets.reserve(size);
Packets { packets }
}
pub fn new_with_recycler(recycler: PacketsRecycler, size: usize, name: &'static str) -> Self {
let mut packets = recycler.allocate(name);
packets.reserve_and_pin(size);
Packets { packets }
}
pub fn new_with_recycler_data(
recycler: &PacketsRecycler,
name: &'static str,
@ -43,6 +54,16 @@ impl Packets {
vec
}
pub fn new_unpinned_with_recycler_data(
recycler: &PacketsRecycler,
name: &'static str,
mut packets: Vec<Packet>,
) -> Self {
let mut vec = Self::new_unpinned_with_recycler(recycler.clone(), packets.len(), name);
vec.packets.append(&mut packets);
vec
}
pub fn set_addr(&mut self, addr: &SocketAddr) {
for m in self.packets.iter_mut() {
m.meta.set_addr(&addr);
@ -76,7 +97,7 @@ pub fn to_packets_with_destination<T: Serialize>(
recycler: PacketsRecycler,
dests_and_data: &[(SocketAddr, T)],
) -> Packets {
let mut out = Packets::new_with_recycler(
let mut out = Packets::new_unpinned_with_recycler(
recycler,
dests_and_data.len(),
"to_packets_with_destination",