Skip to main content

Dialect

Trait Dialect 

Source
pub trait Dialect {
Show 35 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 float_refusal(&self) -> Option<&'static str> { ... } fn float(&self) -> bool { ... } fn double(&self) -> bool { ... } fn half(&self) -> bool { ... } fn mixed_float_widths(&self) -> bool { ... } fn lit_float(&self, _v: f64) -> Option<String> { ... } fn convert( &self, _x: &str, _from: ElementKind, _to: ElementKind, _round: RoundMode, ) -> Option<String> { ... } fn float_unary(&self, _op: UnaryOp, _x: &str) -> Option<String> { ... } fn float_minmax(&self, _is_max: bool, _a: &str, _b: &str) -> Option<String> { ... } fn type_name(&self, _t: ElementKind) -> Option<String> { ... } fn truthy_of(&self, value: &str, _t: ElementKind) -> String { ... } fn temp_typed(&self, ty: &str, name: &str, rhs: &str) -> String { ... } 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 float_refusal(&self) -> Option<&'static str>

Why this dialect cannot lower a float kernel at all, named in the decline of one (None: no reason beyond the generic one). Only asked of a dialect whose Self::float is false.

Source

fn float(&self) -> bool

Whether this dialect instance lowers float kernels (F32, or F64 when Self::double). The default is no: such a kernel is then a typed decline naming the dialect. A dialect that says yes spells Self::lit_float, Self::float_unary and Self::float_minmax, keeps every float add, subtract and multiply unfused (Self::temp_typed) and keeps an execution id the u32 the IR types it as.

Source

fn double(&self) -> bool

Whether the float kernel this instance lowers is F64 rather than F32 (only asked when Self::float is true).

Source

fn half(&self) -> bool

Whether the float kernel this instance lowers is F16 (only asked when Self::float is true): literals must then be exact halves.

Source

fn mixed_float_widths(&self) -> bool

Whether one kernel may use float types of two widths (F32 and F64 together). The default is yes; a dialect whose float-control declarations cannot name two widths says no, and such a kernel is a typed decline.

Source

fn lit_float(&self, _v: f64) -> Option<String>

A float literal for v, already known to be a finite value exact at the kernel’s float width, or None.

Source

fn convert( &self, _x: &str, _from: ElementKind, _to: ElementKind, _round: RoundMode, ) -> Option<String>

x of type from converted to to (both F32, F64, I32 or U32 in a float kernel), the rounding of a float to integer conversion being round; the walker has already checked the combination is one it lowers. A float to integer conversion maps NaN to 0 and clamps to the destination range, an integer to float or float narrowing rounds to nearest even.

Source

fn float_unary(&self, _op: UnaryOp, _x: &str) -> Option<String>

A float unary op on x, or None when there is no exact spelling (the walker declines by name).

Source

fn float_minmax(&self, _is_max: bool, _a: &str, _b: &str) -> Option<String>

NaN-propagating max (is_max) or min of a and b, a on ties; None when not spelled.

Source

fn type_name(&self, _t: ElementKind) -> Option<String>

The type name of t in a float kernel (float, uint, int), or None.

Source

fn truthy_of(&self, value: &str, _t: ElementKind) -> String

A boolean spelling of value != 0 for a value of element type t in a float kernel (a float compares against a float zero, an integer leaf against an integer zero).

Source

fn temp_typed(&self, ty: &str, name: &str, rhs: &str) -> String

A hoisted temporary of type ty (from Self::type_name) holding rhs. A float one must be one a compiler may not fuse or reassociate the operations of (GLSL precise): the value of a float expression is pinned in such a temporary before it is stored.

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§