Skip to main content

qualia_core_db/wgsl_forge/ir/
intrinsics.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
4#[serde(rename_all = "snake_case")]
5pub enum SubgroupReduceOp {
6    Add,
7    Mul,
8    Min,
9    Max,
10    And,
11    Or,
12    Xor,
13}
14
15/// Hardware family an [`Intrinsic`] maps onto. Used by the capability checker to
16/// decide whether a schedule that relies on the intrinsic can run natively, be
17/// lowered to a portable equivalent, or must be excluded on the local adapter.
18#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
19pub enum IntrinsicClass {
20    /// Warp/subgroup operations (shuffle, ballot, reductions).
21    Subgroup,
22    /// Cooperative-matrix / Tensor-core matrix-multiply-accumulate.
23    CooperativeMatrix,
24    /// Ray-query intersection tests (RT cores).
25    RayTracing,
26}
27
28#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
29#[serde(rename_all = "snake_case")]
30pub enum Intrinsic {
31    SubgroupReduce {
32        op: SubgroupReduceOp,
33    },
34    SubgroupShuffle {
35        delta: u32,
36    },
37    SubgroupBallot,
38    CoopMatMul {
39        m: u32,
40        n: u32,
41        k: u32,
42    },
43    /// Hardware ray-query intersection against a bound acceleration structure.
44    /// `destination` receives the committed-hit distance (or a miss sentinel).
45    RayQuery {
46        acceleration_structure: String,
47        origin: String,
48        direction: String,
49        t_min: String,
50        t_max: String,
51        destination: String,
52    },
53}
54
55impl Intrinsic {
56    pub const fn class(&self) -> IntrinsicClass {
57        match self {
58            Self::SubgroupReduce { .. } | Self::SubgroupShuffle { .. } | Self::SubgroupBallot => {
59                IntrinsicClass::Subgroup
60            }
61            Self::CoopMatMul { .. } => IntrinsicClass::CooperativeMatrix,
62            Self::RayQuery { .. } => IntrinsicClass::RayTracing,
63        }
64    }
65}