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_fwd_gpu_minimal
def selective_scan_fwd_gpu_minimal[kernel_dtype: DType, DSTATE: Int, output_LT: TensorLayout, x_LT: TensorLayout, u_LT: TensorLayout, delta_LT: TensorLayout, A_LT: TensorLayout, B_LT: TensorLayout, C_LT: TensorLayout](total_batch_dim: Int32, batch: Int32, dim: Int32, seqlen: Int32, group_size: Int32, delta_softplus: Int8, output: TileTensor[kernel_dtype, output_LT, MutUntrackedOrigin], x: TileTensor[kernel_dtype, x_LT, MutUntrackedOrigin], u: TileTensor[kernel_dtype, u_LT, MutUntrackedOrigin], delta: TileTensor[kernel_dtype, delta_LT, MutUntrackedOrigin], A: TileTensor[kernel_dtype, A_LT, MutUntrackedOrigin], B: TileTensor[kernel_dtype, B_LT, MutUntrackedOrigin], C: TileTensor[kernel_dtype, C_LT, MutUntrackedOrigin], output_strides: IndexList[Int(3)], x_strides: IndexList[Int(4)], u_strides: IndexList[Int(3)], delta_strides: IndexList[Int(3)], A_strides: IndexList[Int(2)], B_strides: IndexList[Int(4)], C_strides: IndexList[Int(4)])
Minimal GPU kernel for selective scan forward - no D, z, or delta_bias.
Each thread processes one (batch, dim) pair and iterates through the
sequence. Omits the D skip connection, z gating, and delta_bias
supported by selective_scan_fwd_gpu.
Parameters:
- kernel_dtype (
DType): Element type of the input and output tensors. - DSTATE (
Int): Number of SSM state elements per (batch, dim) pair. - output_LT (
TensorLayout): Memory layout of theoutputtensor. - x_LT (
TensorLayout): Memory layout of thexcheckpoint tensor. - u_LT (
TensorLayout): Memory layout of theuinput tensor. - delta_LT (
TensorLayout): Memory layout of thedeltatime-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.
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. - seqlen (
Int32): Number of timesteps in each sequence. - group_size (
Int32): Number of dims per group; dims in the same group shareBandCinputs. - delta_softplus (
Int8): Nonzero appliessoftplustodeltabefore the scan recurrence. - output (
TileTensor[kernel_dtype, output_LT, MutUntrackedOrigin]): Output tensor of shape(batch, dim, seqlen), written. - x (
TileTensor[kernel_dtype, x_LT, MutUntrackedOrigin]): Checkpoint tensor of shape(batch, dim, n_chunks, 2*DSTATE)storing per-chunk cumulativeAandBvalues, written. - u (
TileTensor[kernel_dtype, u_LT, MutUntrackedOrigin]): Selective scan input tensor of shape(batch, dim, seqlen), read. - delta (
TileTensor[kernel_dtype, delta_LT, MutUntrackedOrigin]): Time-step tensor of shape(batch, dim, seqlen), 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, seqlen), read. - C (
TileTensor[kernel_dtype, C_LT, MutUntrackedOrigin]): SSM output projection of shape(batch, n_groups, DSTATE, seqlen), read. - output_strides (
IndexList[Int(3)]): 3D strides(batch, dim, seqlen)for indexingoutput. - x_strides (
IndexList[Int(4)]): 4D strides(batch, dim, n_chunks, 2*DSTATE)for indexingx. - u_strides (
IndexList[Int(3)]): 3D strides(batch, dim, seqlen)for indexingu. - delta_strides (
IndexList[Int(3)]): 3D strides(batch, dim, seqlen)for indexingdelta. - A_strides (
IndexList[Int(2)]): 2D strides(dim, DSTATE)for indexingA. - B_strides (
IndexList[Int(4)]): 4D strides(batch, n_groups, DSTATE, seqlen)for indexingB. - C_strides (
IndexList[Int(4)]): 4D strides(batch, n_groups, DSTATE, seqlen)for indexingC.