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>
impl<T> Comptime<T>
sourcepub fn new(inner: T) -> Self
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
sourcepub fn get(_comptime: Self) -> T
pub fn get(_comptime: Self) -> T
Get the inner value of a Comptime. For instance: let c = Comptime::new(false); if Comptime::get(c) {…}
sourcepub fn map<R, F: Fn(T) -> R>(_comptime: Self, _closure: F) -> Comptime<R>
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.
pub fn __expand_map<R, F: Fn(T) -> R>(inner: T, closure: F) -> R
source§impl<T: ComptimeType> Comptime<Option<T>>
impl<T: ComptimeType> Comptime<Option<T>>
sourcepub fn is_some(comptime: Self) -> Comptime<bool>
pub fn is_some(comptime: Self) -> Comptime<bool>
Map a Comptime optional to a Comptime boolean that tell whether the optional contained a value
sourcepub fn unwrap_or_else<F>(_comptime: Self, _alt: F) -> Twhere
F: FnOnce() -> T,
pub fn unwrap_or_else<F>(_comptime: Self, _alt: F) -> Twhere
F: FnOnce() -> T,
Return the inner value of the Comptime if it exists, otherwise tell how to compute it at runtime
sourcepub fn __expand_unwrap_or_else<F>(
context: &mut CubeContext,
t: Option<T>,
alt: F,
) -> <T as CubeType>::ExpandType
pub fn __expand_unwrap_or_else<F>( context: &mut CubeContext, t: Option<T>, alt: F, ) -> <T as CubeType>::ExpandType
Expanded version of unwrap_or_else
source§impl<T: Vectorized> Comptime<T>
impl<T: Vectorized> Comptime<T>
pub fn vectorization(_state: &T) -> Comptime<UInt>
pub fn __expand_vectorization(_context: &mut CubeContext, state: T) -> UInt
source§impl<T: CubePrimitive + Into<ExpandElement>> Comptime<T>
impl<T: CubePrimitive + Into<ExpandElement>> Comptime<T>
pub fn runtime(_comptime: Self) -> T
pub fn __expand_runtime( _context: &mut CubeContext, inner: T, ) -> ExpandElementTyped<T>
Trait Implementations§
source§impl<T: Clone + Init> CubeType for Comptime<T>
impl<T: Clone + Init> CubeType for Comptime<T>
type ExpandType = T
source§fn init(context: &mut CubeContext, expand: Self::ExpandType) -> Self::ExpandType
fn init(context: &mut CubeContext, expand: Self::ExpandType) -> Self::ExpandType
source§impl<T: PartialOrd + PartialEq> PartialOrd for Comptime<T>
impl<T: PartialOrd + PartialEq> PartialOrd for Comptime<T>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)