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

register

def register(name: StaticString)

Registers a struct as a kernel implementation of a MAX Graph op for all devices.

@extensibility.register("mo.matmul")
struct Matmul:
    ...

To restrict a registration to some devices, use the cond overload of register with a platform.

Args:

  • ​name (StaticString): The MAX Graph op name to register (e.g. "mo.matmul").

def register[expr: PlatformExpr, //](name: StaticString, cond: PlatformPredicate[expr], /)

Registers a struct as a kernel implementation for the devices that cond selects.

Build cond from the aliases in extensibility.platforms and the atoms in extensibility.platform_predicates. Give each platform that uses the type, api, arch, or model atoms a name with comptime, and pass that name as cond. In the alias, state every level of the device above the narrowest one that it tests, even when a helper already implies it:

comptime TCGEN05 = ACCELERATOR & CUDA & (arch("sm_100a") | arch("sm_103a"))

@extensibility.register("mo.matmul", CPU)
struct CpuMatmul:
    ...

@extensibility.register("mo.matmul", ACCELERATOR)
struct AcceleratorMatmul:
    ...

@extensibility.register("mo.matmul", TCGEN05)
struct TcgenMatmul:
    ...

The Graph Compiler selects a kernel for each op and device as follows:

  1. It keeps the registrations whose platform holds for the device.
  2. If a user-defined registration remains, it keeps only the user-defined ones. Otherwise it keeps the built-in ones.
  3. It selects the registration whose set of devices is a strict subset of the set of every other remaining registration. In the example, a B200 matches AcceleratorMatmul and TcgenMatmul, and TcgenMatmul wins.

If no registration is a strict subset of all the others, the selection is ambiguous and the Graph Compiler reports an error. To resolve it, narrow a platform or register a kernel for exactly the devices that overlap. Two registrations of the same op for the same set of devices, both built-in or both user-defined, are an error, because neither can ever be selected.

Parameters:

  • ​expr (PlatformExpr): The expression of the platform, inferred from cond.

Args:

Was this page helpful?