use crate::{
utils::tensor_product,
zerocheck::{ZerocheckCpuBackendHelper, ZerocheckRoundInput, ZerocheckRoundParameters},
ComputationBackend, Error,
};
use binius_field::{Field, PackedField};
use std::fmt::Debug;
use tracing::instrument;
#[derive(Clone, Debug)]
pub struct CpuBackend;
pub fn make_portable_backend() -> CpuBackend {
CpuBackend
}
impl ComputationBackend for CpuBackend {
type Vec<P: Send + Sync + Debug + 'static> = Vec<P>;
fn to_hal_slice<P: Debug + Send + Sync + 'static>(v: Vec<P>) -> Self::Vec<P> {
v
}
#[instrument(skip_all)]
fn tensor_product_full_query<P: PackedField>(
&self,
query: &[P::Scalar],
) -> Result<Self::Vec<P>, Error> {
tensor_product(query)
}
#[instrument(skip_all)]
fn zerocheck_compute_round_coeffs<F, PW, FDomain>(
&self,
params: &ZerocheckRoundParameters,
input: &ZerocheckRoundInput<F, PW, FDomain>,
handler: &mut dyn ZerocheckCpuBackendHelper<F, PW, FDomain>,
) -> Result<Vec<PW::Scalar>, Error>
where
F: Field,
PW: PackedField,
PW::Scalar: From<F> + Into<F>,
FDomain: Field,
{
handler.handle_zerocheck_round(params, input)
}
}