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

shuffle_up

def shuffle_up[dtype: DType, simd_width: SIMDLength, //](val: SIMD[dtype, simd_width], offset: UInt32) -> SIMD[dtype, simd_width]

Copies values from threads with lower lane IDs in the warp.

Performs a shuffle operation where each thread receives a value from a thread with a lower lane ID, offset by the specified amount. Uses the full warp mask by default.

For example, with offset=1:

  • Thread N gets value from thread N-1
  • Thread 1 gets value from thread 0
  • Thread 0 gets undefined value

Parameters:

  • dtype (DType): The data type of the SIMD elements (e.g. float32, int32).
  • simd_width (SIMDLength): The number of elements in each SIMD vector.

Args:

Returns:

SIMD[dtype, simd_width]: The SIMD value from the thread offset lanes lower in the warp. Returns undefined values for threads where lane_id - offset < 0.

def shuffle_up[dtype: DType, simd_width: SIMDLength, //](mask: UInt, val: SIMD[dtype, simd_width], offset: UInt32) -> SIMD[dtype, simd_width]

Copies values from threads with lower lane IDs in the warp.

Performs a shuffle operation where each thread receives a value from a thread with a lower lane ID, offset by the specified amount. The operation is performed only for threads specified in the mask.

For example, with offset=1:

  • Thread N gets value from thread N-1 if both threads are in the mask
  • Thread 1 gets value from thread 0 if both threads are in the mask
  • Thread 0 gets undefined value
  • Threads not in the mask get undefined values

Parameters:

  • dtype (DType): The data type of the SIMD elements (e.g. float32, int32).
  • simd_width (SIMDLength): The number of elements in each SIMD vector.

Args:

  • mask (UInt): The warp mask specifying which threads participate in the shuffle.
  • val (SIMD[dtype, simd_width]): The SIMD value to be shuffled up the warp.
  • offset (UInt32): The number of lanes to shift values up by.

Returns:

SIMD[dtype, simd_width]: The SIMD value from the thread offset lanes lower in the warp. Returns undefined values for threads where lane_id - offset < 0 or threads not in the mask.

Was this page helpful?