-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add compile time flags to disable rayon (#240)
* maybe-rayon package * refactor code * remove rayon from dep * fix features * remove default * conditionally compile the DasContext constructor * use multithread and singlethreaded * turn on multithreading for c_kzg * add feature flags
- Loading branch information
1 parent
c00bbe0
commit d472d60
Showing
15 changed files
with
202 additions
and
23 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
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
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
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
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,13 @@ | ||
#[macro_export] | ||
macro_rules! with_optional_threadpool { | ||
($self:expr, $body:expr) => {{ | ||
#[cfg(feature = "multithreaded")] | ||
{ | ||
$self.thread_pool.install(|| $body) | ||
} | ||
#[cfg(not(feature = "multithreaded"))] | ||
{ | ||
$body | ||
} | ||
}}; | ||
} |
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
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,15 @@ | ||
[package] | ||
name = "crate_crypto_internal_eth_kzg_maybe_rayon" | ||
description = "This crate provides an implementation of a wrapper around the rayon crate" | ||
version = { workspace = true } | ||
authors = { workspace = true } | ||
edition = { workspace = true } | ||
license = { workspace = true } | ||
rust-version = { workspace = true } | ||
repository = { workspace = true } | ||
|
||
[dependencies] | ||
rayon = { workspace = true, optional = true } | ||
|
||
[features] | ||
multithreaded = ["rayon"] |
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,17 @@ | ||
#[cfg(feature = "multithreaded")] | ||
mod multi_threaded; | ||
#[cfg(not(feature = "multithreaded"))] | ||
mod single_threaded; | ||
|
||
#[cfg(feature = "multithreaded")] | ||
pub use multi_threaded::*; | ||
#[cfg(not(feature = "multithreaded"))] | ||
pub use single_threaded::*; | ||
|
||
pub mod prelude { | ||
pub use crate::MaybeParallelRefExt; | ||
pub use crate::MaybeParallelRefMutExt; | ||
pub use crate::*; | ||
#[cfg(feature = "multithreaded")] | ||
pub use rayon::prelude::*; | ||
} |
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,29 @@ | ||
pub use rayon::iter::IntoParallelIterator; | ||
pub use rayon::iter::IntoParallelRefIterator; | ||
pub use rayon::iter::IntoParallelRefMutIterator; | ||
pub use rayon::iter::ParallelIterator; | ||
|
||
pub trait MaybeParallelExt: IntoParallelIterator { | ||
fn maybe_into_par_iter(self) -> <Self as IntoParallelIterator>::Iter | ||
where | ||
Self: Sized, | ||
{ | ||
self.into_par_iter() | ||
} | ||
} | ||
|
||
pub trait MaybeParallelRefExt: for<'a> IntoParallelRefIterator<'a> { | ||
fn maybe_par_iter(&self) -> <Self as IntoParallelRefIterator>::Iter { | ||
self.par_iter() | ||
} | ||
} | ||
|
||
pub trait MaybeParallelRefMutExt: for<'a> IntoParallelRefMutIterator<'a> { | ||
fn maybe_par_iter_mut(&mut self) -> <Self as IntoParallelRefMutIterator>::Iter { | ||
self.par_iter_mut() | ||
} | ||
} | ||
|
||
impl<T: IntoParallelIterator> MaybeParallelExt for T {} | ||
impl<T: for<'a> IntoParallelRefIterator<'a>> MaybeParallelRefExt for T {} | ||
impl<T: for<'a> IntoParallelRefMutIterator<'a>> MaybeParallelRefMutExt for T {} |
Oops, something went wrong.