Skip to content

Commit

Permalink
Add support for numeric constants.
Browse files Browse the repository at this point in the history
  • Loading branch information
booti386 authored and Guillaume CHARIFI committed Sep 10, 2024
1 parent 1b2eeea commit d849275
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
14 changes: 14 additions & 0 deletions crates/cubecl-core/src/frontend/element/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -107,6 +120,7 @@ macro_rules! impl_float {
}

impl Float for $primitive {

fn new(val: f32) -> Self {
$new(val)
}
Expand Down
2 changes: 2 additions & 0 deletions crates/cubecl-core/src/frontend/element/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) -> <Self as CubeType>::ExpandType {
Expand Down
3 changes: 3 additions & 0 deletions crates/cubecl-core/src/frontend/element/numeric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d849275

Please sign in to comment.