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

ldg

def ldg[dtype: DType, //, width: Int = Int(1), *, alignment: Int = Int((get_alignof SIMD[dtype, width], _current_target()))](x: Pointer[Scalar[dtype]]) -> SIMD[dtype, width] where dtype.is_numeric()

Load data from global memory through the non-coherent cache.

This function provides a hardware-accelerated global memory load operation that uses the GPU's non-coherent cache (equivalent to CUDA's __ldg instruction). It optimizes for read-only data access patterns.

Note:

  • Uses invariant loads which indicate the memory won't change during kernel execution.
  • Particularly beneficial for read-only texture-like access patterns.
  • May improve performance on memory-bound kernels.

Parameters:

  • ​dtype (DType): The data type to load (must be numeric).
  • ​width (Int): The SIMD vector width for vectorized loads.
  • ​alignment (Int): Memory alignment in bytes. Defaults to natural alignment of the SIMD vector dtype.

Args:

Returns:

SIMD[dtype, width]: SIMD vector containing the loaded data.

Was this page helpful?