Skip to main content

cubecl_attention/components/batch/hypercube/
base.rs

1use cubecl_core as cubecl;
2use cubecl_core::prelude::*;
3
4use crate::components::{AttentionProblem, AttentionSelection};
5
6#[derive(Debug, Clone)]
7pub struct HypercubeSelection {}
8
9impl HypercubeSelection {
10    pub fn to_hypercube_config(
11        &self,
12        _problem: &AttentionProblem,
13        _max_cube_count: CubeCount,
14    ) -> HypercubeConfig {
15        HypercubeConfig {}
16    }
17}
18
19#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
20pub struct HypercubeConfig {}
21
22impl HypercubeConfig {
23    pub fn cube_count_plan(
24        &self,
25        problem: &AttentionProblem,
26        selection: &AttentionSelection,
27    ) -> CubeCountPlan {
28        CubeCountPlan {
29            inner: (problem.seq_q as u32)
30                .div_ceil(selection.tiling_scheme.elements_in_stage_seq_q()),
31            outer: (problem.batch * problem.num_heads) as u32,
32        }
33    }
34}
35
36pub struct CubeCountPlan {
37    inner: u32,
38    outer: u32,
39}
40
41impl CubeCountPlan {
42    pub fn resolve(&self) -> CubeCount {
43        CubeCount::Static(self.inner, self.outer, 1)
44    }
45
46    /// Make a CubeCountInput from CubeCountPlan
47    pub fn as_args<'a, R: Runtime>(&self) -> CubeCountInputArgs<'a, R> {
48        CubeCountInputArgs::Tmp {
49            dummy: ScalarArg::new(0),
50        }
51    }
52}
53
54#[derive(CubeType, CubeLaunch)]
55/// CubeCountPlan stripped of non-essential runtime information
56///
57/// This enum is given as runtime input to the matmul
58pub enum CubeCountInput {
59    Tmp { dummy: u32 },
60}