diff --git a/Cargo.lock b/Cargo.lock index ace9092ae..a08b91b94 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -117,6 +117,17 @@ dependencies = [ "stable_deref_trait", ] +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi 0.1.19", + "libc", + "winapi", +] + [[package]] name = "autocfg" version = "1.2.0" @@ -135,6 +146,41 @@ dependencies = [ "serde", ] +[[package]] +name = "bindgen" +version = "0.69.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0" +dependencies = [ + "bitflags 2.6.0", + "cexpr", + "clang-sys", + "itertools 0.10.5", + "lazy_static", + "lazycell", + "log", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn 2.0.60", + "which", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + [[package]] name = "blake2" version = "0.10.6" @@ -204,6 +250,15 @@ version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d32a725bc159af97c3e629873bb9f88fb8cf8a4867175f76dc987815ea07c83b" +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + [[package]] name = "cfg-if" version = "1.0.0" @@ -234,7 +289,29 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9" dependencies = [ "ciborium-io", - "half", + "half 2.4.1", +] + +[[package]] +name = "clang-sys" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" +dependencies = [ + "glob", + "libc", + "libloading", +] + +[[package]] +name = "clap" +version = "2.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" +dependencies = [ + "bitflags 1.3.2", + "textwrap", + "unicode-width", ] [[package]] @@ -262,6 +339,15 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" +[[package]] +name = "cmake" +version = "0.1.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31c789563b815f77f4250caee12365734369f942439b7defd71e18a48197130" +dependencies = [ + "cc", +] + [[package]] name = "constant_time_eq" version = "0.3.0" @@ -277,6 +363,32 @@ dependencies = [ "libc", ] +[[package]] +name = "criterion" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b01d6de93b2b6c65e17c634a26653a29d107b3c98c607c765bf38d041531cd8f" +dependencies = [ + "atty", + "cast", + "clap 2.34.0", + "criterion-plot 0.4.5", + "csv", + "itertools 0.10.5", + "lazy_static", + "num-traits", + "oorandom", + "plotters", + "rayon", + "regex", + "serde", + "serde_cbor", + "serde_derive", + "serde_json", + "tinytemplate", + "walkdir", +] + [[package]] name = "criterion" version = "0.5.1" @@ -286,8 +398,8 @@ dependencies = [ "anes", "cast", "ciborium", - "clap", - "criterion-plot", + "clap 4.5.4", + "criterion-plot 0.5.0", "is-terminal", "itertools 0.10.5", "num-traits", @@ -303,6 +415,16 @@ dependencies = [ "walkdir", ] +[[package]] +name = "criterion-plot" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2673cc8207403546f45f5fd319a974b1e6983ad1a3ee7e6041650013be041876" +dependencies = [ + "cast", + "itertools 0.10.5", +] + [[package]] name = "criterion-plot" version = "0.5.0" @@ -365,6 +487,27 @@ dependencies = [ "typenum", ] +[[package]] +name = "csv" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac574ff4d437a7b5ad237ef331c17ccca63c46479e5b5453eb8e10bb99a759fe" +dependencies = [ + "csv-core", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "csv-core" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5efa2b3d7902f4b634a20cae3c9c4e6209dc4779feb6863329607560143efa70" +dependencies = [ + "memchr", +] + [[package]] name = "derivative" version = "2.2.0" @@ -450,6 +593,16 @@ dependencies = [ "log", ] +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys", +] + [[package]] name = "generic-array" version = "0.14.7" @@ -473,6 +626,18 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + +[[package]] +name = "half" +version = "1.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b43ede17f21864e81be2fa654110bf1e793774238d86ef8555c37e6519c0403" + [[package]] name = "half" version = "2.4.1" @@ -483,6 +648,15 @@ dependencies = [ "crunchy", ] +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + [[package]] name = "hermit-abi" version = "0.3.9" @@ -504,13 +678,52 @@ dependencies = [ "digest", ] +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "icicle-core" +version = "2.7.1" +source = "git+https://github.com/ingonyama-zk/icicle.git#ea71faf1fa1e4095f7d2b77aa88d3562aeaf103b" +dependencies = [ + "criterion 0.3.6", + "hex", + "icicle-cuda-runtime", + "rayon", +] + +[[package]] +name = "icicle-cuda-runtime" +version = "2.7.1" +source = "git+https://github.com/ingonyama-zk/icicle.git#ea71faf1fa1e4095f7d2b77aa88d3562aeaf103b" +dependencies = [ + "bindgen", + "bitflags 1.3.2", +] + +[[package]] +name = "icicle-m31" +version = "2.7.1" +source = "git+https://github.com/ingonyama-zk/icicle.git#ea71faf1fa1e4095f7d2b77aa88d3562aeaf103b" +dependencies = [ + "cmake", + "icicle-core", + "icicle-cuda-runtime", +] + [[package]] name = "is-terminal" version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b" dependencies = [ - "hermit-abi", + "hermit-abi 0.3.9", "libc", "windows-sys", ] @@ -554,12 +767,34 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + [[package]] name = "libc" version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +[[package]] +name = "libloading" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e310b3a6b5907f99202fcdb4960ff45b93735d7c7d96b760fcff8db2dc0e103d" +dependencies = [ + "cfg-if", + "windows-targets", +] + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + [[package]] name = "log" version = "0.4.21" @@ -581,6 +816,22 @@ version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -683,6 +934,16 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +[[package]] +name = "prettyplease" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e" +dependencies = [ + "proc-macro2", + "syn 2.0.60", +] + [[package]] name = "proc-macro2" version = "1.0.81" @@ -801,6 +1062,12 @@ dependencies = [ "subtle", ] +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + [[package]] name = "rustc_version" version = "0.4.0" @@ -810,6 +1077,19 @@ dependencies = [ "semver", ] +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags 2.6.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + [[package]] name = "ryu" version = "1.0.17" @@ -840,6 +1120,16 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde_cbor" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bef2ebfde456fb76bbcf9f59315333decc4fda0b2b44b420243c11e0f5ec1f5" +dependencies = [ + "half 1.8.3", + "serde", +] + [[package]] name = "serde_derive" version = "1.0.198" @@ -882,6 +1172,12 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "smallvec" version = "1.13.2" @@ -957,10 +1253,13 @@ dependencies = [ "blake3", "bytemuck", "cfg-if", - "criterion", + "criterion 0.5.1", "downcast-rs", "educe", "hex", + "icicle-core", + "icicle-cuda-runtime", + "icicle-m31", "itertools 0.12.1", "num-traits", "rand", @@ -1023,20 +1322,29 @@ dependencies = [ "syn 2.0.60", ] +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +dependencies = [ + "unicode-width", +] + [[package]] name = "thiserror" -version = "1.0.59" +version = "1.0.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa" +checksum = "f2675633b1499176c2dff06b0856a27976a8f9d436737b4cf4f312d4d91d8bbb" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.59" +version = "1.0.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66" +checksum = "d20468752b09f49e909e55a5d338caa8bedf615594e9d80bc4c565d30faf798c" dependencies = [ "proc-macro2", "quote", @@ -1136,6 +1444,12 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unicode-width" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" + [[package]] name = "valuable" version = "0.1.0" @@ -1228,6 +1542,18 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "which" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" +dependencies = [ + "either", + "home", + "once_cell", + "rustix", +] + [[package]] name = "winapi" version = "0.3.9" diff --git a/crates/prover/Cargo.toml b/crates/prover/Cargo.toml index 3c9de2969..74880aeed 100644 --- a/crates/prover/Cargo.toml +++ b/crates/prover/Cargo.toml @@ -25,6 +25,10 @@ thiserror.workspace = true tracing.workspace = true rayon = { version = "1.10.0", optional = true } +icicle-cuda-runtime = { git="https://github.com/ingonyama-zk/icicle.git" } +icicle-core = { git="https://github.com/ingonyama-zk/icicle.git" } +icicle-m31 = { git="https://github.com/ingonyama-zk/icicle.git" } + [dev-dependencies] aligned = "0.4.2" test-log = { version = "0.2.15", features = ["trace"] } @@ -41,6 +45,7 @@ default-features = false features = ["html_reports"] version = "0.5.1" + [lib] bench = false diff --git a/crates/prover/src/core/backend/cpu/accumulation.rs b/crates/prover/src/core/backend/cpu/accumulation.rs index 9c3580f5b..59460282e 100644 --- a/crates/prover/src/core/backend/cpu/accumulation.rs +++ b/crates/prover/src/core/backend/cpu/accumulation.rs @@ -4,9 +4,45 @@ use crate::core::fields::secure_column::SecureColumn; impl AccumulationOps for CpuBackend { fn accumulate(column: &mut SecureColumn, other: &SecureColumn) { - for i in 0..column.len() { - let res_coeff = column.at(i) + other.at(i); - column.set(i, res_coeff); + use std::mem::transmute; + + use icicle_core::vec_ops::{accumulate_scalars, VecOpsConfig}; + use icicle_cuda_runtime::memory::HostSlice; + use icicle_m31::field::ExtensionField; + + use crate::core::SecureField; + + let mut a: Vec = vec![]; + let mut b: Vec = vec![]; + let len = column.len(); + for i in 0..len { + // TODO: just for the sake of correctness check - perf optimisation can be done without + // data conversion + let ci = column.at(i); + let oi = other.at(i); + + let aa = ci.to_m31_array(); + let bb = oi.to_m31_array(); + + let aa: ExtensionField = unsafe { transmute(aa) }; + let bb: ExtensionField = unsafe { transmute(bb) }; + + a.push(aa); + b.push(bb); } + + let a = HostSlice::from_mut_slice(&mut a); + let b = HostSlice::from_slice(&b); + + let cfg = VecOpsConfig::default(); + + accumulate_scalars(a, b, &cfg).unwrap(); + + a.iter().enumerate().for_each(|(i, &item)| { + column.set( + i, + SecureField::from_m31_array(unsafe { std::mem::transmute(item) }), + ) + }); } } diff --git a/crates/prover/src/core/backend/simd/bit_reverse.rs b/crates/prover/src/core/backend/simd/bit_reverse.rs index cedf56839..79ebe09f8 100644 --- a/crates/prover/src/core/backend/simd/bit_reverse.rs +++ b/crates/prover/src/core/backend/simd/bit_reverse.rs @@ -191,13 +191,39 @@ mod tests { #[test] fn bit_reverse_large_column_works() { const LOG_SIZE: u32 = MIN_LOG_SIZE; - let column = (0..1 << LOG_SIZE).map(BaseField::from).collect_vec(); + const TEST_SIZE: usize = 1 << LOG_SIZE; + let column = (0..TEST_SIZE).map(BaseField::from).collect_vec(); let mut expected = column.clone(); cpu_bit_reverse(&mut expected); + use std::mem::transmute; + + use icicle_core::vec_ops::{ + bit_reverse, bit_reverse_inplace, BitReverseConfig, VecOps, VecOpsConfig, + }; + use icicle_cuda_runtime::memory::{DeviceVec, HostSlice}; + use icicle_m31::field::ScalarField; + + let mut input_vec: Vec = vec![]; + for i in 0..TEST_SIZE { + // TODO: just for the sake of correctness check - perf optimisation can be done without + // data conversion + input_vec.push(unsafe { transmute(column[i]) }); + } + + let input = HostSlice::from_mut_slice(&mut input_vec); + let cfg = BitReverseConfig::default(); + bit_reverse_inplace(input, &cfg).unwrap(); + + let mut a: Vec = vec![]; + for i in 0..TEST_SIZE { + a.push(unsafe { transmute(input_vec[i]) }); + } + let mut res = column.iter().copied().collect::(); >::bit_reverse_column(&mut res); assert_eq!(res.to_cpu(), expected); + assert_eq!(a, expected); } } diff --git a/crates/prover/src/lib.rs b/crates/prover/src/lib.rs index 6c9ddaa02..268c49ad4 100644 --- a/crates/prover/src/lib.rs +++ b/crates/prover/src/lib.rs @@ -1,3 +1,4 @@ +#![allow(warnings)] #![feature( array_chunks, iter_array_chunks, @@ -13,7 +14,12 @@ portable_simd )] pub mod constraint_framework; + +#[allow(unused)] pub mod core; +#[allow(warnings)] pub mod examples; +#[allow(warnings)] pub mod math; +#[allow(warnings)] pub mod trace_generation;