For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/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: Int, batch: Int, dim: Int, seqlen: Int, group_size: Int, 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 (
Int): Total number of (batch, dim) pairs launched, equal tobatch * dim, used for thread bounds checking. - βbatch (
Int): Number of sequences processed in parallel. - βdim (
Int): Hidden dimension, equal to the number of channels per sequence position. - βseqlen (
Int): Number of timesteps in each sequence. - βgroup_size (
Int): 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.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!