Skip to main content

LlvmTriton

Struct LlvmTriton 

Source
pub struct LlvmTriton {}
Expand description

A host-side, type-check-only implementation of Triton: every method returns a dummy zero/null value rather than executing real logic. This lets kernel bodies written against the Triton trait compile and type-check on the host; the real computation only happens when the same DSL source is compiled through the teenyc/--frontend=triton path (see the crate docs).

Trait Implementations§

Source§

impl Triton for LlvmTriton

Source§

type BoolTensor = LlvmTensor<bool>

A tensor of bool, produced by comparisons and used as a mask.
Source§

type I32Tensor = LlvmTensor<i32>

A tensor of i32, e.g. produced by Triton::arange.
Source§

type Tensor<D: Dtype> = LlvmTensor<D>

A tensor of dtype D.
Source§

type Pointer<D: Dtype> = LlvmPointer<D>

A device pointer to elements of dtype D.
Source§

fn program_id(_axis: Axis) -> i32

The current program’s index along axis within the launch grid.
Source§

fn num_programs(_axis: Axis) -> i32

The total number of programs launched along axis.
Source§

fn load_scalar_f32_as_i32(_ptr: Self::Pointer<f32>, _offset: i32) -> i32

Scalar gather: load the f32 at ptr + offset, truncate to i32, and return it as a plain Rust i32 usable in scalar arithmetic (e.g. as an addend to arange results via I32Tensor + i32). Read more
Source§

fn arange(_start: impl Into<i32>, _end: impl Into<i32>) -> Self::I32Tensor

Create a 1-D i32 tensor with values [start, start+1, ..., end-1].
Source§

fn arange_f32(_start: impl Into<i32>, _end: impl Into<i32>) -> Self::Tensor<f32>

Create a 1-D f32 tensor with values [start as f32, start+1, ..., end-1]. Read more
Source§

fn zeros<D: Dtype>(_shape: &[i32]) -> Self::Tensor<D>

Create a tensor of the given shape filled with zeros.
Source§

fn zeros_like<D: Dtype>(_x: Self::Tensor<D>) -> Self::Tensor<D>

Create a zero-filled tensor with the same shape/dtype as x.
Source§

fn full<D: Dtype>(_shape: &[i32], _value: D) -> Self::Tensor<D>

Create a tensor of the given shape filled with value.
Source§

fn cast<Src: Dtype, Dst: Dtype>( _x: Self::Tensor<Src>, _fp_downcast_rounding: Option<FpDowncastRounding>, _bitcast: bool, ) -> Self::Tensor<Dst>

Cast a tensor to a different dtype. Read more
Source§

fn cat<D: Dtype>( _a: Self::Tensor<D>, _b: Self::Tensor<D>, _can_reorder: bool, ) -> Self::Tensor<D>

Concatenate two tensors. Read more
Source§

fn broadcast<D: Dtype>( _a: Self::Tensor<D>, _b: Self::Tensor<D>, ) -> (Self::Tensor<D>, Self::Tensor<D>)

Broadcast two tensors to a common compatible shape.
Source§

fn broadcast_to<D: Dtype>( _x: Self::Tensor<D>, _shape: &[i32], ) -> Self::Tensor<D>

Broadcast x to shape.
Source§

fn expand_dims<D: Dtype>(_x: Self::Tensor<D>, _axis: i32) -> Self::Tensor<D>

Insert a size-1 dimension at axis.
Source§

fn permute<D: Dtype>(_x: Self::Tensor<D>, _dims: &[i32]) -> Self::Tensor<D>

Permute x’s dimensions according to dims.
Source§

fn reshape<D: Dtype>( _x: Self::Tensor<D>, _shape: &[i32], _can_reorder: bool, ) -> Self::Tensor<D>

Reshape a tensor. Read more
Source§

fn trans<D: Dtype>(_x: Self::Tensor<D>, _dims: &[i32]) -> Self::Tensor<D>

Permute dimensions. Alias for permute.
Source§

fn ravel<D: Dtype>(_x: Self::Tensor<D>, _can_reorder: bool) -> Self::Tensor<D>

Flatten to 1-D. Read more
Source§

fn view<D: Dtype>(_x: Self::Tensor<D>, _shape: &[i32]) -> Self::Tensor<D>

View with a new shape (order not preserved).
Source§

fn join<D: Dtype>(_a: Self::Tensor<D>, _b: Self::Tensor<D>) -> Self::Tensor<D>

Join two tensors along a new minor dimension.
Source§

fn interleave<D: Dtype>( _a: Self::Tensor<D>, _b: Self::Tensor<D>, ) -> Self::Tensor<D>

Interleave two tensors along their last dimension.
Source§

fn split<D: Dtype>(_x: Self::Tensor<D>) -> (Self::Tensor<D>, Self::Tensor<D>)

Split a tensor in two along its last dimension (which must have size 2).
Source§

fn dot_scaled<D: Num, S: Num, O: Num>( _lhs: Self::Tensor<D>, _lhs_scale: Self::Tensor<S>, _lhs_format: DotFormat, _rhs: Self::Tensor<D>, _rhs_scale: Self::Tensor<S>, _rhs_format: DotFormat, _acc: Option<Self::Tensor<O>>, _fast_math: bool, ) -> Self::Tensor<O>

Scaled mixed-precision matrix multiply (FP8 / narrow formats). Read more
Source§

fn dot<D: Num, O: Num>( _a: Self::Tensor<D>, _b: Self::Tensor<D>, _acc: Option<Self::Tensor<O>>, _input_precision: Option<InputPrecision>, _max_num_imprecise_acc: Option<i32>, ) -> Self::Tensor<O>

Matrix (or batched matrix) multiply. Read more
Source§

fn make_block_ptr<D: Dtype>( _base: Self::Pointer<D>, _shape: &[i32], _strides: &[i32], _offsets: &[i32], _block_shape: &[i32], _order: &[i32], ) -> Self::Pointer<D>

Create a block pointer encoding shape, strides, offsets, and tile shape.
Source§

fn advance<D: Dtype>( _ptr: Self::Pointer<D>, _offsets: &[i32], ) -> Self::Pointer<D>

Advance a block pointer by the given per-dimension offsets.
Source§

fn make_tensor_descriptor<D: Dtype>( _base: Self::Pointer<D>, _shape: &[i32], _strides: &[i32], _block_shape: &[i32], _padding_option: Option<PaddingOption>, ) -> Self::Pointer<D>

Create a tensor descriptor for TMA (Tensor Memory Accelerator) operations. Read more
Source§

fn load_tensor_descriptor<D: Dtype>( _desc: Self::Pointer<D>, _offsets: &[i32], ) -> Self::Tensor<D>

Load a tile from memory using a tensor descriptor and per-dimension offsets.
Source§

fn store_tensor_descriptor<D: Dtype>( _desc: Self::Pointer<D>, _offsets: &[i32], _value: Self::Tensor<D>, )

Store a tile to memory using a tensor descriptor and per-dimension offsets.
Source§

fn load<D: Dtype, const N: usize>( _ptr: Self::Tensor<Self::Pointer<D>>, _mask: Option<Self::BoolTensor>, _other: Option<Self::Tensor<D>>, _boundary_check: &[i32; N], _padding_option: Option<PaddingOption>, _cache_modifier: Option<CacheModifier>, _eviction_policy: Option<EvictionPolicy>, _volatile: bool, ) -> Self::Tensor<D>

Load a tensor from memory. Read more
Source§

fn store<D: Dtype, const N: usize>( _dest: Self::Tensor<Self::Pointer<D>>, _src: Self::Tensor<D>, _mask: Option<Self::BoolTensor>, _boundary_check: &[i32; N], _cache_modifier: Option<CacheModifier>, _eviction_policy: Option<EvictionPolicy>, )

Store a tensor to memory. Read more
Source§

fn lt<D: Num>(_x: Self::Tensor<D>, _y: Self::Tensor<D>) -> Self::BoolTensor

Element-wise less-than between two tensors.
Source§

fn le<D: Num>(_x: Self::Tensor<D>, _y: Self::Tensor<D>) -> Self::BoolTensor

Element-wise less-than-or-equal between two tensors.
Source§

fn gt<D: Num>(_x: Self::Tensor<D>, _y: Self::Tensor<D>) -> Self::BoolTensor

Element-wise greater-than between two tensors.
Source§

fn ge<D: Num>(_x: Self::Tensor<D>, _y: Self::Tensor<D>) -> Self::BoolTensor

Element-wise greater-than-or-equal between two tensors.
Source§

fn eq<D: Num>(_x: Self::Tensor<D>, _y: Self::Tensor<D>) -> Self::BoolTensor

Element-wise equality between two tensors.
Source§

fn ne<D: Num>(_x: Self::Tensor<D>, _y: Self::Tensor<D>) -> Self::BoolTensor

Element-wise inequality between two tensors.
Source§

fn lt_scalar<D: Num>(_x: Self::Tensor<D>, _y: D) -> Self::BoolTensor

Element-wise less-than against a scalar.
Source§

fn le_scalar<D: Num>(_x: Self::Tensor<D>, _y: D) -> Self::BoolTensor

Element-wise less-than-or-equal against a scalar.
Source§

fn gt_scalar<D: Num>(_x: Self::Tensor<D>, _y: D) -> Self::BoolTensor

Element-wise greater-than against a scalar.
Source§

fn ge_scalar<D: Num>(_x: Self::Tensor<D>, _y: D) -> Self::BoolTensor

Element-wise greater-than-or-equal against a scalar.
Source§

fn eq_scalar<D: Num>(_x: Self::Tensor<D>, _y: D) -> Self::BoolTensor

Element-wise equality against a scalar.
Source§

fn ne_scalar<D: Num>(_x: Self::Tensor<D>, _y: D) -> Self::BoolTensor

Element-wise inequality against a scalar.
Source§

fn where_<D: Dtype>( _cond: Self::BoolTensor, _x: Self::Tensor<D>, _y: Self::Tensor<D>, ) -> Self::Tensor<D>

Conditional element selection — corresponds to tl.where. Named where_ to avoid collision with the Rust keyword where.
Source§

fn flip<D: Dtype>(_x: Self::Tensor<D>, _dim: Option<i32>) -> Self::Tensor<D>

Reverse a tensor along dim. None reverses all dimensions.
Source§

fn gather<D: Dtype>( _src: Self::Tensor<D>, _index: Self::I32Tensor, _axis: i32, ) -> Self::Tensor<D>

Gather elements from src along axis using index.
Source§

fn abs<D: Dtype>(_x: Self::Tensor<D>) -> Self::Tensor<D>

Element-wise absolute value.
Source§

fn ceil<D: Float>(_x: Self::Tensor<D>) -> Self::Tensor<D>

Element-wise ceiling.
Source§

fn floor<D: Float>(_x: Self::Tensor<D>) -> Self::Tensor<D>

Element-wise floor.
Source§

fn cos<D: Float>(_x: Self::Tensor<D>) -> Self::Tensor<D>

Element-wise cosine.
Source§

fn sin<D: Float>(_x: Self::Tensor<D>) -> Self::Tensor<D>

Element-wise sine.
Source§

fn exp<D: Float>(_x: Self::Tensor<D>) -> Self::Tensor<D>

Element-wise natural exponential (e^x).
Source§

fn exp2<D: Float>(_x: Self::Tensor<D>) -> Self::Tensor<D>

Element-wise base-2 exponential (2^x).
Source§

fn log<D: Float>(_x: Self::Tensor<D>) -> Self::Tensor<D>

Element-wise natural logarithm.
Source§

fn log2<D: Float>(_x: Self::Tensor<D>) -> Self::Tensor<D>

Element-wise base-2 logarithm.
Source§

fn rsqrt<D: Float>(_x: Self::Tensor<D>) -> Self::Tensor<D>

Element-wise reciprocal square root (1/sqrt(x)).
Source§

fn sigmoid<D: Float>(_x: Self::Tensor<D>) -> Self::Tensor<D>

Element-wise sigmoid (1/(1+e^-x)).
Source§

fn sqrt<D: Float>(_x: Self::Tensor<D>) -> Self::Tensor<D>

Element-wise square root.
Source§

fn sqrt_rn<D: Float>(_x: Self::Tensor<D>) -> Self::Tensor<D>

Element-wise square root, round-to-nearest.
Source§

fn erf<D: Float>(_x: Self::Tensor<D>) -> Self::Tensor<D>

Element-wise error function.
Source§

fn atan<D: Float>(_x: Self::Tensor<D>) -> Self::Tensor<D>

Element-wise arctangent.
Source§

fn softmax<D: Float>( _x: Self::Tensor<D>, _dim: Option<i32>, _keep_dims: bool, _ieee_rounding: bool, ) -> Self::Tensor<D>

Numerically-stable softmax along dim. dim = None defaults to the last dimension. Read more
Source§

fn maximum<D: Num>(_x: Self::Tensor<D>, _y: Self::Tensor<D>) -> Self::Tensor<D>

Element-wise maximum of two tensors.
Source§

fn minimum<D: Num>(_x: Self::Tensor<D>, _y: Self::Tensor<D>) -> Self::Tensor<D>

Element-wise minimum of two tensors.
Source§

fn clamp<D: Num>( _x: Self::Tensor<D>, _lo: Self::Tensor<D>, _hi: Self::Tensor<D>, ) -> Self::Tensor<D>

Element-wise clamp of x to [lo, hi].
Source§

fn fma<D: Float>( _x: Self::Tensor<D>, _y: Self::Tensor<D>, _z: Self::Tensor<D>, ) -> Self::Tensor<D>

Element-wise fused multiply-add: x * y + z.
Source§

fn fdiv<D: Float>( _x: Self::Tensor<D>, _y: Self::Tensor<D>, _ieee_rounding: bool, ) -> Self::Tensor<D>

Element-wise floating-point division. Read more
Source§

fn div_rn<D: Float>(_x: Self::Tensor<D>, _y: Self::Tensor<D>) -> Self::Tensor<D>

Element-wise division, round-to-nearest.
Source§

fn umulhi(_x: Self::Tensor<u32>, _y: Self::Tensor<u32>) -> Self::Tensor<u32>

Element-wise high 32 bits of an unsigned 32×32→64-bit multiply.
Source§

fn cdiv(_x: i32, _div: i32) -> i32

Ceiling integer division: ceil(x / div).
Source§

fn swizzle2d( _i: i32, _j: i32, _size_i: i32, _size_j: i32, _size_g: i32, ) -> (i32, i32)

Swizzle 2-D indices for shared-memory bank-conflict avoidance. Returns the remapped (i, j) indices.
Source§

fn sum<D: Num>( _x: Self::Tensor<D>, _axis: Option<i32>, _keep_dims: bool, ) -> Self::Tensor<D>

Sum all elements along axis. axis = None reduces all dimensions.
Source§

fn max<D: Num>( _x: Self::Tensor<D>, _axis: Option<i32>, _keep_dims: bool, ) -> Self::Tensor<D>

Maximum along axis. axis = None reduces all dimensions.
Source§

fn max_with_indices<D: Num>( _x: Self::Tensor<D>, _axis: i32, _tie_break_left: bool, _keep_dims: bool, ) -> (Self::Tensor<D>, Self::I32Tensor)

Maximum along axis, also returning the index of the maximum. Read more
Source§

fn min<D: Num>( _x: Self::Tensor<D>, _axis: Option<i32>, _keep_dims: bool, ) -> Self::Tensor<D>

Minimum along axis. axis = None reduces all dimensions.
Source§

fn min_with_indices<D: Num>( _x: Self::Tensor<D>, _axis: i32, _tie_break_left: bool, _keep_dims: bool, ) -> (Self::Tensor<D>, Self::I32Tensor)

Minimum along axis, also returning the index of the minimum. Read more
Source§

fn argmax<D: Num>( _x: Self::Tensor<D>, _axis: i32, _tie_break_left: bool, _keep_dims: bool, ) -> Self::I32Tensor

Index of the maximum along axis. Read more
Source§

fn argmin<D: Num>( _x: Self::Tensor<D>, _axis: i32, _tie_break_left: bool, _keep_dims: bool, ) -> Self::I32Tensor

Index of the minimum along axis. Read more
Source§

fn xor_sum<D: Int>( _x: Self::Tensor<D>, _axis: Option<i32>, _keep_dims: bool, ) -> Self::Tensor<D>

XOR-reduction along axis. axis = None reduces all dimensions.
Source§

fn cumsum<D: Num>( _x: Self::Tensor<D>, _axis: i32, _reverse: bool, ) -> Self::Tensor<D>

Cumulative sum along axis.
Source§

fn cumprod<D: Num>( _x: Self::Tensor<D>, _axis: i32, _reverse: bool, ) -> Self::Tensor<D>

Cumulative product along axis.
Source§

fn sort<D: Num>( _x: Self::Tensor<D>, _dim: Option<i32>, _descending: bool, ) -> Self::Tensor<D>

Sort along dim. dim = None sorts along the last dimension.
Source§

fn histogram( _x: Self::I32Tensor, _num_bins: i32, _mask: Option<Self::BoolTensor>, ) -> Self::I32Tensor

Compute a histogram with num_bins bins (width 1, starting at 0). Read more
Source§

fn reduce<D: Dtype, O: Dtype>( _x: Self::Tensor<D>, _axis: i32, _combine_fn: fn(Self::Tensor<O>, Self::Tensor<O>) -> Self::Tensor<O>, _keep_dims: bool, ) -> Self::Tensor<O>

Generic reduction along axis using a user-supplied combine function. Read more
Source§

fn associative_scan<D: Dtype>( _x: Self::Tensor<D>, _axis: i32, _combine_fn: fn(Self::Tensor<D>, Self::Tensor<D>) -> Self::Tensor<D>, _reverse: bool, ) -> Self::Tensor<D>

Generic prefix-scan along axis using a user-supplied combine function. Read more
Source§

fn atomic_add<D: Num>( _ptr: Self::Tensor<Self::Pointer<D>>, _val: Self::Tensor<D>, _mask: Option<Self::BoolTensor>, _sem: Option<MemSem>, _scope: Option<MemScope>, ) -> Self::Tensor<D>

Atomic add. Returns the previous value. Read more
Source§

fn atomic_and<D: Int>( _ptr: Self::Tensor<Self::Pointer<D>>, _val: Self::Tensor<D>, _mask: Option<Self::BoolTensor>, _sem: Option<MemSem>, _scope: Option<MemScope>, ) -> Self::Tensor<D>

Atomic bitwise AND. Returns the previous value. See Triton::atomic_add for parameters.
Source§

fn atomic_or<D: Int>( _ptr: Self::Tensor<Self::Pointer<D>>, _val: Self::Tensor<D>, _mask: Option<Self::BoolTensor>, _sem: Option<MemSem>, _scope: Option<MemScope>, ) -> Self::Tensor<D>

Atomic bitwise OR. Returns the previous value. See Triton::atomic_add for parameters.
Source§

fn atomic_xor<D: Int>( _ptr: Self::Tensor<Self::Pointer<D>>, _val: Self::Tensor<D>, _mask: Option<Self::BoolTensor>, _sem: Option<MemSem>, _scope: Option<MemScope>, ) -> Self::Tensor<D>

Atomic bitwise XOR. Returns the previous value. See Triton::atomic_add for parameters.
Source§

fn atomic_max<D: Num>( _ptr: Self::Tensor<Self::Pointer<D>>, _val: Self::Tensor<D>, _mask: Option<Self::BoolTensor>, _sem: Option<MemSem>, _scope: Option<MemScope>, ) -> Self::Tensor<D>

Atomic maximum. Returns the previous value. See Triton::atomic_add for parameters.
Source§

fn atomic_min<D: Num>( _ptr: Self::Tensor<Self::Pointer<D>>, _val: Self::Tensor<D>, _mask: Option<Self::BoolTensor>, _sem: Option<MemSem>, _scope: Option<MemScope>, ) -> Self::Tensor<D>

Atomic minimum. Returns the previous value. See Triton::atomic_add for parameters.
Source§

fn atomic_xchg<D: Dtype>( _ptr: Self::Tensor<Self::Pointer<D>>, _val: Self::Tensor<D>, _mask: Option<Self::BoolTensor>, _sem: Option<MemSem>, _scope: Option<MemScope>, ) -> Self::Tensor<D>

Atomic exchange. Returns the previous value. See Triton::atomic_add for parameters.
Source§

fn atomic_cas<D: Dtype>( _ptr: Self::Tensor<Self::Pointer<D>>, _cmp: Self::Tensor<D>, _val: Self::Tensor<D>, _sem: Option<MemSem>, _scope: Option<MemScope>, ) -> Self::Tensor<D>

Atomic compare-and-swap. Returns the previous value.
Source§

fn rand( _seed: u32, _offsets: Self::I32Tensor, _n_rounds: i32, ) -> Self::Tensor<f32>

Uniform random f32 in [0, 1). Read more
Source§

fn randn( _seed: u32, _offsets: Self::I32Tensor, _n_rounds: i32, ) -> Self::Tensor<f32>

Standard-normal random f32. Read more
Source§

fn randint( _seed: u32, _offsets: Self::I32Tensor, _n_rounds: i32, ) -> Self::I32Tensor

Random i32. Read more
Source§

fn randint4x( _seed: u32, _offsets: Self::I32Tensor, _n_rounds: i32, ) -> (Self::I32Tensor, Self::I32Tensor, Self::I32Tensor, Self::I32Tensor)

Four random i32 streams (maximally efficient Philox entry point). Read more
Source§

fn multiple_of<D: Dtype>(x: Self::Tensor<D>, _values: &[i32]) -> Self::Tensor<D>

Hint that values of x are always multiples of the given constants.
Source§

fn max_contiguous<D: Dtype>( x: Self::Tensor<D>, _values: &[i32], ) -> Self::Tensor<D>

Hint that x has values[i] contiguous elements along dimension i.
Source§

fn max_constancy<D: Dtype>( x: Self::Tensor<D>, _values: &[i32], ) -> Self::Tensor<D>

Hint that x has values[i] constant elements along dimension i.
Source§

fn inline_asm_elementwise<D: Dtype>( _asm: &str, _constraints: &str, _is_pure: bool, _pack: i32, ) -> Self::Tensor<D>

Emit inline PTX/assembly applied element-wise across a tensor. Read more
Source§

fn assume(_cond: Self::BoolTensor)

Assert that cond is always true, allowing the compiler to assume so.
Source§

fn debug_barrier()

Insert a memory barrier for debugging purposes.
Source§

fn device_assert( _cond: Self::BoolTensor, _msg: &str, _mask: Option<Self::BoolTensor>, )

Emit a runtime assertion on the device. No-op when cond is true. Read more
Source§

fn device_print<D: Dtype>(_prefix: &str, _val: Self::Tensor<D>, _hex: bool)

Print a tensor value from device code for debugging. Read more
Source§

fn static_assert(_cond: bool, _msg: &str)

Compile-time assertion (evaluated before kernel launch).
Source§

fn static_print(_msg: &str)

Compile-time print (evaluated before kernel launch).

Auto Trait Implementations§

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> 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> Same for T

Source§

type Output = T

Should always be Self
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.