cubecl_core/frontend/
options.rs

1use enumset::{EnumSet, EnumSetType};
2use serde::{Deserialize, Serialize};
3
4/// Unchecked optimizations for float operations. May cause precision differences, or undefined
5/// behaviour if the relevant conditions are not followed.
6#[derive(Default, Debug, Hash, Serialize, Deserialize, EnumSetType)]
7pub enum FastMath {
8    /// Disable unsafe optimizations
9    #[default]
10    None,
11    /// Assume values are never `NaN`. If they are, the result is considered undefined behaviour.
12    NotNaN,
13    /// Assume values are never `Inf`/`-Inf`. If they are, the result is considered undefined
14    /// behaviour.
15    NotInf,
16    /// Ignore sign on zero values.
17    UnsignedZero,
18    /// Allow swapping float division with a reciprocal, even if that swap would change precision.
19    AllowReciprocal,
20    /// Allow contracting float operations into fewer operations, even if the precision could
21    /// change.
22    AllowContraction,
23    /// Allow reassociation for float operations, even if the precision could change.
24    AllowReassociation,
25    /// Allow all mathematical transformations for float operations, including contraction and
26    /// reassociation, even if the precision could change.
27    AllowTransform,
28    /// Allow using lower precision intrinsics (CUDA `--use_fast_math`)
29    /// Also impacts `NaN`, `Inf` and signed zero handling, as well as subnormals and rounding.
30    ///
31    /// Notable edge case:
32    /// powf - Returns `NaN` for negative bases
33    ReducedPrecision,
34}
35
36impl FastMath {
37    pub fn all() -> EnumSet<FastMath> {
38        EnumSet::all()
39    }
40}