Skip to main content

Scope

Struct Scope 

Source
pub struct Scope {
    pub depth: u8,
    pub instructions: RefCell<Vec<Instruction>>,
    pub return_value: Option<Value>,
    pub locals: RefCell<Vec<Value>>,
    pub debug: DebugInfo,
    pub global_state: Rc<RefCell<GlobalStateInner>>,
    /* private fields */
}
Expand description

The scope is the main crate::Operation and crate::Value 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§instructions: RefCell<Vec<Instruction>>§return_value: Option<Value>§locals: RefCell<Vec<Value>>§debug: DebugInfo§global_state: Rc<RefCell<GlobalStateInner>>

Implementations§

Source§

impl Scope

Source

pub fn device_properties(&self, properties: &DeviceProperties)

Set the device properties.

Source

pub fn state(&self) -> Ref<'_, GlobalStateInner>

Source

pub fn state_mut(&self) -> RefMut<'_, GlobalStateInner>

Source

pub fn root(debug_enabled: bool) -> Scope

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 with_global_state( self, global_state: Rc<RefCell<GlobalStateInner>>, ) -> Scope

Use existing state.

Source

pub fn create_value(&self, ty: Type) -> Value

Create a new immutable value of type specified by ty.

Source

pub fn create_local_mut(&self, value_ty: impl Into<Type>) -> Value

Create a new mutable local variable of type specified by value_ty.

Source

pub fn create_shared( &self, value_ty: impl Into<Type>, alignment: Option<usize>, ) -> Value

Create a shared variable of the given item type.

Source

pub fn create_function(&self, explicit_params: Vec<Value>, scope: Scope) -> u32

Create a new function.

Source

pub fn register<T>(&self, instruction: T)
where T: Into<Instruction>,

Register an Instruction into the scope.

Source

pub fn create_kernel_ref<'a, T>(&self, value: T) -> &'a mut T
where T: 'a,

Add a value to the global arena so we can create a kernel-wide reference to it. The reference is the same as the type for simplicity, but is only valid for the duration of the root scope. Ensure the reference lifetime is shortened to the lifetime of the underlying variable being referenced.

Source

pub fn resolve_type<T>(&self) -> Option<StorageType>
where T: 'static,

Resolve the element type of the given generic type.

Source

pub fn resolve_size<T>(&self) -> Option<usize>
where T: 'static,

Resolve the comptime size of the given generic size.

Source

pub fn register_type<T>(&self, elem: StorageType)
where T: 'static,

Register the element type for the given generic type.

Source

pub fn register_size<T>(&self, size: usize)
where T: 'static,

Register the comptime size for the given generic size.

Source

pub fn child(&self) -> Scope

Create an empty child scope.

Source

pub fn push_error(&self, msg: impl Into<String>)

Source

pub fn pop_errors(&self) -> Vec<String>

Returns all validation errors.

Source

pub fn process<'a>( &self, processors: impl IntoIterator<Item = &'a dyn Processor>, ) -> ScopeProcessing

Returns the operations to be declared and executed.

Notes:

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

Source

pub fn new_local_index(&self) -> u32

Source

pub fn global(&self, id: u32, value_ty: Type) -> Value

Obtain the index-th buffer

Source

pub fn tensor_map(&self, id: u32) -> Value

Obtain the index-th tensor map

Source

pub fn update_source(&self, source: CubeFnSource)

Source

pub fn register_all(&self, instructions: impl IntoIterator<Item = Instruction>)

Source

pub fn take_instructions(&self) -> Vec<Instruction>

Source

pub fn update_span(&self, line: u32, col: u32)

Source

pub fn update_value_name( &self, value: Value, name: impl Into<Cow<'static, str>>, )

Source

pub fn extract_field(&self, aggregate: Value, ty: Type, field: usize) -> Value

Trait Implementations§

Source§

impl Clone for Scope

Source§

fn clone(&self) -> Scope

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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<(), Error>

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

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

Source§

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

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

impl Display for Scope

Source§

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

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

impl Eq for Scope

Source§

impl Hash for Scope

Source§

fn hash<H>(&self, ra_expand_state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Scope

Source§

fn eq(&self, __other: &Scope) -> bool

Equality operator ==. Read more
Source§

fn ne(&self, __other: &Scope) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Scope

Source§

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

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

impl TypeHash for Scope

Source§

fn write_hash(hasher: &mut impl Hasher)

Write the structure of the type to the hasher
Source§

fn type_hash() -> u64

Generate a stable hash of the type structure. Read more

Auto Trait Implementations§

§

impl !Freeze for Scope

§

impl !RefUnwindSafe for Scope

§

impl !Send for Scope

§

impl !Sync for Scope

§

impl !UnwindSafe for Scope

§

impl Unpin for Scope

§

impl UnsafeUnpin 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> CacheKey for T

Source§

impl<T> CacheValue for T

Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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

Source§

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> IntoComptime for T

Source§

fn comptime(self) -> Self

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.