From d849275eda34c57e71f9bd4e25c1a4697cbd9f0d Mon Sep 17 00:00:00 2001 From: Guillaume Charifi-Hoareau Date: Tue, 10 Sep 2024 16:24:43 +0200 Subject: [PATCH] Add support for numeric constants. --- crates/cubecl-core/src/frontend/element/float.rs | 14 ++++++++++++++ crates/cubecl-core/src/frontend/element/int.rs | 2 ++ crates/cubecl-core/src/frontend/element/numeric.rs | 3 +++ 3 files changed, 19 insertions(+) diff --git a/crates/cubecl-core/src/frontend/element/float.rs b/crates/cubecl-core/src/frontend/element/float.rs index 7de1d7b77..282a68dea 100644 --- a/crates/cubecl-core/src/frontend/element/float.rs +++ b/crates/cubecl-core/src/frontend/element/float.rs @@ -39,6 +39,19 @@ pub trait Float: + std::cmp::PartialOrd + std::cmp::PartialEq { + const DIGITS: u32 = Self::DIGITS; + const EPSILON: Self = Self::EPSILON; + const INFINITY: Self = Self::INFINITY; + const MANTISSA_DIGITS: u32 = Self::MANTISSA_DIGITS; + const MAX_10_EXP: i32 = Self::MAX_10_EXP; + const MAX_EXP: i32 = Self::MAX_EXP; + const MIN_10_EXP: i32 = Self::MIN_10_EXP; + const MIN_EXP: i32 = Self::MIN_EXP; + const MIN_POSITIVE: Self = Self::MIN_POSITIVE; + const NAN: Self = Self::NAN; + const NEG_INFINITY: Self = Self::NEG_INFINITY; + const RADIX: u32 = Self::RADIX; + fn new(val: f32) -> Self; fn vectorized(val: f32, vectorization: u32) -> Self; fn vectorized_empty(vectorization: u32) -> Self; @@ -107,6 +120,7 @@ macro_rules! impl_float { } impl Float for $primitive { + fn new(val: f32) -> Self { $new(val) } diff --git a/crates/cubecl-core/src/frontend/element/int.rs b/crates/cubecl-core/src/frontend/element/int.rs index a498b86d7..0556d293e 100644 --- a/crates/cubecl-core/src/frontend/element/int.rs +++ b/crates/cubecl-core/src/frontend/element/int.rs @@ -40,6 +40,8 @@ pub trait Int: + std::cmp::PartialOrd + std::cmp::PartialEq { + const BITS: Self = Self::BITS; + fn new(val: i64) -> Self; fn vectorized(val: i64, vectorization: u32) -> Self; fn __expand_new(context: &mut CubeContext, val: i64) -> ::ExpandType { diff --git a/crates/cubecl-core/src/frontend/element/numeric.rs b/crates/cubecl-core/src/frontend/element/numeric.rs index 9c19b1c4f..ff5da1e54 100644 --- a/crates/cubecl-core/src/frontend/element/numeric.rs +++ b/crates/cubecl-core/src/frontend/element/numeric.rs @@ -49,6 +49,9 @@ pub trait Numeric: + std::cmp::PartialOrd + std::cmp::PartialEq { + const MAX: Self = Self::MAX; + const MIN: Self = Self::MIN; + /// Create a new constant numeric. /// /// Note: since this must work for both integer and float