zkonduit / ezkl

ezkl is an engine for doing inference for deep learning models and other computational graphs in a zk-snark (ZKML). Use it from Python, Javascript, or the command line.
https://docs.ezkl.xyz/
949 stars 142 forks source link

[BUG]: ezkl running error when icicle_gpu features is enabled #804

Closed cherryicake closed 6 months ago

cherryicake commented 6 months ago

Describe the bug

When I enable icicle gpu support in ezkl, an InvalidContext error will appear during actual operation

Error stack

thread 'actix-rt|system:0|arbiter:0' panicked at /root/.cargo/git/checkouts/halo2-e0b23654a802914d/30f6fbf/halo2_proofs/src/icicle.rs:76:50: calledResult::unwrap()on anErrvalue: InvalidContext stack backtrace: 0: 0x556edf8ad3e6 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hfecca39b07c4fcbc 1: 0x556edf8dd400 - core::fmt::write::hac38076b2df535c3 2: 0x556edf8aa30f - std::io::Write::write_fmt::hc618f51de184ded7 3: 0x556edf8ad1c4 - std::sys_common::backtrace::print::h3d80365599e4186a 4: 0x556edf8aea47 - std::panicking::default_hook::{{closure}}::h8335850836899fff 5: 0x556edf8ae7a9 - std::panicking::default_hook::h44ae3592f8bdcad7 6: 0x556edf8aeed8 - std::panicking::rust_panic_with_hook::h91951ce8adb19a4d 7: 0x556edf8aedb2 - std::panicking::begin_panic_handler::{{closure}}::h5df637559c663cfa 8: 0x556edf8ad8e6 - std::sys_common::backtrace::__rust_end_short_backtrace::hef201df6e278e27a 9: 0x556edf8aeb04 - rust_begin_unwind 10: 0x556edeadfc55 - core::panicking::panic_fmt::hbedf0cc3d53692aa 11: 0x556edeae01a3 - core::result::unwrap_failed::hd07ab689ffa9b4ab 12: 0x556edebc4359 - halo2_proofs::icicle::copy_scalars_to_device::ha6e9554b354209d6 13: 0x556edebc4ec5 - <halo2_proofs::poly::kzg::commitment::ParamsKZG<E> as halo2_proofs::poly::commitment::Params<<E as pairing::Engine>::G1Affine>>::commit_lagrange::h31f1d50f1cf4aeda 14: 0x556edeb05b44 - <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter::h057fb6ef271aa722 15: 0x556ededb2080 - halo2_proofs::plonk::prover::create_proof::hdd609156c8a8915d 16: 0x556eded5a933 - ezkl::pfsys::create_proof_circuit::he9bd711cc9711e1f 17: 0x556ededa42c8 - <ezkl_worker::proof as actix_web::service::HttpServiceFactory>::register::proof::{{closure}}::h22c55030577f720e

Here is the code location of the error

///  halo2_proofs::icicle::copy_scalars_to_device
pub fn copy_scalars_to_device<C: CurveAffine>(
    coeffs: &[C::Scalar],
) -> DeviceBuffer<ScalarField_BN254> {
    let scalars = icicle_scalars_from_c::<C>(coeffs);

    DeviceBuffer::from_slice(scalars.as_slice()).unwrap()
}

///  rustacuda::prelude::DeviceBuffer;
pub fn from_slice(slice: &[T]) -> CudaResult<Self> {
        unsafe {
            let mut uninit = DeviceBuffer::uninitialized(slice.len())?;
            uninit.copy_from(slice)?;
            Ok(uninit)
        }
    }

Device and Operating System

OS: ubuntu22.04 GPU type: NVIDIA GeForce RTX 3070 Driver Version: 535.161.08
CUDA Version: 12.2