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 function
strided_load
def strided_load[dtype: DType, //, simd_width: SIMDLength, stride: Int, *, alignment: Int = Int((get_alignof Scalar[dtype], _current_target())), invariant: Bool = True](addr: Pointer[Scalar[dtype], address_space=addr.address_space], mask: SIMD[DType.bool, simd_width] = SIMD(fill=True)) -> SIMD[dtype, simd_width]
Loads simd_width values from addr with a compile-time stride.
Knowing the stride at compile time lets the two common cases avoid the
gather used by the runtime-stride overload (which lowers to scattered
per-element loads on NVIDIA GPUs): a contiguous stride == 1 load becomes a
single coalesced vector load, and a stride == 0 broadcast becomes one
scalar load splatted across lanes. Any other stride (or a partially-masked
load) delegates to the runtime-stride overload.
Body authors use this for side-input loads (gamma/beta/cos/sin) along the
reduced axis: inner axis gives stride=1, a non-inner axis gives
stride=0 (one value per row, splatted across the tile).
invariant defaults True: addr is always mut=False here, and every
current call site loads a read-only weight/side input (never aliased by
an output of the same kernel), so the load-invariant hint is safe by
construction. Pass invariant=False explicitly if a future call site's
memory isn't provably invariant for the kernel's duration.
Parameters:
- βdtype (
DType): DType of the loaded value. - βsimd_width (
SIMDLength): The width of the SIMD vector. - βstride (
Int): The compile-time stride, in elements, between lanes. - βalignment (
Int): Alignment in bytes of the contiguousstride == 1load; defaults to the element alignment. Pass the SIMD-natural alignment whenaddris known to be vector-aligned to fold the load into one access. - βinvariant (
Bool): Whether the memory is load invariant.
Args:
- βaddr (
Pointer[Scalar[dtype], address_space=addr.address_space]): The memory location to load data from. - βmask (
SIMD[DType.bool, simd_width]): A binary vector which prevents memory access to certain lanes of the result.
Returns:
SIMD[dtype, simd_width]: A vector containing the loaded data.