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

StaticOffsetEngine

struct StaticOffsetEngine[*, static_offset: Int, element_width: Int = Int(1)]

Stub of the planned static-offset engine family.

Views externally owned memory like DefaultEngine, but starts every access static_offset scalar elements past the handle. The offset is encoded in the engine'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 engines 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 of 1 (the default) is a non-vectorized tensor; larger values describe a vectorized view whose logical elements are SIMD vectors.

Implemented traits​

AnyType, Deinitable, Movable, TensorEngine

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]] = StaticOffsetEngine[static_offset=static_offset, element_width=element_width]

The storage type produced by offsetting with a given coordinate.

Dynamic offsetting never changes the engine, 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 Pointer borrowing the storage, static_offset scalar elements before the viewed region.

Parameters​

  • ​mut (Bool): The mutability of the borrowed storage, inferred from origin.
  • ​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 engine'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:

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.

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 engine's parameters and continues to apply on top.

Parameters:

  • ​offset_mut (Bool): The mutability of the storage, inferred from offset_origin.
  • ​offset_types (TypeList[values]): The coordinate element types of offset_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:

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.

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, OtherEngine: TensorEngine](storage: Tuple[Pointer[SIMD[dst_dtype, element_width], self_origin, address_space=self_address_space], SelfLayoutType], other: Tuple[OtherEngine.StorageType[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 engine's unsafe_ptr, 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.
  • ​OtherEngine (TensorEngine): The engine of the source. May differ from Self as long as the two engines are copy-compatible (same logical element size).

Args:

Was this page helpful?