use crate::components::{
AccG, AvailableLineSizes, InputRuntimeArg, LhsG, MatmulLineSizes, MatmulPrecision,
MatmulProblem, MatmulSelection, MatmulSpec, OutputRuntimeArg, RhsG, TilingScheme,
batch::{CubeCountInput, CubeCountInputArgs, HypercubeConfig},
error::MatmulSetupError,
global::{self, GlobalConfig as _},
};
use cubecl_core as cubecl;
use cubecl_core::prelude::*;
use cubecl_std::{
CubeOption,
tensor::{View, layout::Coords3d},
};
use std::{fmt::Debug, hash::Hash};
pub trait BatchMatmulFamily: 'static + Send + Sync {
type Matmul<MP: MatmulPrecision>: BatchMatmul<MP, Config = Self::Config>;
type Config: BatchConfig;
fn setup<MP: MatmulPrecision, R: Runtime>(
client: &ComputeClient<R::Server>,
problem: &MatmulProblem,
selection: &MatmulSelection,
line_sizes: &MatmulLineSizes,
) -> Result<Self::Config, MatmulSetupError>;
unsafe fn launch_unchecked<'a, MS: MatmulSpec, R: Runtime>(
client: &ComputeClient<<R as Runtime>::Server>,
cube_dim: CubeDim,
cube_count: CubeCount,
input: InputRuntimeArg<'a, MS, R>,
output: OutputRuntimeArg<'a, MS, R>,
cube_count_input: CubeCountInputArgs<'a, R>,
config: Self::Config,
);
fn filter_line_sizes(available_line_sizes: AvailableLineSizes) -> AvailableLineSizes {
available_line_sizes
}
}
#[cube]
pub trait BatchMatmul<MP: MatmulPrecision>: 'static + Send + Sync {
type Config: BatchConfig;
fn execute(
a: View<Line<LhsG<MP>>, Coords3d>,
b: View<Line<RhsG<MP>>, Coords3d>,
c: CubeOption<View<Line<AccG<MP>>, Coords3d>>,
out: View<Line<AccG<MP>>, Coords3d, ReadWrite>,
cube_count_args: CubeCountInput,
#[comptime] config: Self::Config,
);
}
pub trait BatchConfig:
Copy + Clone + Eq + PartialEq + Hash + Debug + Send + Sync + 'static
{
type GlobalConfig: global::GlobalConfig;
fn global_config(&self) -> Self::GlobalConfig;
fn tiling_scheme(&self) -> TilingScheme {
self.global_config().tiling_scheme()
}
fn cube_dim(&self) -> CubeDim;
fn line_sizes(&self) -> MatmulLineSizes;
fn hypercube_config(&self) -> HypercubeConfig;
fn can_yield_extra_cubes(&self) -> bool;
}