-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Speed up incremental build #1682
Open
matthiasgoergens
wants to merge
16
commits into
main
Choose a base branch
from
matthias/speed-up-cli-compiling
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
882a88b
Separate out clap derive stuff
matthiasgoergens 15f8e10
Clean up
matthiasgoergens 6bda1ad
Move stuff
matthiasgoergens 6399fec
Move benchs
matthiasgoergens 0caf013
Make clippy happy
matthiasgoergens bd87dc6
Merge remote-tracking branch 'origin/main' into matthias/speed-up-cli…
matthiasgoergens 9748451
CLean up
matthiasgoergens 6b18afc
Slim down
matthiasgoergens dc923c5
Format
matthiasgoergens 7693224
Upgrade clio
matthiasgoergens 9604a44
Shuffle tests
matthiasgoergens 4c81c6a
Restore test
matthiasgoergens 19c59c6
Read at runtime
matthiasgoergens 57a4507
Read at compile time
matthiasgoergens 9d5253c
Clippy
matthiasgoergens ba18db8
Fix
matthiasgoergens File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
[workspace] | ||
exclude = ["sdk"] | ||
members = [ | ||
"args", | ||
"circuits", | ||
"cli", | ||
"examples-builder", | ||
|
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,23 @@ | ||
[package] | ||
categories = ["cryptography"] | ||
description = "MozakVM cli" | ||
edition = "2021" | ||
keywords = ["crypto", "zero-knowledge", "vm"] | ||
license = "All rights reserved" | ||
name = "mozak-cli-args" | ||
readme = "README.md" | ||
repository = "https://github.com/0xmozak/mozak-vm" | ||
version = "0.1.0" | ||
|
||
[dependencies] | ||
clap = { version = "4.5", features = [ | ||
"derive", | ||
"cargo", | ||
"env", | ||
"unicode", | ||
] } | ||
# TODO(Matthias): implement shell completion for CLI via clap_complete | ||
# clap_complete = "4.3" | ||
clap-verbosity-flag = "2.2" | ||
clap_derive = "4.5" | ||
clio = { version = "0.3", features = ["clap-parse"] } |
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,31 @@ | ||
use clap::{Args as Args_, Subcommand}; | ||
|
||
#[derive(Debug, Args_, Clone)] | ||
#[command(args_conflicts_with_subcommands = true)] | ||
pub struct BenchArgs { | ||
#[command(subcommand)] | ||
pub function: BenchFunction, | ||
} | ||
|
||
#[derive(PartialEq, Debug, Subcommand, Clone)] | ||
pub enum BenchFunction { | ||
XorBench { | ||
iterations: u32, | ||
}, | ||
NopBench { | ||
iterations: u32, | ||
}, | ||
Poseidon2Bench { | ||
input_len: u32, | ||
}, | ||
/// Benchmarks (almost) every instruction. | ||
OmniBench { | ||
iterations: u32, | ||
}, | ||
SortBench { | ||
n: u32, | ||
}, | ||
SortBenchRecursive { | ||
n: u32, | ||
}, | ||
} |
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,76 @@ | ||
#![deny(clippy::pedantic)] | ||
#![deny(clippy::cargo)] | ||
#![allow(clippy::multiple_crate_versions)] | ||
pub mod bench_args; | ||
|
||
use bench_args::BenchArgs; | ||
use clap::{Parser, Subcommand}; | ||
use clap_derive::Args; | ||
use clio::{Input, Output}; | ||
|
||
#[derive(Parser, Debug, Clone)] | ||
#[command(author, version, about, long_about = None)] | ||
pub struct Cli { | ||
#[clap(flatten)] | ||
pub verbose: clap_verbosity_flag::Verbosity, | ||
#[command(subcommand)] | ||
pub command: Command, | ||
/// Debug API, default is OFF, currently only `prove` command is supported | ||
#[arg(short, long)] | ||
pub debug: bool, | ||
} | ||
|
||
#[derive(Clone, Debug, Args)] | ||
pub struct RunArgs { | ||
pub elf: Input, | ||
#[arg(long)] | ||
pub system_tape: Option<Input>, | ||
#[arg(long)] | ||
pub self_prog_id: Option<String>, | ||
} | ||
|
||
#[derive(Clone, Debug, Args)] | ||
pub struct ProveArgs { | ||
pub elf: Input, | ||
pub proof: Output, | ||
#[arg(long)] | ||
pub system_tape: Option<Input>, | ||
#[arg(long)] | ||
pub self_prog_id: Option<String>, | ||
pub recursive_proof: Option<Output>, | ||
} | ||
|
||
#[derive(Clone, Debug, Subcommand)] | ||
pub enum Command { | ||
/// Decode a given ELF and prints the program | ||
Decode { elf: Input }, | ||
/// Decode and execute a given ELF. Prints the final state of | ||
/// the registers | ||
Run(RunArgs), | ||
/// Prove and verify the execution of a given ELF | ||
ProveAndVerify(RunArgs), | ||
/// Prove the execution of given ELF and write proof to file. | ||
Prove(ProveArgs), | ||
/// Verify the given proof from file. | ||
Verify { proof: Input }, | ||
/// Verify the given recursive proof from file. | ||
VerifyRecursiveProof { proof: Input, verifier_key: Input }, | ||
/// Builds a transaction bundle. | ||
BundleTransaction { | ||
/// System tape generated from native execution. | ||
#[arg(long, required = true)] | ||
system_tape: Input, | ||
/// Output file path of the serialized bundle. | ||
#[arg(long, default_value = "bundle")] | ||
bundle: Output, | ||
}, | ||
/// Compute the Program Rom Hash of the given ELF. | ||
ProgramRomHash { elf: Input }, | ||
/// Compute the Memory Init Hash of the given ELF. | ||
MemoryInitHash { elf: Input }, | ||
/// Bench the function with given parameters | ||
Bench(BenchArgs), | ||
} | ||
|
||
#[allow(non_upper_case_globals)] | ||
pub const parse: fn() -> Cli = Cli::parse; |
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,47 @@ | ||
pub mod nop; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file moved here from the CLI. |
||
pub mod omni; | ||
pub mod poseidon2; | ||
pub mod sort; | ||
pub mod xor; | ||
|
||
use std::time::Duration; | ||
|
||
use anyhow::Result; | ||
pub use mozak_cli_args::bench_args::{BenchArgs, BenchFunction}; | ||
use nop::NopBench; | ||
use omni::OmniBench; | ||
use poseidon2::Poseidon2Bench; | ||
use sort::{SortBench, SortBenchRecursive}; | ||
use xor::XorBench; | ||
|
||
pub(crate) trait Bench { | ||
type Args; | ||
type Prepared; | ||
|
||
/// method to be executed to prepare the benchmark | ||
fn prepare(&self, args: &Self::Args) -> Self::Prepared; | ||
|
||
/// actual benchmark function, whose execution time is | ||
/// to be measured | ||
fn execute(&self, prepared: Self::Prepared) -> Result<()>; | ||
|
||
/// benchmark the `execute` function implemented through the | ||
/// trait `Bench` | ||
fn bench(&self, args: &Self::Args) -> Result<Duration> { | ||
let prepared = self.prepare(args); | ||
let start = std::time::Instant::now(); | ||
self.execute(prepared)?; | ||
Ok(start.elapsed()) | ||
} | ||
} | ||
|
||
pub fn bench(args: &BenchArgs) -> Result<Duration> { | ||
match &args.function { | ||
BenchFunction::XorBench { iterations } => XorBench.bench(iterations), | ||
BenchFunction::NopBench { iterations } => NopBench.bench(iterations), | ||
BenchFunction::OmniBench { iterations } => OmniBench.bench(iterations), | ||
BenchFunction::Poseidon2Bench { input_len } => Poseidon2Bench.bench(input_len), | ||
BenchFunction::SortBench { n } => SortBench.bench(n), | ||
BenchFunction::SortBenchRecursive { n } => SortBenchRecursive.bench(n), | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm all for improving compilation speed but seems like this comes at the cost of reordering our CLI logic in a somewhat confusing manner, I'm not sure if args should belong outside of the cli.