cubecl_ir/
marker.rs

1use core::fmt::Display;
2
3use enumset::{EnumSet, EnumSetType};
4
5use crate::{Instruction, Operation, TypeHash};
6
7use crate::{OperationCode, OperationReflect};
8
9use super::Variable;
10
11/// Operations that don't change the semantics of the kernel. In other words, operations that do not
12/// perform any computation, if they run at all. i.e. `println`, comments and debug symbols.
13///
14/// Can be safely removed or ignored without changing the kernel result.
15#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
16#[derive(Debug, Clone, TypeHash, PartialEq, Eq, Hash, OperationCode)]
17#[operation(opcode_name = MarkerOpCode)]
18pub enum Marker {
19    /// Frees a shared memory, allowing reuse in later blocks.
20    Free(Variable),
21}
22
23impl OperationReflect for Marker {
24    type OpCode = MarkerOpCode;
25
26    fn op_code(&self) -> Self::OpCode {
27        self.__match_opcode()
28    }
29}
30
31impl Display for Marker {
32    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
33        match self {
34            Marker::Free(var) => write!(f, "free({var})"),
35        }
36    }
37}
38
39impl From<Marker> for Instruction {
40    fn from(value: Marker) -> Self {
41        Instruction::no_out(Operation::Marker(value))
42    }
43}
44
45/// Unchecked optimizations for float operations. May cause precision differences, or undefined
46/// behaviour if the relevant conditions are not followed.
47#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
48#[derive(Debug, Hash, TypeHash, EnumSetType)]
49pub enum FastMath {
50    /// Assume values are never `NaN`. If they are, the result is considered undefined behaviour.
51    NotNaN,
52    /// Assume values are never `Inf`/`-Inf`. If they are, the result is considered undefined
53    /// behaviour.
54    NotInf,
55    /// Ignore sign on zero values.
56    UnsignedZero,
57    /// Allow swapping float division with a reciprocal, even if that swap would change precision.
58    AllowReciprocal,
59    /// Allow contracting float operations into fewer operations, even if the precision could
60    /// change.
61    AllowContraction,
62    /// Allow reassociation for float operations, even if the precision could change.
63    AllowReassociation,
64    /// Allow all mathematical transformations for float operations, including contraction and
65    /// reassociation, even if the precision could change.
66    AllowTransform,
67    /// Allow using lower precision intrinsics
68    ReducedPrecision,
69}
70
71impl FastMath {
72    pub const fn all() -> EnumSet<FastMath> {
73        EnumSet::all()
74    }
75}