Skip to content

Commit 009a61f

Browse files
hero78119lispc
andauthored
WIP refactor #799 (#952)
### Change scope - [x] unify `Expression` with ceno - [x] unify sumcheck with ceno - [ ] WIP GKR witness generation, take bit benchmark as example --------- Co-authored-by: Zhang Zhuo <[email protected]>
1 parent 24a43b4 commit 009a61f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+2382
-4250
lines changed

.github/workflows/integration.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,11 @@ jobs:
5858
env:
5959
RUSTFLAGS: "-C opt-level=3"
6060
run: cargo run --release --package ceno_zkvm --bin e2e -- --platform=ceno --hints=10 --public-io=4191 examples/target/riscv32im-ceno-zkvm-elf/release/examples/fibonacci
61+
62+
- name: Install cargo make
63+
run: |
64+
cargo make --version || cargo install cargo-make
65+
66+
- name: Test install Ceno cli
67+
run: |
68+
cargo make cli

.github/workflows/lints.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ jobs:
4343
- name: Install cargo make
4444
run: |
4545
cargo make --version || cargo install cargo-make
46+
4647
- name: Check code format
4748
run: cargo fmt --all --check
4849

Cargo.lock

Lines changed: 44 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ members = [
1212
"sumcheck_macro",
1313
"poseidon",
1414
"gkr_iop",
15-
"subprotocols",
1615
"sumcheck",
1716
"transcript",
1817
"whir",
@@ -75,9 +74,9 @@ serde = { version = "1.0", features = ["derive", "rc"] }
7574
serde_json = "1.0"
7675
strum = "0.26"
7776
strum_macros = "0.26"
78-
subprotocols = { path = "subprotocols" }
7977
substrate-bn = { version = "0.6.0" }
8078
sumcheck = { path = "sumcheck" }
79+
thiserror = "1" # do we need this?
8180
tiny-keccak = { version = "2.0.2", features = ["keccak"] }
8281
tracing = { version = "0.1", features = [
8382
"attributes",

Makefile.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,17 @@ args = [
3030
]
3131
command = "cargo"
3232
workspace = false
33+
34+
[tasks.cli]
35+
args = [
36+
"install",
37+
"--features",
38+
"jemalloc",
39+
"--features",
40+
"nightly-features",
41+
"--path",
42+
"./ceno_cli",
43+
]
44+
command = "cargo"
45+
env = { "JEMALLOC_SYS_WITH_MALLOC_CONF" = "retain:true,metadata_thp:always,thp:always,dirty_decay_ms:-1,muzzy_decay_ms:-1,abort_conf:true" }
46+
workspace = false

ceno_cli/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ tracing.workspace = true
2323
tracing-forest.workspace = true
2424
tracing-subscriber.workspace = true
2525

26+
[target.'cfg(unix)'.dependencies]
27+
tikv-jemallocator = { version = "0.6", optional = true }
28+
2629
ceno_emul = { path = "../ceno_emul" }
2730
ceno_host = { path = "../ceno_host" }
2831
ceno_zkvm = { path = "../ceno_zkvm" }
@@ -33,6 +36,8 @@ mpcs = { path = "../mpcs" }
3336
vergen-git2 = { version = "1", features = ["build", "cargo", "rustc", "emit_and_set"] }
3437

3538
[features]
39+
jemalloc = ["dep:tikv-jemallocator", "ceno_zkvm/jemalloc"]
40+
jemalloc-prof = ["jemalloc", "tikv-jemallocator?/profiling"]
3641
nightly-features = [
3742
"ceno_zkvm/nightly-features",
3843
"ff_ext/nightly-features",

ceno_cli/src/main.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
use crate::{commands::*, utils::*};
22
use anyhow::Context;
3+
#[cfg(all(feature = "jemalloc", unix, not(test)))]
4+
use ceno_zkvm::print_allocated_bytes;
35
use clap::{Args, Parser, Subcommand};
46

57
mod commands;
68
mod utils;
79

10+
// Use jemalloc as global allocator for performance
11+
#[cfg(all(feature = "jemalloc", unix, not(test)))]
12+
#[global_allocator]
13+
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
14+
815
const CENO_VERSION: &str = env!("CENO_VERSION");
916

1017
#[derive(Parser)]
@@ -86,4 +93,8 @@ fn main() {
8693
print_error(e);
8794
std::process::exit(1);
8895
}
96+
#[cfg(all(feature = "jemalloc", unix, not(test)))]
97+
{
98+
print_allocated_bytes();
99+
}
89100
}

ceno_zkvm/Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ rand_chacha.workspace = true
2424
rayon.workspace = true
2525
serde.workspace = true
2626
serde_json.workspace = true
27-
subprotocols.workspace = true
2827
sumcheck.workspace = true
2928
transcript = { path = "../transcript" }
3029
witness = { path = "../witness" }
@@ -51,6 +50,10 @@ tempfile = "3.14"
5150
thread_local = "1.1"
5251
tiny-keccak.workspace = true
5352

53+
[target.'cfg(unix)'.dependencies]
54+
tikv-jemalloc-ctl = { version = "0.6", features = ["stats"], optional = true }
55+
tikv-jemallocator = { version = "0.6", optional = true }
56+
5457
[dev-dependencies]
5558
cfg-if.workspace = true
5659
criterion.workspace = true
@@ -65,6 +68,8 @@ glob = "0.3"
6568
default = ["forbid_overflow"]
6669
flamegraph = ["pprof2/flamegraph", "pprof2/criterion"]
6770
forbid_overflow = []
71+
jemalloc = ["dep:tikv-jemallocator", "dep:tikv-jemalloc-ctl"]
72+
jemalloc-prof = ["jemalloc", "tikv-jemallocator?/profiling"]
6873
nightly-features = [
6974
"p3/nightly-features",
7075
"ff_ext/nightly-features",

ceno_zkvm/benches/alloc.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Use jemalloc as global allocator for performance
2+
#[cfg(all(feature = "jemalloc", unix))]
3+
#[global_allocator]
4+
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;

ceno_zkvm/benches/fibonacci.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use ceno_zkvm::{
77
e2e::{Checkpoint, Preset, run_e2e_with_checkpoint, setup_platform},
88
scheme::{constants::MAX_NUM_VARIABLES, verifier::ZKVMVerifier},
99
};
10+
mod alloc;
1011
use criterion::*;
1112

1213
use ff_ext::GoldilocksExt2;
@@ -31,7 +32,7 @@ fn setup() -> (Program, Platform) {
3132
let stack_size = 32768;
3233
let heap_size = 2097152;
3334
let pub_io_size = 16;
34-
let program = Program::load_elf(ceno_examples::fibonacci, u32::MAX).unwrap();
35+
let program = Program::load_elf(ceno_examples::guest_keccak, u32::MAX).unwrap();
3536
let platform = setup_platform(Preset::Ceno, &program, stack_size, heap_size, pub_io_size);
3637
(program, platform)
3738
}

ceno_zkvm/benches/fibonacci_witness.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use ceno_zkvm::{
77
e2e::{Checkpoint, Preset, run_e2e_with_checkpoint, setup_platform},
88
scheme::constants::MAX_NUM_VARIABLES,
99
};
10+
mod alloc;
1011
use criterion::*;
1112
use ff_ext::GoldilocksExt2;
1213
use mpcs::{BasefoldDefault, SecurityLevel};

ceno_zkvm/benches/is_prime.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use ceno_zkvm::{
77
e2e::{Checkpoint, Preset, run_e2e_with_checkpoint, setup_platform},
88
scheme::constants::MAX_NUM_VARIABLES,
99
};
10+
mod alloc;
1011
use criterion::*;
1112
use ff_ext::GoldilocksExt2;
1213
use mpcs::{BasefoldDefault, SecurityLevel};

ceno_zkvm/benches/quadratic_sorting.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use ceno_zkvm::{
77
e2e::{Checkpoint, Preset, run_e2e_with_checkpoint, setup_platform},
88
scheme::constants::MAX_NUM_VARIABLES,
99
};
10+
mod alloc;
1011
use criterion::*;
1112
use ff_ext::GoldilocksExt2;
1213
use mpcs::{BasefoldDefault, SecurityLevel};

ceno_zkvm/benches/riscv_add.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use ceno_zkvm::{
66
scheme::prover::ZKVMProver,
77
structs::{ZKVMConstraintSystem, ZKVMFixedTraces},
88
};
9+
mod alloc;
910
use criterion::*;
1011

1112
use ceno_zkvm::scheme::constants::MAX_NUM_VARIABLES;

ceno_zkvm/src/bin/e2e.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use ceno_emul::{IterAddresses, Platform, Program, WORD_SIZE, Word};
22
use ceno_host::{CenoStdin, memory_from_file};
3+
#[cfg(all(feature = "jemalloc", unix, not(test)))]
4+
use ceno_zkvm::print_allocated_bytes;
35
use ceno_zkvm::{
46
e2e::{
57
Checkpoint, FieldType, PcsKind, Preset, run_e2e_with_checkpoint, setup_platform,
@@ -26,6 +28,11 @@ use tracing_subscriber::{
2628
};
2729
use transcript::BasicTranscript as Transcript;
2830

31+
// Use jemalloc as global allocator for performance
32+
#[cfg(all(feature = "jemalloc", unix, not(test)))]
33+
#[global_allocator]
34+
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
35+
2936
fn parse_size(s: &str) -> Result<u32, parse_size::Error> {
3037
parse_size::Config::new()
3138
.with_binary()
@@ -272,6 +279,11 @@ fn main() {
272279
Checkpoint::PrepVerify, // FIXME: when whir and babybear is ready
273280
)
274281
}
282+
};
283+
284+
#[cfg(all(feature = "jemalloc", unix, not(test)))]
285+
{
286+
print_allocated_bytes();
275287
}
276288
}
277289

ceno_zkvm/src/instructions/riscv/dummy/dummy_ecall.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ impl<E: ExtensionField> GKRIOPInstruction<E> for LargeEcallDummy<E, KeccakSpec>
209209
})
210210
.collect_vec();
211211

212-
layout.phase1_witness(KeccakTrace { instances })
212+
layout.phase1_witness_group(KeccakTrace { instances })
213213
}
214214

215215
fn assign_instance_with_gkr_iop(

ceno_zkvm/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ pub mod stats;
2020
pub mod structs;
2121
mod uint;
2222
mod utils;
23+
#[cfg(all(feature = "jemalloc", unix, not(test)))]
24+
pub use utils::print_allocated_bytes;
2325
mod witness;
2426

2527
pub use structs::ROMType;

ceno_zkvm/src/scheme/mock_prover.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ impl<'a, E: ExtensionField + Hash> MockProver<E> {
530530
{
531531
let right = -right.as_ref();
532532

533-
let left_evaluated = wit_infer_by_expr(&[], wits_in, &[], pi, &challenge, left);
533+
let left_evaluated = wit_infer_by_expr(&[], wits_in, &[], pi, &challenge, &left);
534534
let left_evaluated = left_evaluated.get_base_field_vec();
535535

536536
let right_evaluated = wit_infer_by_expr(&[], wits_in, &[], pi, &challenge, &right);

0 commit comments

Comments
 (0)