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 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 contiguous stride == 1 load; defaults to the element alignment. Pass the SIMD-natural alignment when addr is 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.