cubecl_tile/space/partition/
compute_scope.rs1use cubecl::prelude::*;
4
5#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, PartialOrd, Ord)]
7pub enum ComputeScope {
8 Unit,
9 Plane,
10 PlaneGroup {
13 planes: usize,
14 },
15 Cube,
16}
17
18impl ComputeScope {
19 pub const WARPGROUP: Self = Self::PlaneGroup { planes: 4 };
22
23 pub fn planes(self) -> Option<usize> {
25 match self {
26 ComputeScope::Plane => Some(1),
27 ComputeScope::PlaneGroup { planes } => Some(planes),
28 ComputeScope::Unit | ComputeScope::Cube => None,
29 }
30 }
31}
32
33#[cube]
34impl ComputeScope {
35 pub fn position(#[comptime] compute_scope: ComputeScope) -> usize {
38 match comptime!(compute_scope) {
39 ComputeScope::Plane => UNIT_POS_Y as usize,
40 ComputeScope::PlaneGroup { planes } => UNIT_POS_Y as usize / planes,
41 ComputeScope::Unit => UNIT_POS_X as usize,
42 ComputeScope::Cube => {
43 panic!(
44 "ComputeScope::position: a cube has one position per grid dimension; say which"
45 )
46 }
47 }
48 }
49
50 pub fn unit(#[comptime] compute_scope: ComputeScope) -> usize {
55 match comptime!(compute_scope) {
56 ComputeScope::Cube => UNIT_POS as usize,
57 ComputeScope::PlaneGroup { planes } => {
58 (UNIT_POS_Y as usize % planes) * CUBE_DIM_X as usize + UNIT_POS_X as usize
59 }
60 ComputeScope::Plane => UNIT_POS_X as usize,
61 ComputeScope::Unit => comptime!(panic!(
62 "ComputeScope::unit: a unit is the only unit of its own scope"
63 )),
64 }
65 }
66}