Struct cubecl_core::frontend::Comptime

source ·
pub struct Comptime<T> { /* private fields */ }
Expand description

Encapsulates a value to signify it must be used at compilation time rather than in the kernel

Use Comptime<Option<T>> to have an alternate runtime behaviour if the compilation time value is not present

Implementations§

source§

impl<T> Comptime<T>

source

pub fn new(inner: T) -> Self

Create a new Comptime. Useful when hardcoding values in Cube kernels. For instance: if Comptime::new(false) {…} never generates the inner code block

source

pub fn get(_comptime: Self) -> T

Get the inner value of a Comptime. For instance: let c = Comptime::new(false); if Comptime::get(c) {…}

source

pub fn map<R, F: Fn(T) -> R>(_comptime: Self, _closure: F) -> Comptime<R>

Executes a closure on the comptime and returns a new comptime containing the value.

source

pub fn __expand_map<R, F: Fn(T) -> R>(inner: T, closure: F) -> R

source§

impl<T: ComptimeType> Comptime<Option<T>>

source

pub fn is_some(comptime: Self) -> Comptime<bool>

Map a Comptime optional to a Comptime boolean that tell whether the optional contained a value

source

pub fn unwrap_or_else<F>(_comptime: Self, _alt: F) -> T
where F: FnOnce() -> T,

Return the inner value of the Comptime if it exists, otherwise tell how to compute it at runtime

source

pub fn __expand_unwrap_or_else<F>( context: &mut CubeContext, t: Option<T>, alt: F, ) -> <T as CubeType>::ExpandType
where F: FnOnce(&mut CubeContext) -> T::ExpandType,

Expanded version of unwrap_or_else

source§

impl<T: Vectorized> Comptime<T>

source

pub fn vectorization(_state: &T) -> Comptime<UInt>

source

pub fn __expand_vectorization(_context: &mut CubeContext, state: T) -> UInt

source§

impl<T: CubePrimitive + Into<ExpandElement>> Comptime<T>

source

pub fn runtime(_comptime: Self) -> T

source

pub fn __expand_runtime( _context: &mut CubeContext, inner: T, ) -> ExpandElementTyped<T>

Trait Implementations§

source§

impl<T: Add<T, Output = T>> Add for Comptime<T>

§

type Output = Comptime<T>

The resulting type after applying the + operator.
source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
source§

impl<T: Clone> Clone for Comptime<T>

source§

fn clone(&self) -> Comptime<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Clone + Init> CubeType for Comptime<T>

§

type ExpandType = T

source§

fn init(context: &mut CubeContext, expand: Self::ExpandType) -> Self::ExpandType

Wrapper around the init method, necessary to type inference.
source§

impl<T: Div<T, Output = T>> Div for Comptime<T>

§

type Output = Comptime<T>

The resulting type after applying the / operator.
source§

fn div(self, rhs: Self) -> Self::Output

Performs the / operation. Read more
source§

impl From<Comptime<u32>> for UInt

source§

fn from(value: Comptime<u32>) -> Self

Converts to this type from the input type.
source§

impl<T: Mul<T, Output = T>> Mul for Comptime<T>

§

type Output = Comptime<T>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
source§

impl<T: PartialOrd + PartialEq> PartialEq for Comptime<T>

source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: PartialOrd + PartialEq> PartialOrd for Comptime<T>

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T: Rem<T, Output = T>> Rem for Comptime<T>

§

type Output = Comptime<T>

The resulting type after applying the % operator.
source§

fn rem(self, rhs: Self) -> Self::Output

Performs the % operation. Read more
source§

impl<T: Sub<T, Output = T>> Sub for Comptime<T>

§

type Output = Comptime<T>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
source§

impl<T: Copy> Copy for Comptime<T>

Auto Trait Implementations§

§

impl<T> Freeze for Comptime<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Comptime<T>
where T: RefUnwindSafe,

§

impl<T> Send for Comptime<T>
where T: Send,

§

impl<T> Sync for Comptime<T>
where T: Sync,

§

impl<T> Unpin for Comptime<T>
where T: Unpin,

§

impl<T> UnwindSafe for Comptime<T>
where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T, Rhs, Output> NumOps<Rhs, Output> for T
where T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,