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).
Python function
declare
declare()
max.experimental.custom.declare(name, *, inputs, outputs, parameters=None, custom_extensions=())
Declares a custom op from its signature.
Validates the signature, compiles any Mojo source package, and resolves
the kernel against custom_extensions once, here, rather than on
every call.
-
Parameters:
-
- name (str) – The registered kernel symbol.
- inputs (Mapping[str, TemplateType]) – One
TemplateTypeper operand, keyed by a name used in diagnostics and accepted as a keyword at call time. Iteration order is operand order. - outputs (Sequence[TemplateType]) – One
TemplateTypeper result. Dims may only be statics,SymbolandParamvalues, or expressions over them. ASymbolno input binds is data-dependent: the kernel must register a shape function with@extensibility.register_shape_function(see the “Declare the output shape” section of https://docs.modular.com/max/develop/build-custom-ops). - parameters (Mapping[str, bool | int | float | str | DType | None] | None) – Compile-time parameters passed to the kernel. A value of
Nonedeclares the parameter without giving it one yet, leaving anyParamnaming it unresolved (seeCustomOp.is_complete). - custom_extensions (Sequence[Path | str]) – Paths to the Mojo packages defining the kernel.
-
Returns:
-
An immutable
CustomOp. -
Raises:
-
- ValueError – If
inputsoroutputsis empty, or if neithercustom_extensionsnor the process-global overlay registersname. - TypeError – If a dim names a symbol that is neither a
Symbolnor aParam. - MojoCompilationError – If a source package fails to compile.
- ValueError – If
-
Return type: