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
impl Scope
Sourcepub fn device_properties(&self, properties: &DeviceProperties)
pub fn device_properties(&self, properties: &DeviceProperties)
Set the device properties.
pub fn state(&self) -> Ref<'_, GlobalStateInner>
pub fn state_mut(&self) -> RefMut<'_, GlobalStateInner>
Sourcepub fn root(debug_enabled: bool) -> Scope
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.
Sourcepub fn with_global_state(
self,
global_state: Rc<RefCell<GlobalStateInner>>,
) -> Scope
pub fn with_global_state( self, global_state: Rc<RefCell<GlobalStateInner>>, ) -> Scope
Use existing state.
Sourcepub fn create_value(&self, ty: Type) -> Value
pub fn create_value(&self, ty: Type) -> Value
Create a new immutable value of type specified by ty.
Sourcepub fn create_local_mut(&self, value_ty: impl Into<Type>) -> Value
pub fn create_local_mut(&self, value_ty: impl Into<Type>) -> Value
Create a new mutable local variable of type specified by value_ty.
Create a shared variable of the given item type.
Sourcepub fn create_function(&self, explicit_params: Vec<Value>, scope: Scope) -> u32
pub fn create_function(&self, explicit_params: Vec<Value>, scope: Scope) -> u32
Create a new function.
Sourcepub fn register<T>(&self, instruction: T)where
T: Into<Instruction>,
pub fn register<T>(&self, instruction: T)where
T: Into<Instruction>,
Register an Instruction into the scope.
Sourcepub fn create_kernel_ref<'a, T>(&self, value: T) -> &'a mut Twhere
T: 'a,
pub fn create_kernel_ref<'a, T>(&self, value: T) -> &'a mut Twhere
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.
Sourcepub fn resolve_type<T>(&self) -> Option<StorageType>where
T: 'static,
pub fn resolve_type<T>(&self) -> Option<StorageType>where
T: 'static,
Resolve the element type of the given generic type.
Sourcepub fn resolve_size<T>(&self) -> Option<usize>where
T: 'static,
pub fn resolve_size<T>(&self) -> Option<usize>where
T: 'static,
Resolve the comptime size of the given generic size.
Sourcepub fn register_type<T>(&self, elem: StorageType)where
T: 'static,
pub fn register_type<T>(&self, elem: StorageType)where
T: 'static,
Register the element type for the given generic type.
Sourcepub fn register_size<T>(&self, size: usize)where
T: 'static,
pub fn register_size<T>(&self, size: usize)where
T: 'static,
Register the comptime size for the given generic size.
pub fn push_error(&self, msg: impl Into<String>)
Sourcepub fn pop_errors(&self) -> Vec<String>
pub fn pop_errors(&self) -> Vec<String>
Returns all validation errors.
Sourcepub fn process<'a>(
&self,
processors: impl IntoIterator<Item = &'a dyn Processor>,
) -> ScopeProcessing
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.
pub fn new_local_index(&self) -> u32
Sourcepub fn tensor_map(&self, id: u32) -> Value
pub fn tensor_map(&self, id: u32) -> Value
Obtain the index-th tensor map
pub fn update_source(&self, source: CubeFnSource)
pub fn register_all(&self, instructions: impl IntoIterator<Item = Instruction>)
pub fn take_instructions(&self) -> Vec<Instruction>
pub fn update_span(&self, line: u32, col: u32)
pub fn update_value_name( &self, value: Value, name: impl Into<Cow<'static, str>>, )
pub fn extract_field(&self, aggregate: Value, ty: Type, field: usize) -> Value
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Scope
impl<'de> Deserialize<'de> for Scope
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Scope, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Scope, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
impl Eq for Scope
Source§impl Serialize for Scope
impl Serialize for Scope
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
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> 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
impl<T> CacheKey for T
impl<T> CacheValue for T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneExpand for Twhere
T: Clone,
impl<T> CloneExpand for Twhere
T: Clone,
fn __expand_clone_method(&self, _: &Scope) -> T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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