IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /max/get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
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 struct

VarlenConvIO

struct VarlenConvIO[x_origin: Origin[mut=x_origin.mut], weight_origin: Origin[mut=weight_origin.mut], bias_origin: Origin[mut=bias_origin.mut], out_origin: MutOrigin, x_dtype: DType, weight_dtype: DType, bias_dtype: DType, out_dtype: DType, x_layout: TensorLayout, weight_layout: TensorLayout, bias_layout: TensorLayout, out_layout: TensorLayout, x_store: TensorStorage, weight_store: TensorStorage, bias_store: TensorStorage, out_store: TensorStorage, x_addr: AddressSpace, weight_addr: AddressSpace, bias_addr: AddressSpace, out_addr: AddressSpace, x_idx: DType, weight_idx: DType, bias_idx: DType, out_idx: DType, //]

Owner of the forward-path DRAM reads/writes for varlen causal conv1d.

Holds the (dim, seqlen) input x, (dim, width) weight, (dim,) bias, and (dim, seqlen) output TileTensor views and exposes one method per access verb.

weight/bias (never axis-permuted) still index through t.load(Coord(...)) -- the view's own RuntimeLayout matches the (d, w) / (d,) logical order exactly. load_x/store_out instead take the caller's runtime dim/seqlen strides and compute the offset explicitly (d*dim_stride + s*seqlen_stride), matching the conv-state ring-buffer's raw_load/raw_store pattern below. This is required, not just symmetric style: x/output's physical axis order flips under the channels_last builtin parameter (kernels.mojo's CausalConv1DVarlenFwd) while the (d, s) logical argument order here does not, so a Coord(d, s) load through the view's native layout would silently swap axes and read/write the wrong element whenever the caller is channels-last. Passing the (already axis-corrected) strides down and addressing raw offsets sidesteps the mismatch. See Kernels/claude_kb/entries/patterns/mojo-layout-is-cute-layout-algebra.md ("shape and stride are orthogonal") -- d/s are the algorithm's shape plane; the stride plane is what may vary, so loads/stores must go through strides, not through a Coord tied to the view's declared axis order.

Every view parameter (dtype, layout, origin, storage, address space, index type) is inferred from the constructor arguments, so the owner adapts to whatever tensor storage the caller's views carry -- the CPU reference and GPU kernel pass differently-parameterized views. The read views (x, weight, bias) carry origins with a free mut (the CPU reference passes them immutable, the GPU kernel mutable; reads need no mutability proof); the store target output pins MutOrigin so store type-checks. Modeled on the owner-per-transition pattern (see Fp4WeightLoader in matmul2d_fp4.mojo), constructed by direct field init so no origin rebase is needed. Stateless: the circular conv-state position is not owned here, so the same owner serves any path.

Parameters​

  • ​x_origin (Origin[mut=x_origin.mut]): Inferred origin of the input view.
  • ​weight_origin (Origin[mut=weight_origin.mut]): Inferred origin of the weight view.
  • ​bias_origin (Origin[mut=bias_origin.mut]): Inferred origin of the bias view.
  • ​out_origin (MutOrigin): Inferred mutable origin of the output view.
  • ​x_dtype (DType): Input element type.
  • ​weight_dtype (DType): Weight element type.
  • ​bias_dtype (DType): Bias element type.
  • ​out_dtype (DType): Output element type.
  • ​x_layout (TensorLayout): Layout type of the (dim, seqlen) input view.
  • ​weight_layout (TensorLayout): Layout type of the (dim, width) weight view.
  • ​bias_layout (TensorLayout): Layout type of the (dim,) bias view.
  • ​out_layout (TensorLayout): Layout type of the (dim, seqlen) output view.
  • ​x_store (TensorStorage): Inferred storage of the input view.
  • ​weight_store (TensorStorage): Inferred storage of the weight view.
  • ​bias_store (TensorStorage): Inferred storage of the bias view.
  • ​out_store (TensorStorage): Inferred storage of the output view.
  • ​x_addr (AddressSpace): Inferred address space of the input view.
  • ​weight_addr (AddressSpace): Inferred address space of the weight view.
  • ​bias_addr (AddressSpace): Inferred address space of the bias view.
  • ​out_addr (AddressSpace): Inferred address space of the output view.
  • ​x_idx (DType): Inferred linear-index type of the input view.
  • ​weight_idx (DType): Inferred linear-index type of the weight view.
  • ​bias_idx (DType): Inferred linear-index type of the bias view.
  • ​out_idx (DType): Inferred linear-index type of the output view.

Fields​

  • ​x (TileTensor[x_dtype, x_layout, x_origin, Storage=x_store, address_space=x_addr, linear_idx_type=x_idx]):
  • ​weight (TileTensor[weight_dtype, weight_layout, weight_origin, Storage=weight_store, address_space=weight_addr, linear_idx_type=weight_idx]):
  • ​bias (TileTensor[bias_dtype, bias_layout, bias_origin, Storage=bias_store, address_space=bias_addr, linear_idx_type=bias_idx]):
  • ​output (TileTensor[out_dtype, out_layout, out_origin, Storage=out_store, address_space=out_addr, linear_idx_type=out_idx]):
  • ​x_dim_stride (UInt32):
  • ​x_seqlen_stride (UInt32):
  • ​out_dim_stride (UInt32):
  • ​out_seqlen_stride (UInt32):

Implemented traits​

AnyType, Copyable, ImplicitlyCopyable, ImplicitlyDeletable, Movable

Methods​

load_x​

def load_x(self, d: Int, s: Int) -> Scalar[x_dtype]

Load x[d, s]: windowed history read of the input.

Args:

  • ​d (Int): The channel index into the (dim, seqlen) input view.
  • ​s (Int): The sequence position index into the (dim, seqlen) input view.

Returns:

Scalar[x_dtype]

load_weight​

def load_weight(self, d: Int, w: Int) -> Scalar[weight_dtype]

Load weight[d, w]: per-channel conv tap.

Args:

  • ​d (Int): The channel index into the (dim, width) weight view.
  • ​w (Int): The convolution tap index in [0, width).

Returns:

Scalar[weight_dtype]

load_bias​

def load_bias(self, d: Int) -> Scalar[bias_dtype]

Load bias[d]: per-channel bias.

Args:

  • ​d (Int): The channel index into the (dim,) bias view.

Returns:

Scalar[bias_dtype]

store_out​

def store_out(self, d: Int, s: Int, val: Scalar[out_dtype])

Store output[d, s] = val: convolution output.

Args:

  • ​d (Int): The channel index into the (dim, seqlen) output view.
  • ​s (Int): The sequence position index into the (dim, seqlen) output view.
  • ​val (Scalar[out_dtype]): The convolution result to store at output[d, s].