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
match_any
def match_any[dtype: DType, //, mask_type: DType = DType.uint32 if (DefaultMaxPlugin if (xor _index_lt[PluginSelector._find[_current_target(), 0, trap_if_missing=False](), 0](), True) else [PluginSelector._find[_current_target(), 0, trap_if_missing=False]()] if (xor _index_lt[PluginSelector._find[_current_target(), 0, trap_if_missing=False](), 3](), True) else CudaMaxPlugin, HipMaxPlugin, MetalMaxPlugin[PluginSelector._find[_current_target(), 0, trap_if_missing=False]()] if identical(_NoMaxPlugin if (xor _index_lt[TargetPluginSelector._find[0](), len(#kgen.get_target_plugin<apply(:!lit.generator<() -> !kgen.target> @std::@sys::@info::@"_current_target()"), :param_list<trait<@std::@traits::@anytype::@AnyType>> [@max::@_plugin::@_impl::@_NoMaxPlugin]>)](), True) else #kgen.get_target_plugin<apply(:!lit.generator<() -> !kgen.target> @std::@sys::@info::@"_current_target()"), :param_list<trait<@std::@traits::@anytype::@AnyType>> [@max::@_plugin::@_impl::@_NoMaxPlugin]>[TargetPluginSelector._find[0]()](MaxPlugin), _NoMaxPlugin) else _NoMaxPlugin if (xor _index_lt[TargetPluginSelector._find[0](), len(#kgen.get_target_plugin<apply(:!lit.generator<() -> !kgen.target> @std::@sys::@info::@"_current_target()"), :param_list<trait<@std::@traits::@anytype::@AnyType>> [@max::@_plugin::@_impl::@_NoMaxPlugin]>)](), True) else #kgen.get_target_plugin<apply(:!lit.generator<() -> !kgen.target> @std::@sys::@info::@"_current_target()"), :param_list<trait<@std::@traits::@anytype::@AnyType>> [@max::@_plugin::@_impl::@_NoMaxPlugin]>[TargetPluginSelector._find[0]()](MaxPlugin).HookFor[CompilationTarget(Int(0))].warp_size <= Int(32)) else DType.uint64](value: Scalar[dtype]) -> Scalar[mask_type]
Finds, for each lane, the mask of warp lanes whose value bits match it.
Returns a per-lane lane mask whose bit l is set for every active lane l
whose value has the same bit pattern as the calling lane's. The comparison
is on the bits (matching NVIDIA's match.any.sync), so 0.0 and -0.0 do
not match while two NaNs with equal bits do. This is the fold a warp uses
to coalesce same-keyed lanes (a histogram or scatter leader handling a whole
group in one non-atomic update) instead of one atomic per lane.
All WARP_SIZE lanes must reach the call converged.
Example:
from max.gpu.primitives.warp import match_any
# If lanes 0, 3, 7 hold the same value, each of them gets a mask with
# bits 0, 3, and 7 set; the remaining lanes get their own groups.
var my_key = Int32(42)
var group = match_any(my_key)Constraints:
Requires a GPU target with warp shuffles. dtype must be a 32- or
64-bit type and mask_type must be DType.uint32 or DType.uint64
(NVIDIA returns a 32-bit mask, so mask_type must be DType.uint32
there).
Parameters:
- โdtype (
DType): The element type ofvalue(inferred from the argument). - โmask_type (
DType): The lane-mask return type,DType.uint32orDType.uint64(defaults to the type matchingWARP_SIZE).
Args:
- โvalue (
Scalar[dtype]): The calling lane's value to match against the rest of the warp.
Returns:
Scalar[mask_type]: A mask_type lane mask with bit l set for each active lane l holding
a bit-equal value.