use cubecl::linalg::matmul::kernels::MatmulLaunchError;
use super::init_matmul_output;
use crate::{tensor::JitTensor, FloatElement, JitRuntime};
#[cfg(feature = "autotune")]
use super::matmul_autotune;
pub enum MatmulStrategy {
#[cfg(feature = "autotune")]
Autotune,
Cube,
}
impl Default for MatmulStrategy {
fn default() -> Self {
#[cfg(feature = "autotune")]
return MatmulStrategy::Autotune;
#[cfg(not(feature = "autotune"))]
MatmulStrategy::Cube
}
}
pub fn matmul<R: JitRuntime, E: FloatElement>(
lhs: JitTensor<R>,
rhs: JitTensor<R>,
out: Option<JitTensor<R>>,
strategy: MatmulStrategy,
) -> Result<JitTensor<R>, MatmulLaunchError> {
match strategy {
MatmulStrategy::Cube => {
let out = out.unwrap_or_else(|| init_matmul_output::<R, E>(&lhs, &rhs));
let client = &lhs.client;
cubecl::linalg::matmul::launch_ref::<R, E>(
&Default::default(),
client,
&lhs.as_handle_ref(),
&rhs.as_handle_ref(),
&out.as_handle_ref(),
)?;
Ok(out)
}
#[cfg(feature = "autotune")]
MatmulStrategy::Autotune => Ok(matmul_autotune::<R, E>(lhs, rhs, out)),
}
}