cubecl_tile/space/partition/
count.rs1use crate::Extent;
4
5#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
7pub enum Count {
8 Stated(usize),
10 All,
12 AllAcross(usize),
14 Distributed(usize),
16}
17
18#[derive(Clone, Copy, PartialEq, Eq, Debug)]
20pub(crate) enum GridCount {
21 Const(usize),
22 Extent(usize),
23}
24
25impl Count {
26 pub(crate) fn stated(self) -> Option<usize> {
28 match self {
29 Count::Stated(n) | Count::AllAcross(n) => Some(n),
30 Count::All | Count::Distributed(_) => None,
31 }
32 }
33
34 pub(crate) fn tiles(self, extent: usize, tile: usize) -> usize {
36 match self {
37 Count::Stated(n) | Count::Distributed(n) => n,
38 Count::All | Count::AllAcross(_) => extent.div_ceil(tile),
39 }
40 }
41
42 pub(crate) fn tiles_const(self, extent: Extent, tile: usize) -> Option<usize> {
44 match (self, extent) {
45 (Count::Stated(n) | Count::Distributed(n), _) => Some(n),
46 (_, Extent::Static(extent)) => Some(self.tiles(extent, tile)),
47 (_, Extent::Dynamic) => None,
48 }
49 }
50
51 pub(crate) fn grid(self, tile: usize) -> GridCount {
53 match self {
54 Count::Stated(n) | Count::Distributed(n) => GridCount::Const(n),
55 Count::All | Count::AllAcross(_) => GridCount::Extent(tile),
56 }
57 }
58}
59
60impl From<Count> for usize {
62 fn from(count: Count) -> usize {
63 count
64 .stated()
65 .expect("a units level's count is stated; every tile is the launch's")
66 }
67}