Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEAT: Implement generic parallel collect
Allow non-copy elements by implementing dropping partial results from collect (needed if there is a panic with unwinding during the apply-collect process). It is implemented by: 1. allocate an uninit output array of the right size and layout 2. use parallelsplits to split the Zip into chunks processed in parallel 3. for each chunk keep track of the slice of written elements 4. each output chunk is contiguous due to the layout being picked to match the Zip's preferred layout 5. Use reduce to merge adjacent partial results; this ensures we drop all the rests correctly, if there is a panic in any thread
- Loading branch information
Showing
3 changed files
with
204 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,4 +157,5 @@ pub use crate::par_azip; | |
mod impl_par_methods; | ||
mod into_impls; | ||
mod par; | ||
mod send_producer; | ||
mod zipmacro; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
|
||
use crate::imp_prelude::*; | ||
use crate::{Layout, NdProducer}; | ||
use std::ops::{Deref, DerefMut}; | ||
|
||
/// An NdProducer that is unconditionally `Send`. | ||
#[repr(transparent)] | ||
pub(crate) struct SendProducer<T> { | ||
inner: T | ||
} | ||
|
||
impl<T> SendProducer<T> { | ||
/// Create an unconditionally `Send` ndproducer from the producer | ||
pub(crate) unsafe fn new(producer: T) -> Self { Self { inner: producer } } | ||
} | ||
|
||
unsafe impl<P> Send for SendProducer<P> { } | ||
|
||
impl<P> Deref for SendProducer<P> { | ||
type Target = P; | ||
fn deref(&self) -> &P { &self.inner } | ||
} | ||
|
||
impl<P> DerefMut for SendProducer<P> { | ||
fn deref_mut(&mut self) -> &mut P { &mut self.inner } | ||
} | ||
|
||
impl<P: NdProducer> NdProducer for SendProducer<P> | ||
where P: NdProducer, | ||
{ | ||
type Item = P::Item; | ||
type Dim = P::Dim; | ||
type Ptr = P::Ptr; | ||
type Stride = P::Stride; | ||
|
||
private_impl! {} | ||
|
||
#[inline(always)] | ||
fn raw_dim(&self) -> Self::Dim { | ||
self.inner.raw_dim() | ||
} | ||
|
||
#[inline(always)] | ||
fn equal_dim(&self, dim: &Self::Dim) -> bool { | ||
self.inner.equal_dim(dim) | ||
} | ||
|
||
#[inline(always)] | ||
fn as_ptr(&self) -> Self::Ptr { | ||
self.inner.as_ptr() | ||
} | ||
|
||
#[inline(always)] | ||
fn layout(&self) -> Layout { | ||
self.inner.layout() | ||
} | ||
|
||
#[inline(always)] | ||
unsafe fn as_ref(&self, ptr: Self::Ptr) -> Self::Item { | ||
self.inner.as_ref(ptr) | ||
} | ||
|
||
#[inline(always)] | ||
unsafe fn uget_ptr(&self, i: &Self::Dim) -> Self::Ptr { | ||
self.inner.uget_ptr(i) | ||
} | ||
|
||
#[inline(always)] | ||
fn stride_of(&self, axis: Axis) -> Self::Stride { | ||
self.inner.stride_of(axis) | ||
} | ||
|
||
#[inline(always)] | ||
fn contiguous_stride(&self) -> Self::Stride { | ||
self.inner.contiguous_stride() | ||
} | ||
|
||
fn split_at(self, axis: Axis, index: usize) -> (Self, Self) { | ||
let (a, b) = self.inner.split_at(axis, index); | ||
(Self { inner: a }, Self { inner: b }) | ||
} | ||
} | ||
|