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:
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:
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:
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 atoutput[d, s].
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!