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

TensorTuple

struct TensorTuple[*Ts: AnyType]

A heterogeneous tuple of a kernel's tensor arguments, held by value.

A kernel takes one TensorTuple per variadic tensor argument, with the element types in an infer-only TypeList bound by tensor-argument traits. A signature can take one per operand list (an output tuple and an input tuple) but not two on the same side: a graph op's flat operand list cannot carry run boundaries, so mogg-verify-kernels rejects a second variadic per side, as it does for the legacy VariadicTensors lane:

def execute[
    Outs: TypeList[Trait=Output & DenseTensor, ...],
    Ins: TypeList[Trait=Input & DenseTensor, ...],
    //,
    target: StaticString,
](outputs: TensorTuple[*Outs], inputs: TensorTuple[*Ins], ctx: DeviceContext):
    comptime for i in range(len(Ins)):
        var x = inputs[i]

The struct is a Tuple of tensor arguments in all but two respects. It puts no bound of its own on the element types, so a kernel's list needs only its tensor-argument bound; the elements must be Copyable to be held and Deinitable to be dropped, as every emitted tensor argument is, and that is checked where the tuple is instantiated. And its storage is a plain aggregate rather than a parameter pack, so it crosses a kernel launch as one argument (see _mlir_type).

The graph compiler builds the tuple from the arguments it emits.

Like TileTensor, the tuple is its own device representation, over its elements' device types: when every element is DevicePassable, so is the tuple, and enqueue_function projects it to its device_type by running each element's own _to_device_type in place. A device kernel taking TensorTuple[*Ts].device_type then indexes element k with the access its bound grants.

Parameters​

  • ​*Ts (AnyType): The element types.

Implemented traits​

AnyType, Copyable (where TypeList.all_conforms_to[Copyable]()), Deinitable, DevicePassable (where TypeList.all_conforms_to[DevicePassable]()), ImplicitlyCopyable (where TypeList.all_conforms_to[ImplicitlyCopyable]()), Movable (where TypeList.all_conforms_to[Movable]()), RegisterPassable (where TypeList.all_conforms_to[RegisterPassable]()), Sized

comptime members​

device_type​

comptime device_type = TensorTuple[*#kgen.param_list.tabulate(len(values), [idx: __mlir_type.index] values[idx].device_type if conforms_to(values[idx], DevicePassable) else values[idx])]

Methods​

__init__​

def __init__(out self, *elements: *Ts.values)

Constructs a tuple holding copies of elements.

Constraints:

Every element type must be Copyable.

Args:

  • ​*elements (*Ts.values): The tensor arguments to hold.

def __init__(out self, *, copy: Self) where TypeList.all_conforms_to[Copyable]()

Copies a tuple element by element.

Args:

  • ​copy (Self): The tuple to copy.

def __init__(out self, *, deinit move: Self) where TypeList.all_conforms_to[Movable]()

Moves a tuple element by element.

Args:

  • ​move (Self): The tuple to move from.

__deinit__​

def __deinit__(deinit self)

Destroys each element.

Constraints:

Every element type must be Deinitable.

__len__​

def __len__(self) -> Int

Returns the number of elements.

Returns:

Int: The number of elements in the tuple.

__getitem_param__​

def __getitem_param__[idx: Int](ref self) -> ref[idx] Ts.values[SIMDLength(idx)]

Returns a reference to the element at idx.

Parameters:

  • ​idx (Int): The element's index.

Returns:

ref[idx] Ts.values[SIMDLength(idx)]: A reference to the element.

get_type_name​

static def get_type_name() -> String

Returns the host type's name, for kernel-launch diagnostics.

Returns:

String: The name TensorTuple.

Was this page helpful?