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 function
fused_concat
def fused_concat[dtype: DType, rank: Int, input_fn: def[input_index: Int, width: Int, _rank: Int, alignment: Int = Int(1)](IndexList[_rank]) capturing thin -> SIMD[dtype, width], output_0_fn: def[c_type: DType, rank: Int, width: SIMDLength = SIMDLength(1), *, alignment: Int = Int(1)](IndexList[rank], SIMD[c_type, width]) capturing thin -> None, output_layout: TensorLayout, *, axis: Int, target: StringSlice[ImmStaticOrigin] = StringSlice("cpu")](input_shapes: StaticTuple[IndexList[rank]], output: TileTensor[dtype, output_layout, Storage=output.Storage], ctx: DeviceContext)
Concatenates inputs produced by input_fn along axis into output, applying output_0_fn to each element.
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 target 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. - βinput_fn (
def[input_index: Int, width: Int, _rank: Int, alignment: Int = Int(1)](IndexList[_rank]) capturing thin -> SIMD[dtype, width]): Function that produces input element values on demand, indexed by input position. - βoutput_0_fn (
def[c_type: DType, rank: Int, width: SIMDLength = SIMDLength(1), *, alignment: Int = Int(1)](IndexList[rank], SIMD[c_type, width]) capturing thin -> None): Epilogue function applied to each produced element before storing. - βoutput_layout (
TensorLayout): Layout type of the output tensor. - βaxis (
Int): Axis along which to concatenate the inputs. - βtarget (
StringSlice[ImmStaticOrigin]): Target device to dispatch to (defaults to"cpu").
Args:
- βinput_shapes (
StaticTuple[IndexList[rank]]): Static tuple of per-input shapes describing each logical input thatinput_fnproduces. - βoutput (
TileTensor[dtype, output_layout, Storage=output.Storage]): Destination tensor that receives the concatenated result. - βctx (
DeviceContext): Device context used to schedule the work.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!