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 module

platform_predicates

Platform predicates for the cond argument of @extensibility.register.

A platform predicate selects the devices that a kernel registration applies to. Build one from the type, api, arch, and model atoms below, and combine predicates with & and |. The CPU, ACCELERATOR, CUDA, HIP, and METAL aliases in extensibility.platforms cover the common cases. Name a predicate for a specific device with comptime, and pass the name to register:

comptime B200 = ACCELERATOR & CUDA & model("NVIDIA B200")

@extensibility.register("mo.matmul", B200)
struct B200Matmul:
    ...

& and | flatten and order their operands, so CUDA | HIP and HIP | CUDA are the same type. Predicates that select the same devices need not be spelled the same way, or have the same type, as CUDA and ACCELERATOR & CUDA show: the graph compiler compares predicates by the devices they select, not by their type.

A platform predicate is not a Bool: only register accepts it.

When more than one registration of an op matches a device, the graph compiler selects the registration whose predicate selects the fewest devices: its set of devices must be a strict subset of the set of every other match. The graph compiler compares predicates only through string equality on the four device fields. Thus a predicate must state every field that it depends on. For example, CUDA is type("gpu") & api("cuda"), so a CUDA kernel is more specific than a kernel registered for all accelerators.

comptime values​

PlatformExpr​

comptime PlatformExpr = __generator_type[label: KGENString, api: KGENString, arch: KGENString, model: KGENString] __mlir_type.`!kgen.scalar<bool>`

The expression of a platform predicate: what it tests on a device.

A predicate may compare the label, API, architecture, or model of a device with a string literal, and combine those tests with & and |. The graph compiler reads the expression as data when it imports a kernel, so it rejects anything else, and it rejects a predicate that holds for no device.

Structs​

Functions​

  • ​api: Returns a platform predicate that holds when the device API equals value.
  • ​arch: Returns a platform predicate that holds when the device architecture equals value.
  • ​model: Returns a platform predicate that holds when the device model equals value.
  • ​type: Returns a platform predicate that holds when the device label equals value.

Was this page helpful?