use crate::dyn_backend::{DynBackendDevice, DynBackendStorage};
use fuel_ir::{Error, GgmlDType, Layout, Result, Shape};
use std::any::Any;
use std::borrow::Cow;
pub trait DynQuantizedStorage: Send + Sync + std::fmt::Debug {
fn dtype(&self) -> GgmlDType;
fn block_size(&self) -> usize;
fn storage_size_in_bytes(&self) -> usize;
fn quantize(&mut self, src: &dyn DynBackendStorage) -> Result<()>;
fn quantize_imatrix(
&mut self,
src: &dyn DynBackendStorage,
imatrix_weights: &[f32],
n_per_row: usize,
) -> Result<()>;
fn quantize_onto(&mut self, src: &dyn DynBackendStorage) -> Result<()>;
fn quantize_imatrix_onto(
&mut self,
src: &dyn DynBackendStorage,
imatrix_weights: &[f32],
n_per_row: usize,
) -> Result<()>;
fn dequantize(&self, elem_count: usize) -> Result<Box<dyn DynBackendStorage>>;
fn dequantize_f16(&self, _elem_count: usize) -> Result<Box<dyn DynBackendStorage>> {
Err(Error::Msg("dequantize_f16 not supported on this backend".into()).bt())
}
fn data(&self) -> Result<Cow<'_, [u8]>>;
fn device_ptr(&self) -> Result<*const u8> {
Err(Error::Msg("device_ptr not supported on this backend".into()).bt())
}
fn fwd(
&self,
self_shape: &Shape,
input: &dyn DynBackendStorage,
layout: &Layout,
) -> Result<(Box<dyn DynBackendStorage>, Shape)>;
fn indexed_moe_forward(
&self,
_self_shape: &Shape,
_input: &dyn DynBackendStorage,
_input_layout: &Layout,
_ids: &dyn DynBackendStorage,
_ids_layout: &Layout,
) -> Result<(Box<dyn DynBackendStorage>, Shape)> {
Err(Error::Msg("indexed_moe_forward not supported on this backend".into()).bt())
}
fn as_any(&self) -> &dyn Any;
fn device_arc_dyn(&self) -> std::sync::Arc<dyn DynBackendDevice>;
}
pub trait QuantizedDeviceKernels: DynBackendDevice {
fn qzeros(&self, elem_count: usize, dtype: GgmlDType) -> Result<Box<dyn DynQuantizedStorage>>;
fn load_quantized(
&self,
dtype: GgmlDType,
data: Cow<'_, [u8]>,
) -> Result<Box<dyn DynQuantizedStorage>>;
}