Skip to main content

vyre_foundation/ir_inner/model/program/stats/
methods.rs

1use super::{
2    ProgramStats, CAP_ASYNC_DISPATCH, CAP_BF16, CAP_DISTRIBUTED_COLLECTIVES, CAP_F16, CAP_F64,
3    CAP_INDIRECT_DISPATCH, CAP_SUBGROUP_OPS, CAP_TENSOR_OPS, CAP_TRAP, NODE_KIND_ASSIGN,
4    NODE_KIND_BARRIER, NODE_KIND_IF, NODE_KIND_LET, NODE_KIND_LOOP, NODE_KIND_REGION,
5    NODE_KIND_STORE,
6};
7
8impl ProgramStats {
9    /// True when the program uses subgroup operations.
10    #[inline]
11    #[must_use]
12    pub fn subgroup_ops(&self) -> bool {
13        self.capability_bits & CAP_SUBGROUP_OPS != 0
14    }
15
16    /// True when the program uses IEEE-754 binary16 values.
17    #[inline]
18    #[must_use]
19    pub fn f16(&self) -> bool {
20        self.capability_bits & CAP_F16 != 0
21    }
22
23    /// True when the program uses bfloat16 values.
24    #[inline]
25    #[must_use]
26    pub fn bf16(&self) -> bool {
27        self.capability_bits & CAP_BF16 != 0
28    }
29
30    /// True when the program uses IEEE-754 binary64 values.
31    #[inline]
32    #[must_use]
33    pub fn f64(&self) -> bool {
34        self.capability_bits & CAP_F64 != 0
35    }
36
37    /// True when the program requires async dispatch semantics.
38    #[inline]
39    #[must_use]
40    pub fn async_dispatch(&self) -> bool {
41        self.capability_bits & CAP_ASYNC_DISPATCH != 0
42    }
43
44    /// True when the program requires indirect dispatch support.
45    #[inline]
46    #[must_use]
47    pub fn indirect_dispatch(&self) -> bool {
48        self.capability_bits & CAP_INDIRECT_DISPATCH != 0
49    }
50
51    /// True when the program uses tensor / tensor-core operand types.
52    #[inline]
53    #[must_use]
54    pub fn tensor_ops(&self) -> bool {
55        self.capability_bits & CAP_TENSOR_OPS != 0
56    }
57
58    /// True when the program uses `Node::Trap`.
59    #[inline]
60    #[must_use]
61    pub fn trap(&self) -> bool {
62        self.capability_bits & CAP_TRAP != 0
63    }
64
65    /// True when the program uses distributed collective communication nodes.
66    #[inline]
67    #[must_use]
68    pub fn distributed_collectives(&self) -> bool {
69        self.capability_bits & CAP_DISTRIBUTED_COLLECTIVES != 0
70    }
71
72    /// True when at least one node of any kind in `mask` was observed
73    /// in the stats walk. Use the `NODE_KIND_*` constants to compose
74    /// the mask:
75    ///
76    /// ```ignore
77    /// use vyre_foundation::ir::stats::{NODE_KIND_LOOP, NODE_KIND_IF};
78    /// if program.stats().has_any_node_kind(NODE_KIND_LOOP | NODE_KIND_IF) {
79    ///     // walk the tree
80    /// }
81    /// ```
82    #[inline]
83    #[must_use]
84    pub fn has_any_node_kind(&self, mask: u32) -> bool {
85        (self.node_kinds_present & mask) != 0
86    }
87
88    /// True when the program contains at least one `Node::Let`.
89    #[inline]
90    #[must_use]
91    pub fn has_node_let(&self) -> bool {
92        self.has_any_node_kind(NODE_KIND_LET)
93    }
94    /// True when the program contains at least one `Node::Loop`.
95    #[inline]
96    #[must_use]
97    pub fn has_node_loop(&self) -> bool {
98        self.has_any_node_kind(NODE_KIND_LOOP)
99    }
100    /// True when the program contains at least one `Node::If`.
101    #[inline]
102    #[must_use]
103    pub fn has_node_if(&self) -> bool {
104        self.has_any_node_kind(NODE_KIND_IF)
105    }
106    /// True when the program contains at least one `Node::Store`.
107    #[inline]
108    #[must_use]
109    pub fn has_node_store(&self) -> bool {
110        self.has_any_node_kind(NODE_KIND_STORE)
111    }
112    /// True when the program contains at least one `Node::Barrier`.
113    #[inline]
114    #[must_use]
115    pub fn has_node_barrier(&self) -> bool {
116        self.has_any_node_kind(NODE_KIND_BARRIER)
117    }
118    /// True when the program contains at least one `Node::Assign`.
119    #[inline]
120    #[must_use]
121    pub fn has_node_assign(&self) -> bool {
122        self.has_any_node_kind(NODE_KIND_ASSIGN)
123    }
124    /// True when the program contains at least one `Node::Region`.
125    #[inline]
126    #[must_use]
127    pub fn has_node_region(&self) -> bool {
128        self.has_any_node_kind(NODE_KIND_REGION)
129    }
130}