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 = 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 implementingTensorLayoutthat defines the tensor's shape and stride structure. - origin (
Origin): 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. WhenNone, 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,
ImplicitlyDestructible,
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.reduce(#kgen.param_list.reduce(#kgen.param_list.reduce(#kgen.param_list.reduce(LayoutType.__shape_types, base=, reducer=[PrevV: KGENParamList[CoordLike], VA: KGENParamList[CoordLike], idx: __mlir_type.index] #kgen.param_list.concat(PrevV, VA[idx]._ParamListType if VA[idx].is_tuple else VA[idx])), base=, reducer=[PrevV: KGENParamList[CoordLike], VA: KGENParamList[CoordLike], idx: __mlir_type.index] #kgen.param_list.concat(PrevV, VA[idx]._ParamListType if VA[idx].is_tuple else VA[idx])), base=, reducer=[PrevV: KGENParamList[CoordLike], VA: KGENParamList[CoordLike], idx: __mlir_type.index] #kgen.param_list.concat(PrevV, VA[idx]._ParamListType if VA[idx].is_tuple else VA[idx])), base=, reducer=[PrevV: KGENParamList[CoordLike], VA: KGENParamList[CoordLike], idx: __mlir_type.index] #kgen.param_list.concat(PrevV, VA[idx]._ParamListType if VA[idx].is_tuple else VA[idx]))].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]] = False if (TypeList[LayoutType.__shape_types].size != TypeList[values].size) else ParameterList.all_satisfies[comptime[Elt: KGENParamList[CoordLike]] True if not Elt[1].is_tuple.__bool__() else False if not Elt[0].is_tuple.__bool__() else False if (TypeList[Elt[0]._ParamListType].size != TypeList[Elt[1]._ParamListType].size) else ParameterList.all_satisfies[comptime[Elt: KGENParamList[CoordLike]] True if not Elt[1].is_tuple.__bool__() else False if not Elt[0].is_tuple.__bool__() else False if (TypeList[Elt[0]._ParamListType].size != TypeList[Elt[1]._ParamListType].size) else ParameterList.all_satisfies[comptime[Elt: KGENParamList[CoordLike]] True if not Elt[1].is_tuple.__bool__() else False if not Elt[0].is_tuple.__bool__() else (TypeList[Elt[0]._ParamListType].size == TypeList[Elt[1]._ParamListType].size)]()]()]()
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
- C (
TypeList): The coordinate element types to check against.
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
__init__(other: NullableTileTensor[other.dtype, other.LayoutType, other.origin, 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:
- other (
NullableTileTensor): The mutable NullableTileTensor to cast from.
Returns:
@implicit
__init__(other: TileTensor[other.dtype, other.LayoutType, other.origin, 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:
- other (
TileTensor): The TileTensor to cast from.
Returns:
@implicit
__init__(other: TileTensor[other.dtype, other.LayoutType, other.origin, 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:
- other (
TileTensor): The mutable TileTensor to cast from.
Returns:
value
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: A TileTensor backed by the stored pointer and layout.
dim
dim[i: Int](self) -> Scalar[linear_idx_type]
Returns the size of dimension i.
Parameters:
- i (
Int): The dimension index (compile-time constant).
Returns:
Scalar: The size of dimension i as a scalar.
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: The size of the specified dimension as a scalar.
num_elements
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
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: A LayoutTensor with the same shape, stride, and address space of
this tensor.