Skip to content

Commit

Permalink
chore: make "parallel" is not default feature (#189)
Browse files Browse the repository at this point in the history
* chore: make "parallel" is not default feature

* fix: add parallel feature to recursion crate
  • Loading branch information
jonathanpwang authored Jul 24, 2024
1 parent e726acd commit cc02145
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ec2-on-demand.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:

- name: Run benchmark
run: |
RUSTFLAGS="-Ctarget-cpu=native" cargo run --release --bin benchmark -- rw -r 90 -w 10
RUSTFLAGS="-Ctarget-cpu=native" cargo run --release --bin benchmark --features parallel -- rw -r 90 -w 10
- name: Copy output CSVs to S3
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/recursion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ jobs:
- name: Run recursion crate tests
working-directory: recursion
run: |
cargo test --profile=fast
cargo test --profile=fast --features parallel
2 changes: 1 addition & 1 deletion .github/workflows/stark-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
- name: Run tests
working-directory: stark-backend
run: |
cargo test
cargo test --features parallel
4 changes: 2 additions & 2 deletions .github/workflows/vm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ jobs:
- name: Run vm crate tests
working-directory: vm
run: |
cargo test --profile=fast
cargo test --profile=fast --features parallel
- name: Run compiler crate tests
working-directory: vm
run: |
cargo test --profile=fast
cargo test --profile=fast --features parallel
2 changes: 1 addition & 1 deletion benchmark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ tracing-appender = "0.2.3"
regex = "1.10.5"

[features]
default = ["parallel"]
default = []
parallel = ["afs/parallel", "olap/parallel"]
2 changes: 1 addition & 1 deletion bin/afs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ tracing-subscriber = { version = "0.3.17", features = ["std", "env-filter"] }
tracing-forest = { version = "0.1.6", features = ["ansi", "smallvec"] }

[features]
default = ["parallel"]
default = []
parallel = ["afs-chips/parallel"]
2 changes: 1 addition & 1 deletion bin/olap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ p3-keccak = { workspace = true }
tracing = "0.1.40"

[features]
default = ["parallel"]
default = []
parallel = ["afs-chips/parallel"]
2 changes: 1 addition & 1 deletion chips/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ tracing-forest = { version = "0.1.6", features = ["ansi", "smallvec"] }
test-case = "3.3.1"

[features]
default = ["parallel"]
default = []
test-traits = ["p3-baby-bear"] # traits for testing
parallel = ["afs-stark-backend/parallel"]
3 changes: 3 additions & 0 deletions chips/src/page_rw_checker/offline_checker/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ impl PageOfflineChecker {
// Creating a timestamp bigger than all others
let max_clk = ops.iter().map(|op| op.clk).max().unwrap_or(0) + 1;

#[cfg(feature = "parallel")]
ops.par_sort_by_key(|op| (op.idx.clone(), op.clk));
#[cfg(not(feature = "parallel"))]
ops.sort_by_key(|op| (op.idx.clone(), op.clk));

let dummy_op = Operation {
idx: vec![0; self.offline_checker.idx_len],
Expand Down
2 changes: 1 addition & 1 deletion poseidon2-air/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ rand_xoshiro = "0.6.0"
ark-ff = { version = "^0.4.0", default-features = false }

[features]
default = ["parallel"]
default = []
parallel = ["afs-stark-backend/parallel"]
4 changes: 4 additions & 0 deletions recursion/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ rand = "0.8.5"

[dev-dependencies]
afs-chips = { path = "../chips" }

[features]
default = []
parallel = ["afs-stark-backend/parallel"]
2 changes: 1 addition & 1 deletion stark-backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ csv = "1.3.0"
eyre = "0.6.12"

[features]
default = ["parallel"]
default = []
parallel = ["p3-maybe-rayon/parallel"]
5 changes: 5 additions & 0 deletions stark-backend/src/prover/quotient/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,15 @@ impl<'pcs, SC: StarkGenericConfig> QuotientCommitter<'pcs, SC> {
PcsProverData<SC>: Send + Sync,
Com<SC>: Send + Sync,
{
#[cfg(feature = "parallel")]
let inner = (raps, &pk.per_air, traces, public_values)
.into_par_iter() // uses rayon multizip
.map(|(rap, pk, trace, pis)| self.single_rap_quotient_values(rap, &pk.vk, trace, pis))
.collect();
#[cfg(not(feature = "parallel"))]
let inner = itertools::izip!(raps, &pk.per_air, traces, public_values)
.map(|(rap, pk, trace, pis)| self.single_rap_quotient_values(rap, &pk.vk, trace, pis))
.collect();
QuotientData { inner }
}

Expand Down
2 changes: 1 addition & 1 deletion vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ rand_xoshiro = "0.6.0"
ark-ff = { version = "^0.4.0", default-features = false }

[features]
default = ["parallel"]
default = []
parallel = ["afs-stark-backend/parallel"]
9 changes: 7 additions & 2 deletions vm/src/memory/offline_checker/trace.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use std::sync::Arc;

use afs_chips::offline_checker::OfflineCheckerChip;
use afs_chips::range_gate::RangeCheckerGateChip;
use p3_field::PrimeField32;
use p3_matrix::dense::RowMajorMatrix;
#[cfg(feature = "parallel")]
use p3_maybe_rayon::prelude::*;

use crate::memory::{MemoryAccess, OpType};

use super::MemoryChip;
use afs_chips::range_gate::RangeCheckerGateChip;
use p3_maybe_rayon::prelude::*;

impl<const WORD_SIZE: usize, F: PrimeField32> MemoryChip<WORD_SIZE, F> {
/// Each row in the trace follow the same order as the Cols struct:
Expand All @@ -22,8 +23,12 @@ impl<const WORD_SIZE: usize, F: PrimeField32> MemoryChip<WORD_SIZE, F> {
&mut self,
range_checker: Arc<RangeCheckerGateChip>,
) -> RowMajorMatrix<F> {
#[cfg(feature = "parallel")]
self.accesses
.par_sort_by_key(|op| (op.address_space, op.address, op.timestamp));
#[cfg(not(feature = "parallel"))]
self.accesses
.sort_by_key(|op| (op.address_space, op.address, op.timestamp));

let dummy_op = MemoryAccess {
timestamp: 0,
Expand Down

0 comments on commit cc02145

Please sign in to comment.