Skip to main content

Dialect

Trait Dialect 

Source
pub trait Dialect {
Show 23 methods // Required methods fn name(&self) -> &'static str; fn prologue(&self, layout: &Layout) -> String; fn epilogue(&self) -> &'static str; fn lit(&self, v: i64, signed: bool) -> String; fn index(&self, name: &str, idx: &str, is_buffer: bool) -> String; fn exec(&self, id: ExecId, signed: bool) -> Option<String>; fn binary( &self, op: BinaryOp, a: &str, b: &str, signed: bool, ) -> Option<String>; fn select(&self, cond: &str, a: &str, b: &str, signed: bool) -> String; fn temp(&self, name: &str, rhs: &str, signed: bool) -> String; fn bound(&self, name: &str, rhs: &str, signed: bool) -> String; fn barrier(&self, scope: Scope) -> Option<String>; fn fence(&self, scope: Scope, order: MemoryOrder) -> Option<String>; // Provided methods fn wide(&self) -> bool { ... } fn cast_to_compute(&self, _x: &str, _from: ElementKind) -> Option<String> { ... } fn arith(&self, op: ArithOp, a: &str, b: &str) -> Option<String> { ... } fn truthy(&self, value: &str, signed: bool) -> String { ... } fn atomic_rmw( &self, _op: AtomicOp, _elem: &str, _value: &str, ) -> Option<String> { ... } fn atomic_cas( &self, _elem: &str, _expected: &str, _desired: &str, ) -> Option<String> { ... } fn typed_atomics(&self) -> bool { ... } fn atomic_scope_ok(&self, _scope: Scope) -> bool { ... } fn atomic_load(&self, _elem: &str) -> Option<String> { ... } fn atomic_store(&self, _elem: &str, _value: &str) -> Option<String> { ... } fn atomic_cas_lines( &self, elem: &str, expected: &str, desired: &str, dest: Option<&str>, ) -> Option<Vec<String>> { ... }
}
Expand description

The spellings of one target language.

A method that cannot spell something returns None (or an Err text), and the walker turns that into a typed decline naming it; nothing is approximated.

Required Methods§

Source

fn name(&self) -> &'static str

The backend name used in decline texts (glsl, wgsl).

Source

fn prologue(&self, layout: &Layout) -> String

The header, buffer and shared declarations and the opening of the entry function, with the locals declared (one line each) at the top of the entry.

Source

fn epilogue(&self) -> &'static str

The closing of the entry function.

Source

fn lit(&self, v: i64, signed: bool) -> String

An integer literal in the compute dtype.

Source

fn index(&self, name: &str, idx: &str, is_buffer: bool) -> String

The element idx of the buffer or shared array name.

Source

fn exec(&self, id: ExecId, signed: bool) -> Option<String>

The spelling of an execution id, or None when the dialect has none.

Source

fn binary(&self, op: BinaryOp, a: &str, b: &str, signed: bool) -> Option<String>

A binary op on two integers, or None when there is no spelling.

Source

fn select(&self, cond: &str, a: &str, b: &str, signed: bool) -> String

cond != 0 ? a : b.

Source

fn temp(&self, name: &str, rhs: &str, signed: bool) -> String

A hoisted temporary declaration line (no indentation, no newline).

Source

fn bound(&self, name: &str, rhs: &str, signed: bool) -> String

The For counter’s bound and step constants, declared once before the loop.

Source

fn barrier(&self, scope: Scope) -> Option<String>

A statement that synchronizes scope (and orders memory), or None when there is none.

Source

fn fence(&self, scope: Scope, order: MemoryOrder) -> Option<String>

A memory fence at scope, or None when the dialect has none without a barrier.

Provided Methods§

Source

fn wide(&self) -> bool

Whether this dialect instance lowers 64-bit integer kernels (I64/U64). The default is no: such a kernel is then a typed decline naming the dialect. A dialect that says yes types every spelling at 64 bits and spells Self::cast_to_compute; an execution id stays the u32 the IR types it as, reached through a Cast.

Source

fn cast_to_compute(&self, _x: &str, _from: ElementKind) -> Option<String>

x, of integer type from, converted (wrapping) to the compute dtype, or None when there is no spelling. Only asked of a dialect whose Self::wide is true.

Source

fn arith(&self, op: ArithOp, a: &str, b: &str) -> Option<String>

a + b, a - b, a * b (wrapping); None for a division.

Source

fn truthy(&self, value: &str, signed: bool) -> String

A boolean spelling of value != 0.

Source

fn atomic_rmw(&self, _op: AtomicOp, _elem: &str, _value: &str) -> Option<String>

An expression applying atomic op to the element elem with value, giving the old value; None when the dialect has no spelling (the default).

Source

fn atomic_cas( &self, _elem: &str, _expected: &str, _desired: &str, ) -> Option<String>

An expression compare-exchanging the element elem, giving the value found; None when the dialect has no spelling (the default).

Source

fn typed_atomics(&self) -> bool

Whether the dialect declares an atomically accessed buffer or array with a different type (WGSL atomic<u32>), so plain access to it goes through Self::atomic_load / Self::atomic_store.

Source

fn atomic_scope_ok(&self, _scope: Scope) -> bool

Whether an atomic at scope can be spelled (the default: every scope).

Source

fn atomic_load(&self, _elem: &str) -> Option<String>

An expression reading the element elem of an atomically typed buffer or array.

Source

fn atomic_store(&self, _elem: &str, _value: &str) -> Option<String>

A statement writing value to the element elem of an atomically typed buffer or array.

Source

fn atomic_cas_lines( &self, elem: &str, expected: &str, desired: &str, dest: Option<&str>, ) -> Option<Vec<String>>

The lines compare-exchanging elem and writing the value found to dest, if any. The default is one assignment of Self::atomic_cas; a dialect whose exchange can fail spuriously overrides it with a retry loop, because the IR’s compare-exchange cannot.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§