IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /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. /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_engine: TensorEngine, weight_engine: TensorEngine, bias_engine: TensorEngine, out_engine: TensorEngine, x_addr: AddressSpace, weight_addr: AddressSpace, bias_addr: AddressSpace, out_addr: AddressSpace, x_idx: DType, weight_idx: DType, bias_idx: DType, out_idx: DType, //, channels_last: Bool]

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.

x and output are the caller's physical tensors: (dim, seqlen), or (seqlen, dim) when channels_last. load_x/store_out take the logical (d, s) and order the Coord by channels_last, so the axis order that flips under the channels_last builtin parameter (kernels.mojo's CausalConv1DVarlenFwd) stays out of the kernels.

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_engine (TensorEngine): Inferred engine of the input view.
  • ​weight_engine (TensorEngine): Inferred engine of the weight view.
  • ​bias_engine (TensorEngine): Inferred engine of the bias view.
  • ​out_engine (TensorEngine): Inferred engine 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.
  • ​channels_last (Bool): Whether x and output are (seqlen, dim) rather than (dim, seqlen).

Fields​

  • ​x (TileTensor[x_dtype, x_layout, x_origin, Engine=x_engine, address_space=x_addr, linear_idx_type=x_idx]):
  • ​weight (TileTensor[weight_dtype, weight_layout, weight_origin, Engine=weight_engine, address_space=weight_addr, linear_idx_type=weight_idx]):
  • ​bias (TileTensor[bias_dtype, bias_layout, bias_origin, Engine=bias_engine, address_space=bias_addr, linear_idx_type=bias_idx]):
  • ​output (TileTensor[out_dtype, out_layout, out_origin, Engine=out_engine, address_space=out_addr, linear_idx_type=out_idx]):

Implemented traits​

AnyType, Copyable, Deinitable, ImplicitlyCopyable, 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].

Was this page helpful?