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 function

fused_concat

def fused_concat[dtype: DType, rank: Int, InputFnType: def[input_index: Int, width: Int, alignment: Int = Int(1)](Coord[**?]) -> SIMD[dtype, width] & RegisterPassable & ImplicitlyCopyable, OutputFnType: ElementwiseEpilogueFn, OutputLayoutType: TensorLayout, *, axis: Int](input_shapes: StaticTuple[Coord[*#kgen.param_list.tabulate(rank, [idx: __mlir_type.index] Int)]], output_layout: OutputLayoutType, input_fn: InputFnType, output_0_fn: OutputFnType, ctx: DeviceContext)

Concatenates inputs produced by input_fn along axis, handing each element to output_0_fn.

Instead of reading from concrete input tensors, the fused variant drives the concat from a caller-supplied input_fn that produces values on demand, allowing the concat to be fused with preceding elementwise operations. Dispatches to the CPU or GPU fused implementation based on the target of ctx and returns early when the output tensor is empty.

Parameters:

  • ​dtype (DType): Element type of the input and output tensors.
  • ​rank (Int): Number of dimensions in the input and output tensors.
  • ​InputFnType (def[input_index: Int, width: Int, alignment: Int = Int(1)](Coord[**?]) -> SIMD[dtype, width] & RegisterPassable & ImplicitlyCopyable): Type of the input function (inferred).
  • ​OutputFnType (ElementwiseEpilogueFn): Type of the output epilogue function (inferred).
  • ​OutputLayoutType (TensorLayout): Layout type of the concatenated output.
  • ​axis (Int): Axis along which to concatenate the inputs.

Args:

  • ​input_shapes (StaticTuple[Coord[*#kgen.param_list.tabulate(rank, [idx: __mlir_type.index] Int)]]): Static tuple of per-input shapes describing each logical input that input_fn produces.
  • ​output_layout (OutputLayoutType): Layout of the concatenated output. The concat reads only its shape; every element reaches the output through output_0_fn.
  • ​input_fn (InputFnType): Function that produces input element values on demand, indexed by input position.
  • ​output_0_fn (OutputFnType): Epilogue function that stores each produced element.
  • ​ctx (DeviceContext): Device context used to schedule the work.

Was this page helpful?