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[weight_origin: Origin[mut=weight_origin.mut], bias_origin: Origin[mut=bias_origin.mut], out_origin: MutOrigin, dtype: DType, weight_layout: TensorLayout, bias_layout: TensorLayout, out_layout: TensorLayout, weight_engine: TensorEngine, bias_engine: TensorEngine, out_engine: TensorEngine, weight_addr: AddressSpace, bias_addr: AddressSpace, out_addr: AddressSpace, weight_idx: DType, bias_idx: DType, out_idx: DType, XFn: def[width: Int, alignment: Int](Int, Int) -> SIMD[dtype, width] & RegisterPassable & ImplicitlyCopyable, //, channels_last: Bool]

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

Holds the input reader, the (dim, width) weight, (dim,) bias, and 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. The methods take the logical (d, s) and order the coordinates by channels_last, so the axis order stays out of the kernels.

Every view parameter is inferred from the constructor arguments, so the owner adapts to whatever storage the caller's views carry. Only the store target output pins a mutable origin.

The CPU reference is the owner's user. The GPU forward kernel indexes its tensors directly: on Metal, that kernel's accesses through these fields read zero and drop stores.

Parameters​

  • ​weight_origin (Origin[mut=mut]): Inferred origin of the weight view.
  • ​bias_origin (Origin[mut=mut]): Inferred origin of the bias view.
  • ​out_origin (MutOrigin): Inferred mutable origin of the output view.
  • ​dtype (DType): Element type of x, weight, bias and output.
  • ​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 output 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.
  • ​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.
  • ​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.
  • ​XFn (def[width: Int, alignment: Int](Int, Int) -> SIMD[dtype, width] & RegisterPassable & ImplicitlyCopyable): Inferred reader of x at its physical (row, column) index.
  • ​channels_last (Bool): Whether x and output are (seqlen, dim) rather than (dim, seqlen).

Fields​

  • ​x_fn (XFn):
  • ​weight (TileTensor[dtype, weight_layout, weight_origin, Engine=weight_engine, address_space=weight_addr, linear_idx_type=weight_idx]):
  • ​bias (TileTensor[dtype, bias_layout, bias_origin, Engine=bias_engine, address_space=bias_addr, linear_idx_type=bias_idx]):
  • ​output (TileTensor[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​

dim​

def dim(self) -> Int

Returns the number of channels.

Returns:

Int

load_x​

def load_x[width: Int = Int(1)](self, d: Int, s: Int) -> SIMD[dtype, width]

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

Parameters:

  • ​width (Int): The number of consecutive channels; above 1 needs channels_last, where they are contiguous.

Args:

  • ​d (Int): The first channel index.
  • ​s (Int): The packed sequence position.

Returns:

SIMD[dtype, width]

load_weight​

def load_weight(self, d: Int, w: Int) -> Scalar[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[dtype]

load_bias​

def load_bias[width: Int = Int(1)](self, d: Int) -> SIMD[dtype, width]

Load bias[d:d + width], or zero when bias is empty.

Parameters:

  • ​width (Int): The number of consecutive channels.

Args:

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

Returns:

SIMD[dtype, width]

store_out​

def store_out[width: Int = Int(1)](self, d: Int, s: Int, val: SIMD[dtype, width])

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

Parameters:

  • ​width (Int): The number of consecutive channels, as in load_x.

Args:

  • ​d (Int): The first channel index.
  • ​s (Int): The packed sequence position.
  • ​val (SIMD[dtype, width]): The convolution result to store.

Was this page helpful?