For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).
Mojo function
selective_scan_update_gpu
def selective_scan_update_gpu[kernel_dtype: DType, DSTATE: Int, state_out_LT: TensorLayout, output_LT: TensorLayout, state_in_LT: TensorLayout, x_LT: TensorLayout, dt_LT: TensorLayout, A_LT: TensorLayout, B_LT: TensorLayout, C_LT: TensorLayout, D_LT: TensorLayout, z_LT: TensorLayout, dt_bias_LT: TensorLayout](total_batch_dim: Int32, batch: Int32, dim: Int32, group_size: Int32, delta_softplus: Int8, state_out: TileTensor[kernel_dtype, state_out_LT, MutUntrackedOrigin], output: TileTensor[kernel_dtype, output_LT, MutUntrackedOrigin], state_in: TileTensor[kernel_dtype, state_in_LT, MutUntrackedOrigin], x: TileTensor[kernel_dtype, x_LT, MutUntrackedOrigin], dt: TileTensor[kernel_dtype, dt_LT, MutUntrackedOrigin], A: TileTensor[kernel_dtype, A_LT, MutUntrackedOrigin], B: TileTensor[kernel_dtype, B_LT, MutUntrackedOrigin], C: TileTensor[kernel_dtype, C_LT, MutUntrackedOrigin], D: TileTensor[kernel_dtype, D_LT, MutUntrackedOrigin], z: TileTensor[kernel_dtype, z_LT, MutUntrackedOrigin], dt_bias: TileTensor[kernel_dtype, dt_bias_LT, MutUntrackedOrigin], state_out_strides: IndexList[Int(3)], output_strides: IndexList[Int(2)], state_in_strides: IndexList[Int(3)], x_strides: IndexList[Int(2)], dt_strides: IndexList[Int(2)], A_strides: IndexList[Int(2)], B_strides: IndexList[Int(3)], C_strides: IndexList[Int(3)], D_strides: IndexList[Int(1)], z_strides: IndexList[Int(2)], dt_bias_strides: IndexList[Int(1)])
GPU kernel for selective scan update (single step).
Each thread processes one (batch, dim) pair. Reads initial state from state_in, writes updated state to state_out.
Parameters:
- kernel_dtype (
DType): Element type of the input and output tensors. - DSTATE (
Int): Number of SSM state elements per (batch, dim) pair. - state_out_LT (
TensorLayout): Memory layout of thestate_outtensor. - output_LT (
TensorLayout): Memory layout of theoutputtensor. - state_in_LT (
TensorLayout): Memory layout of thestate_intensor. - x_LT (
TensorLayout): Memory layout of thexinput tensor. - dt_LT (
TensorLayout): Memory layout of thedttime-step tensor. - A_LT (
TensorLayout): Memory layout of theArecurrence matrix. - B_LT (
TensorLayout): Memory layout of theBinput projection tensor. - C_LT (
TensorLayout): Memory layout of theCoutput projection tensor. - D_LT (
TensorLayout): Memory layout of theDskip connection tensor. - z_LT (
TensorLayout): Memory layout of thezgating tensor. - dt_bias_LT (
TensorLayout): Memory layout of thedt_biastensor.
Args:
- total_batch_dim (
Int32): Total number of (batch, dim) pairs launched, equal tobatch * dim, used for thread bounds checking. - batch (
Int32): Number of sequences processed in parallel. - dim (
Int32): Hidden dimension, equal to the number of channels per sequence position. - group_size (
Int32): Number of dims per group; dims in the same group shareBandCinputs. - delta_softplus (
Int8): Nonzero appliessoftplustodtbefore the scan recurrence. - state_out (
TileTensor[kernel_dtype, state_out_LT, MutUntrackedOrigin]): Updated SSM state tensor of shape(batch, dim, DSTATE), written. - output (
TileTensor[kernel_dtype, output_LT, MutUntrackedOrigin]): Step output tensor of shape(batch, dim), written. - state_in (
TileTensor[kernel_dtype, state_in_LT, MutUntrackedOrigin]): Previous SSM state tensor of shape(batch, dim, DSTATE), read. - x (
TileTensor[kernel_dtype, x_LT, MutUntrackedOrigin]): Input value tensor of shape(batch, dim)for the current timestep, read. - dt (
TileTensor[kernel_dtype, dt_LT, MutUntrackedOrigin]): Time-step tensor of shape(batch, dim), read. - A (
TileTensor[kernel_dtype, A_LT, MutUntrackedOrigin]): SSM recurrence matrix of shape(dim, DSTATE), read. - B (
TileTensor[kernel_dtype, B_LT, MutUntrackedOrigin]): SSM input projection of shape(batch, n_groups, DSTATE), read. - C (
TileTensor[kernel_dtype, C_LT, MutUntrackedOrigin]): SSM output projection of shape(batch, n_groups, DSTATE), read. - D (
TileTensor[kernel_dtype, D_LT, MutUntrackedOrigin]): Skip connection vector of shape(dim,), read; added asD * xto the output when present. - z (
TileTensor[kernel_dtype, z_LT, MutUntrackedOrigin]): Gating tensor of shape(batch, dim), read; gates the output viaz * sigmoid(z)when present. - dt_bias (
TileTensor[kernel_dtype, dt_bias_LT, MutUntrackedOrigin]): Bias vector of shape(dim,), read; added todtbeforesoftpluswhen present. - state_out_strides (
IndexList[Int(3)]): 3D strides(batch, dim, DSTATE)for indexingstate_out. - output_strides (
IndexList[Int(2)]): 2D strides(batch, dim)for indexingoutput. - state_in_strides (
IndexList[Int(3)]): 3D strides(batch, dim, DSTATE)for indexingstate_in. - x_strides (
IndexList[Int(2)]): 2D strides(batch, dim)for indexingx. - dt_strides (
IndexList[Int(2)]): 2D strides(batch, dim)for indexingdt. - A_strides (
IndexList[Int(2)]): 2D strides(dim, DSTATE)for indexingA. - B_strides (
IndexList[Int(3)]): 3D strides(batch, n_groups, DSTATE)for indexingB. - C_strides (
IndexList[Int(3)]): 3D strides(batch, n_groups, DSTATE)for indexingC. - D_strides (
IndexList[Int(1)]): 1D strides(dim,)for indexingD. - z_strides (
IndexList[Int(2)]): 2D strides(batch, dim)for indexingz. - dt_bias_strides (
IndexList[Int(1)]): 1D strides(dim,)for indexingdt_bias.