cubecl_core::ir

Struct Scope

Source
pub struct Scope {
    pub depth: u8,
    pub operations: Vec<Operation>,
    pub locals: Vec<Variable>,
    pub const_arrays: Vec<(Variable, Vec<Variable>)>,
    pub layout_ref: Option<Variable>,
    pub undeclared: u16,
    /* private fields */
}
Expand description

The scope is the main operation and variable container that simplify the process of reading inputs, creating local variables and adding new operations.

Notes:

This type isn’t responsible for creating shader bindings and figuring out which variable can be written to.

Fields§

§depth: u8§operations: Vec<Operation>§locals: Vec<Variable>§const_arrays: Vec<(Variable, Vec<Variable>)>§layout_ref: Option<Variable>§undeclared: u16

Implementations§

Source§

impl Scope

Source

pub fn root() -> Self

Create a scope that is at the root of a kernel definition.

A local scope can be created with the child method.

Source

pub fn zero<I: Into<Item>>(&mut self, item: I) -> Variable

Create a variable initialized at zero.

Source

pub fn create_with_value<E, I>(&mut self, value: E, item: I) -> Variable
where E: ToPrimitive, I: Into<Item> + Copy,

Create a variable initialized at some value.

Source

pub fn create_matrix(&mut self, matrix: Matrix) -> Variable

Create a matrix variable

Source

pub fn create_slice(&mut self, item: Item) -> Variable

Create a slice variable

Source

pub fn create_local<I: Into<Item>>(&mut self, item: I) -> Variable

Create a local variable of the given item type.

Source

pub fn create_local_undeclared(&mut self, item: Item) -> Variable

Create a new undeclared local, but doesn’t perform the declaration.

Useful for for loops and other algorithms that require the control over initialization.

Source

pub fn create_local_binding(&mut self, item: Item) -> Variable

Create a new undeclared local binding, but doesn’t perform the declaration.

Useful for temporaries and other algorithms that require the control over initialization.

Source

pub fn read_array<I: Into<Item>>( &mut self, index: u16, item: I, position: Variable, ) -> Variable

Reads an input array to a local variable.

The index refers to the argument position of the array in the compute shader.

Source

pub fn read_scalar(&mut self, index: u16, elem: Elem) -> Variable

Reads an input scalar to a local variable.

The index refers to the scalar position for the same element type.

Source

pub fn last_local_index(&self) -> Option<&Variable>

Retrieve the last local variable that was created.

Source

pub fn write_global( &mut self, input: Variable, output: Variable, position: Variable, )

Writes a variable to given output.

Notes:

This should only be used when doing compilation.

Source

pub fn write_global_custom(&mut self, output: Variable)

Writes a variable to given output.

Notes:

This should only be used when doing compilation.

Source

pub fn read_globals(&self) -> Vec<(u16, ReadingStrategy)>

Source

pub fn register<T: Into<Operation>>(&mut self, operation: T)

Register an operation into the scope.

Source

pub fn child(&mut self) -> Self

Create an empty child scope.

Source

pub fn process(&mut self) -> ScopeProcessing

Returns the variables and operations to be declared and executed.

Notes:

New operations and variables can be created within the same scope without having name conflicts.

Source

pub fn new_local_index(&self) -> u16

Source

pub fn create_shared<I: Into<Item>>( &mut self, item: I, shared_memory_size: u32, ) -> Variable

Create a shared variable of the given item type.

Source

pub fn create_const_array<I: Into<Item>>( &mut self, item: I, data: Vec<Variable>, ) -> Variable

Create a shared variable of the given item type.

Source

pub fn create_local_array<I: Into<Item>>( &mut self, item: I, array_size: u32, ) -> Variable

Create a local array of the given item type.

Trait Implementations§

Source§

impl Clone for Scope

Source§

fn clone(&self) -> Scope

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 Debug for Scope

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Scope

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Scope

Source§

fn eq(&self, other: &Scope) -> 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 Serialize for Scope

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Scope

Auto Trait Implementations§

§

impl Freeze for Scope

§

impl RefUnwindSafe for Scope

§

impl Send for Scope

§

impl Sync for Scope

§

impl Unpin for Scope

§

impl UnwindSafe for Scope

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,

Source§

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>,

Source§

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>,

Source§

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,