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
StaticOffsetStorage
struct StaticOffsetStorage[*, static_offset: Int, element_width: Int = Int(1)]
Stub of the planned static-offset storage policy family.
Views externally owned memory like PointerStorage, but starts every
access static_offset scalar elements past the handle. The offset is
encoded in the policy's parameters, so it costs nothing at runtime and
survives unsafe_cast. This is a minimal placeholder used by the
TensorOps binary-op tests to exercise per-operand storage policies until
the full static-offset design lands.
Parametersβ
- βstatic_offset (
Int): The number of scalar elements every access is advanced by. - βelement_width (
Int): Number of scalar elements per logical element. A value of1(the default) is a non-vectorized tensor; larger values describe a vectorized view whose logical elements are SIMD vectors.
Implemented traitsβ
AnyType,
ImplicitlyDeletable,
TensorStorage
comptime membersβ
element_sizeβ
comptime element_size = element_width
Number of scalar elements per logical element (alias of element_width).
OffsetResultTypeβ
comptime OffsetResultType[offset_types: TypeList[values]] = StaticOffsetStorage[static_offset=static_offset, element_width=element_width]
The storage type produced by offsetting with a given coordinate.
Dynamic offsetting never changes the storage policy, so this is Self;
the static offset stays encoded in the parameters.
Parametersβ
- βoffset_types (
TypeList[values]): The coordinate element types of the applied offset.
StorageTypeβ
comptime StorageType[mut: Bool, //, dtype: DType, origin: Origin[mut=mut], address_space: AddressSpace] = Pointer[SIMD[dtype, element_width], origin, address_space=address_space]
A raw UnsafePointer borrowing the storage, static_offset scalar elements before the viewed region.
Parametersβ
- βmut (
Bool): The mutability of the borrowed storage, inferred fromorigin. - βdtype (
DType): The element data type of the borrowed storage. - βorigin (
Origin[mut=mut]): The origin tracking the lifetime of the borrowed storage. - βaddress_space (
AddressSpace): The address space the borrowed storage resides in.
Methodsβ
unsafe_castβ
static def unsafe_cast[to_mut: Bool, //, to_dtype: DType, to_origin: Origin[mut=to_mut], to_address_space: AddressSpace](storage: Pointer[SIMD[dtype, element_width], address_space=storage.address_space]) -> Pointer[SIMD[to_dtype, element_width], to_origin, address_space=to_address_space]
Reinterprets a storage handle with new type parameters.
The static offset lives in the policy's parameters, so it is unaffected by the reinterpret.
Parameters:
- βto_mut (
Bool): The mutability of the origin. - βto_dtype (
DType): The element data type to reinterpret the storage as. - βto_origin (
Origin[mut=to_mut]): The origin to reinterpret the storage as. - βto_address_space (
AddressSpace): The address space to reinterpret the storage as.
Args:
- βstorage (
Pointer[SIMD[dtype, element_width], address_space=storage.address_space]): The storage to reinterpret.
Returns:
Pointer[SIMD[to_dtype, element_width], to_origin, address_space=to_address_space]: A handle referring to the same storage, viewed with the new type
parameters.
loadβ
static def load[dtype: DType, //, width: SIMDLength, alignment: Int, invariant: Bool = False, non_temporal: Bool = False](storage: Pointer[SIMD[dtype, element_width], address_space=storage.address_space]) -> SIMD[dtype, width]
Loads a SIMD value from the start of the viewed region.
Parameters:
- βdtype (
DType): The element data type of the storage. - βwidth (
SIMDLength): The number of elements to load. - βalignment (
Int): The alignment guarantee for the load. - βinvariant (
Bool): If True, the compiler may assume the memory won't be modified during the kernel, enabling load hoisting and caching. - βnon_temporal (
Bool): If True, indicates the data will not be reused soon, allowing the hardware to bypass caches (e.g., streaming loads).
Args:
- βstorage (
Pointer[SIMD[dtype, element_width], address_space=storage.address_space]): The storage to load from.
Returns:
SIMD[dtype, width]: The loaded SIMD value.
static def load[dtype: DType, //, width: SIMDLength, alignment: Int, invariant: Bool = False, non_temporal: Bool = False](storage: Pointer[SIMD[dtype, element_width], address_space=storage.address_space], offset: T) -> SIMD[dtype, width]
Loads a SIMD value at a scalar-element offset into the region.
Parameters:
- βdtype (
DType): The element data type of the storage. - βwidth (
SIMDLength): The number of elements to load. - βalignment (
Int): The alignment guarantee for the load. - βinvariant (
Bool): If True, the compiler may assume the memory won't be modified during the kernel, enabling load hoisting and caching. - βnon_temporal (
Bool): If True, indicates the data will not be reused soon, allowing the hardware to bypass caches (e.g., streaming loads).
Args:
- βstorage (
Pointer[SIMD[dtype, element_width], address_space=storage.address_space]): The storage to load from. - βoffset (
T): The scalar-element offset to load at, relative to the start of the viewed region.
Returns:
SIMD[dtype, width]: The loaded SIMD value.
storeβ
static def store[dtype: DType, alignment: Int, *, non_temporal: Bool = False](storage: Pointer[SIMD[dtype, element_width], address_space=storage.address_space], value: SIMD[dtype])
Stores a SIMD value at the start of the viewed region.
Parameters:
- βdtype (
DType): The element data type of the storage. - βalignment (
Int): The alignment guarantee for the store. - βnon_temporal (
Bool): If True, indicates the data will not be reused soon, allowing the hardware to bypass caches (e.g., streaming stores).
Args:
- βstorage (
Pointer[SIMD[dtype, element_width], address_space=storage.address_space]): The storage to store into. - βvalue (
SIMD[dtype]): TheSIMDvalue to store.
static def store[dtype: DType, alignment: Int, *, non_temporal: Bool = False](storage: Pointer[SIMD[dtype, element_width], address_space=storage.address_space], offset: T, value: SIMD[dtype])
Stores a SIMD value at a scalar-element offset into the region.
Parameters:
- βdtype (
DType): The element data type of the storage. - βalignment (
Int): The alignment guarantee for the store. - βnon_temporal (
Bool): If True, indicates the data will not be reused soon, allowing the hardware to bypass caches (e.g., streaming stores).
Args:
- βstorage (
Pointer[SIMD[dtype, element_width], address_space=storage.address_space]): The storage to store into. - βoffset (
T): The scalar-element offset to store at, relative to the start of the viewed region. - βvalue (
SIMD[dtype]): TheSIMDvalue to store.
offsetβ
static def offset[offset_mut: Bool, offset_types: TypeList[offset_types.values], //, offset_dtype: DType, offset_origin: Origin[mut=offset_mut], offset_address_space: AddressSpace](var storage: Pointer[SIMD[offset_dtype, element_width], offset_origin, address_space=offset_address_space], var offset_coord: Coord[offset_types]) -> Pointer[SIMD[offset_dtype, element_width], offset_origin, address_space=offset_address_space]
Returns a storage handle offset by a number of scalar elements.
The dynamic offset advances the handle itself; the static offset remains in the policy's parameters and continues to apply on top.
Parameters:
- βoffset_mut (
Bool): The mutability of the storage, inferred fromoffset_origin. - βoffset_types (
TypeList[offset_types.values]): The coordinate element types ofoffset_coord. - βoffset_dtype (
DType): The element data type of the storage. - βoffset_origin (
Origin[mut=offset_mut]): The origin tracking the lifetime of the storage. - βoffset_address_space (
AddressSpace): The address space the storage resides in.
Args:
- βstorage (
Pointer[SIMD[offset_dtype, element_width], offset_origin, address_space=offset_address_space]): The storage to offset from. - βoffset_coord (
Coord[offset_types]): A rank-1 coordinate holding the number of scalar elements to advance the handle by.
Returns:
Pointer[SIMD[offset_dtype, element_width], offset_origin, address_space=offset_address_space]: A handle of the same type starting the given number of scalar
elements into the referenced storage.
distanceβ
static def distance[dtype: DType, address_space: AddressSpace, //](storage: Pointer[SIMD[dtype, element_width], address_space=address_space], other: Pointer[SIMD[dtype, element_width], address_space=address_space]) -> Int
Returns the scalar-element distance from other to storage.
Both handles carry the same static offset, so it cancels out of the distance.
Parameters:
- βdtype (
DType): The storages'DType. - βaddress_space (
AddressSpace): The storages'AddressSpace.
Args:
- βstorage (
Pointer[SIMD[dtype, element_width], address_space=address_space]): The storage to measure the distance to. - βother (
Pointer[SIMD[dtype, element_width], address_space=address_space]): The storage to measure the distance from.
Returns:
Int: The number of scalar elements separating the two handles. The
value is positive when storage is ahead of other and negative
when it precedes other.
copy_fromβ
static def copy_from[SelfLayoutType: TensorLayout, self_origin: MutOrigin, self_address_space: AddressSpace, OtherLayoutType: TensorLayout, other_mut: Bool, other_origin: Origin[mut=other_mut], other_address_space: AddressSpace, //, dst_dtype: DType, src_dtype: DType, OtherStorage: TensorStorage](storage: Tuple[Pointer[SIMD[dst_dtype, element_width], self_origin, address_space=self_address_space], SelfLayoutType], other: Tuple[OtherStorage.StorageType[other_mut, origin_of(other_origin), src_dtype, other_origin, other_address_space], OtherLayoutType])
Copies the elements of other into storage, in place.
Delegates to the shared _copy_from loop; destination accesses go
through this policy's load/store, so the static offset applies.
Parameters:
- βSelfLayoutType (
TensorLayout): The layout type of the destination storage. - βself_origin (
MutOrigin): The origin of the destination storage. - βself_address_space (
AddressSpace): The address space of the destination storage. - βOtherLayoutType (
TensorLayout): The layout type of the source storage. - βother_mut (
Bool): The mutability of the source storage. - βother_origin (
Origin[mut=other_mut]): The origin of the source storage. - βother_address_space (
AddressSpace): The address space of the source storage. - βdst_dtype (
DType): The element data type of the destination storage. - βsrc_dtype (
DType): The element data type of the source storage. - βOtherStorage (
TensorStorage): The storage policy of the source. May differ fromSelfas long as the two policies are copy-compatible (same logical element size).
Args:
- βstorage (
Tuple[Pointer[SIMD[dst_dtype, element_width], self_origin, address_space=self_address_space], SelfLayoutType]): A tuple of the destination storage (modified in place) and its layout. - βother (
Tuple[OtherStorage.StorageType[other_mut, origin_of(other_origin), src_dtype, other_origin, other_address_space], OtherLayoutType]): A tuple of the source storage and its layout.