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).
PointerStorage
struct PointerStorage
Implements TensorStorage backed by a raw UnsafePointer.
PointerStorage is the default storage policy for TileTensor. Its
StorageType handle is a plain UnsafePointer, and every operation is
expressed directly in terms of the underlying pointer.
Implemented traits
AnyType,
ImplicitlyDeletable,
TensorStorage
comptime members
StorageType
comptime StorageType[mut: Bool, //, dtype: DType, origin: Origin[mut=mut], address_space: AddressSpace] = UnsafePointer[Scalar[dtype], origin, address_space=address_space]
A raw UnsafePointer to Scalar[dtype] borrowing the storage.
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: UnsafePointer[Scalar[dtype], address_space=storage.address_space]) -> UnsafePointer[Scalar[to_dtype], to_origin, address_space=to_address_space]
Reinterprets a storage handle with new type parameters.
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 (
UnsafePointer[Scalar[dtype], address_space=storage.address_space]): The storage to reinterpret.
Returns:
UnsafePointer[Scalar[to_dtype], 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: SIMDSize, alignment: Int](storage: UnsafePointer[Scalar[dtype], address_space=storage.address_space]) -> SIMD[dtype, width]
Loads a SIMD value from the storage.
Parameters:
- width (
SIMDSize): The number of elements to load. - alignment (
Int): The alignment guarantee for the load.
Args:
- storage (
UnsafePointer[Scalar[dtype], address_space=storage.address_space]): The storage to load from.
Returns:
SIMD[dtype, width]: The loaded SIMD value.
static def load[dtype: DType, //, width: SIMDSize, alignment: Int](storage: UnsafePointer[Scalar[dtype], address_space=storage.address_space], offset: T) -> SIMD[dtype, width]
Loads a SIMD value at an element offset from the storage.
Parameters:
- width (
SIMDSize): The number of elements to load. - alignment (
Int): The alignment guarantee for the load.
Args:
- storage (
UnsafePointer[Scalar[dtype], address_space=storage.address_space]): The storage to load from. - offset (
T): The element offset to load at.
Returns:
SIMD[dtype, width]: The loaded SIMD value.
store
static def store[dtype: DType, //, alignment: Int](storage: UnsafePointer[Scalar[dtype], address_space=storage.address_space], value: SIMD[dtype])
Stores a SIMD value into the storage.
Parameters:
- alignment (
Int): The alignment guarantee for the store.
Args:
- storage (
UnsafePointer[Scalar[dtype], address_space=storage.address_space]): The storage to store into. - value (
SIMD[dtype]): TheSIMDvalue to store.
static def store[dtype: DType, //, alignment: Int](storage: UnsafePointer[Scalar[dtype], address_space=storage.address_space], offset: T, value: SIMD[dtype])
Stores a SIMD value at an element offset in the storage.
Parameters:
- alignment (
Int): The alignment guarantee for the store.
Args:
- storage (
UnsafePointer[Scalar[dtype], address_space=storage.address_space]): The storage to store into. - offset (
T): The element offset to store at. - value (
SIMD[dtype]): TheSIMDvalue to store.
offset
static def offset(storage: UnsafePointer[Scalar[dtype], address_space=storage.address_space], offset: T) -> UnsafePointer[Scalar[dtype], storage.origin, address_space=storage.address_space]
Returns a storage handle offset by a number of elements.
The returned handle refers to the same externally owned storage,
advanced by offset elements.
Args:
- storage (
UnsafePointer[Scalar[dtype], address_space=storage.address_space]): The storage to offset from. - offset (
T): The number of elements to advance the handle by.
Returns:
UnsafePointer[Scalar[dtype], storage.origin, address_space=storage.address_space]: A handle of the same type starting offset elements into the
referenced storage.
distance
static def distance[dtype: DType, address_space: AddressSpace, //](storage: UnsafePointer[Scalar[dtype], address_space=address_space], other: UnsafePointer[Scalar[dtype], address_space=address_space]) -> Int
Returns the element distance from other to storage.
Parameters:
- dtype (
DType): The storages'DType. - address_space (
AddressSpace): The storages'AddressSpace.
Args:
- storage (
UnsafePointer[Scalar[dtype], address_space=address_space]): The storage to measure the distance to. - other (
UnsafePointer[Scalar[dtype], address_space=address_space]): The storage to measure the distance from.
Returns:
Int: The number of elements separating the two handles. The value is
positive when storage is ahead of other and negative when it
precedes other.