IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: Nightly
For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

NullableTileTensor

struct NullableTileTensor[mut: Bool, //, dtype: DType, LayoutType: TensorLayout, origin: Origin[mut=mut], *, address_space: AddressSpace = AddressSpace.GENERIC, linear_idx_type: DType = _get_index_type[LayoutType](address_space), element_size: Int = Int(1)]

A TileTensor variant whose pointer may be absent (null).

NullableTileTensor carries the same layout metadata as TileTensor but explicitly represents its pointer as nullable.

Only layout-query methods are provided. To perform loads, stores, or other data operations, first check self.ptr and then call value() to obtain a regular TileTensor.

Parameters

  • mut (Bool): The inferred mutability of the underlying pointer.
  • dtype (DType): The data type of tensor elements.
  • LayoutType (TensorLayout): A type implementing TensorLayout that defines the tensor's shape and stride structure.
  • origin (Origin[mut=mut]): The origin of the underlying pointer for lifetime tracking.
  • address_space (AddressSpace): Memory address space. Defaults to GENERIC.
  • linear_idx_type (DType): Integer type for memory indexing.
  • element_size (Int): The number of scalar elements per logical element.

Fields

  • ptr (Optional[UnsafePointer[Scalar[dtype], origin, address_space=address_space]]): Optional pointer to the tensor's underlying data storage. When None, represents a tensor with layout metadata but no backing memory (e.g. an output buffer that the callee should allocate).
  • layout (LayoutType): The layout instance defining shape and stride mappings.

Implemented traits

AnyType, Copyable, ImplicitlyCopyable, ImplicitlyDeletable, Movable, RegisterPassable

comptime members

all_dims_known

comptime all_dims_known = LayoutType.all_dims_known

True if both shape and stride are fully known at compile time.

ElementType

comptime ElementType = SIMD[dtype, element_size]

The SIMD type used for element access.

flat_rank

comptime flat_rank = TypeList[#kgen.param_list.concat(#kgen.param_list.tabulate(len(#kgen.param_list.concat(#kgen.param_list.tabulate(len(#kgen.param_list.concat(#kgen.param_list.tabulate(len(#kgen.param_list.concat(#kgen.param_list.tabulate(len(LayoutType.__shape_types), [idx: __mlir_type.index] LayoutType.__shape_types[SIMDSize(Int(idx))]._ParamListType))), [idx: __mlir_type.index] #kgen.param_list.concat(#kgen.param_list.tabulate(len(LayoutType.__shape_types), [idx: __mlir_type.index] LayoutType.__shape_types[SIMDSize(Int(idx))]._ParamListType))[SIMDSize(Int(idx))]._ParamListType))), [idx: __mlir_type.index] #kgen.param_list.concat(#kgen.param_list.tabulate(len(#kgen.param_list.concat(#kgen.param_list.tabulate(len(LayoutType.__shape_types), [idx: __mlir_type.index] LayoutType.__shape_types[SIMDSize(Int(idx))]._ParamListType))), [idx: __mlir_type.index] #kgen.param_list.concat(#kgen.param_list.tabulate(len(LayoutType.__shape_types), [idx: __mlir_type.index] LayoutType.__shape_types[SIMDSize(Int(idx))]._ParamListType))[SIMDSize(Int(idx))]._ParamListType))[SIMDSize(Int(idx))]._ParamListType))), [idx: __mlir_type.index] #kgen.param_list.concat(#kgen.param_list.tabulate(len(#kgen.param_list.concat(#kgen.param_list.tabulate(len(#kgen.param_list.concat(#kgen.param_list.tabulate(len(LayoutType.__shape_types), [idx: __mlir_type.index] LayoutType.__shape_types[SIMDSize(Int(idx))]._ParamListType))), [idx: __mlir_type.index] #kgen.param_list.concat(#kgen.param_list.tabulate(len(LayoutType.__shape_types), [idx: __mlir_type.index] LayoutType.__shape_types[SIMDSize(Int(idx))]._ParamListType))[SIMDSize(Int(idx))]._ParamListType))), [idx: __mlir_type.index] #kgen.param_list.concat(#kgen.param_list.tabulate(len(#kgen.param_list.concat(#kgen.param_list.tabulate(len(LayoutType.__shape_types), [idx: __mlir_type.index] LayoutType.__shape_types[SIMDSize(Int(idx))]._ParamListType))), [idx: __mlir_type.index] #kgen.param_list.concat(#kgen.param_list.tabulate(len(LayoutType.__shape_types), [idx: __mlir_type.index] LayoutType.__shape_types[SIMDSize(Int(idx))]._ParamListType))[SIMDSize(Int(idx))]._ParamListType))[SIMDSize(Int(idx))]._ParamListType))[SIMDSize(Int(idx))]._ParamListType))].size

The flattened rank.

GenericType

comptime GenericType = NullableTileTensor[dtype, LayoutType, origin, linear_idx_type=linear_idx_type]

Type alias for this tensor with GENERIC address space.

Used by constructors that create tensors from Span, DeviceBuffer, or HostBuffer, which all produce GENERIC address space tensors.

is_compatible_with

comptime is_compatible_with[C: TypeList[values]] = ParameterList.all_satisfies[comptime[Elt: Bool] Elt]() if (Int(len(LayoutType.__shape_types)) == Int(len(values))) else (Int(len(LayoutType.__shape_types)) == Int(len(values)))

True if coordinate types C are structurally compatible with this tensor's layout shape.

A scalar coordinate element is always compatible. A tuple coordinate element requires the corresponding layout shape element to also be a tuple of the same length, checked recursively up to 4 levels of nesting.

Parameters

is_row_major

comptime is_row_major = ParameterList.all_satisfies[comptime[Elt: Bool] Elt]()

True if the tensor has row-major (contiguous) strides.

PtrType

comptime PtrType = UnsafePointer[Scalar[dtype], origin, address_space=address_space]

The non-null pointer type for the underlying data storage.

rank

comptime rank = LayoutType.rank

The number of dimensions in the tensor's layout.

shape_known

comptime shape_known = LayoutType.shape_known

True if all shape dimensions are compile-time constants.

static_shape

comptime static_shape[i: Int] = LayoutType.static_shape[i]

Get the compile-time shape value for dimension i, or -1 if dynamic.

Parameters

  • i (Int): The dimension index.

static_stride

comptime static_stride[i: Int] = LayoutType.static_stride[i]

Get the compile-time stride value for dimension i, or -1 if dynamic.

Parameters

  • i (Int): The dimension index.

stride_known

comptime stride_known = LayoutType.stride_known

True if all stride dimensions are compile-time constants.

Methods

__init__

@implicit def __init__(other: NullableTileTensor[address_space=other.address_space, linear_idx_type=other.linear_idx_type, element_size=other.element_size]) -> NullableTileTensor[other.dtype, other.LayoutType, origin_of(other.origin), address_space=other.address_space, linear_idx_type=other.linear_idx_type, element_size=other.element_size]

Implicitly cast a mutable NullableTileTensor to immutable.

Args:

Returns:

NullableTileTensor[other.dtype, other.LayoutType, origin_of(other.origin), address_space=other.address_space, linear_idx_type=other.linear_idx_type, element_size=other.element_size]

@implicit def __init__(other: TileTensor[Storage=other.Storage, address_space=other.address_space, linear_idx_type=other.linear_idx_type, element_size=other.element_size]) -> NullableTileTensor[other.dtype, other.LayoutType, other.origin, address_space=other.address_space, linear_idx_type=other.linear_idx_type, element_size=other.element_size]

Implicitly cast a TileTensor to a NullableTileTensor.

Args:

Returns:

NullableTileTensor[other.dtype, other.LayoutType, other.origin, address_space=other.address_space, linear_idx_type=other.linear_idx_type, element_size=other.element_size]

@implicit def __init__(other: TileTensor[Storage=other.Storage, address_space=other.address_space, linear_idx_type=other.linear_idx_type, element_size=other.element_size]) -> NullableTileTensor[other.dtype, other.LayoutType, origin_of(other.origin), address_space=other.address_space, linear_idx_type=other.linear_idx_type, element_size=other.element_size]

Implicitly cast a mutable TileTensor to an immutable NullableTileTensor.

Args:

Returns:

NullableTileTensor[other.dtype, other.LayoutType, origin_of(other.origin), address_space=other.address_space, linear_idx_type=other.linear_idx_type, element_size=other.element_size]

value

def value(self) -> TileTensor[dtype, LayoutType, origin, address_space=address_space, linear_idx_type=linear_idx_type, element_size=element_size]

Returns a regular TileTensor with the underlying pointer.

The caller must ensure the underlying pointer is non-null before calling this method.

Returns:

TileTensor[dtype, LayoutType, origin, address_space=address_space, linear_idx_type=linear_idx_type, element_size=element_size]: A TileTensor backed by the stored pointer and layout.

dim

def dim[i: Int](self) -> Scalar[linear_idx_type]

Returns the size of outer-mode dimension i.

For a flat layout this is shape[i]. For a nested layout (where shape[i] is itself a Coord) this is the product of all leaf dims under outer-mode i — the i-th mode's extent under CuTe Layout Algebra. For shape ((a, b), (c, d)): dim[0] = a*b, dim[1] = c*d.

Parameters:

  • i (Int): The dimension index (compile-time constant).

Returns:

Scalar[linear_idx_type]: The product of all leaf dims under outer-mode i.

def dim[IndexType: Indexer](self, index: IndexType) -> Scalar[linear_idx_type]

Returns the size of the specified dimension.

Parameters:

  • IndexType (Indexer): The type of the index argument.

Args:

  • index (IndexType): The dimension index (runtime value).

Returns:

Scalar[linear_idx_type]: The size of the specified dimension as a scalar.

num_elements

def num_elements(self) -> Int

Returns the total number of elements in the tensor.

Computes the product of all shape dimensions.

Returns:

Int: The total element count.

to_layout_tensor

def to_layout_tensor(self) -> LayoutTensor[dtype, Layout(coord_to_int_tuple[LayoutType._shape_types](), coord_to_int_tuple[LayoutType._stride_types]()), origin, address_space=address_space]

Return a LayoutTensor with the same shape, stride, and address space of this tensor. Currently it expects flat layouts.

This is a utility to help with porting LayoutTensor methods to this type.

Returns:

LayoutTensor[dtype, Layout(coord_to_int_tuple[LayoutType._shape_types](), coord_to_int_tuple[LayoutType._stride_types]()), origin, address_space=address_space]: A LayoutTensor with the same shape, stride, and address space of this tensor.