Extending passes¶
Passes are the entry point for optimization knowledge. A pass reads current typed semantics and execution relationships, rewrites real IR and hands a complete program to later consumers. Before adding an optimization, read passes and analyses, the relevant GPU/CPU contract and target lowering.
Locate the responsible layer¶
| Change | Responsible location |
|---|---|
| Domain, dtype, effects and algorithm semantics | DSL / canonical KIR; discuss design changes separately |
| Def-use, coordinates, aliasing, dependence and working-set queries | The dialect's Analysis/ |
| Ownership, traversal, blocking, reuse and materialization | Responsibility groups in GPU/CPU/DSA Transforms/ |
| Capabilities, implementations, local forms and legality | lib/Target/<Provider>/ |
| Source API spelling | Target serialization |
| ABI binding, toolchain invocation and tuning calls | python/intent/runtime/<provider>/ |
GPU and CPU may reuse analysis ideas without sharing a physical topology. A pass need not run on every backend. Shared facts, independent decisions and appropriate target consumers are useful reuse.
A complete optimization component¶
- Define legality from current typed operands, regions, def-use, access relations, effects, lifetimes and capabilities, never kernel names, operation counts or string labels.
- Let analyses provide recomputable facts. Unknown is not permission to replay, alias or assume initialization.
- Rewrite operations, types, regions, coordinates, carries or resource lifetimes. Do not introduce a schema/plan that jointly interprets execution alongside IR.
- Preserve logical members, dtypes, numerical permissions, ordered control, effects, ABI and the author's kernel count.
- Declare invalidated analyses and check postconditions after a complete transformation group. Verifiers do not repair programs; serializers do not add loops, workspace or parameters.
Use existing MLIR pass declaration, registration and pipeline mechanisms. Inspect include/Intent/Dialect/<Family>/Transforms/Passes.td, lib/Dialect/<Family>/Transforms/ and its Passes.cpp; target-local transformations live in lib/Target/<Provider>/Transforms/. intent-opt --help lists actual callable passes and options.
intent components --compiler /path/to/intent-compile --json lists compiled
components with their MLIR name, owner, stage, required flag and description.
Keep registration beside the owning pipeline and use registerTransformation
and addTransformation; do not add backend-name branches to the public driver.
CompileOptions(optimizations={"intent-cpu-fuse-tensor-computations": False})
or CLI --optimization NAME=false disables a complete optional component without
granting numerical permissions. New components must state their legal unoptimized
representation; missing lowering is not an optimization-disable failure.
For example, block-program reduction optimizations live in lib/Dialect/Block/Transforms/Reduction/, declarations in Block Passes.td, and complete transformation entry points and ordering in Block Transforms/Passes.cpp. CPU task partitioning and storage reuse live in CPU Transforms/Task/ and Transforms/Storage/; CPU Transforms/Passes.cpp assembles that family's pipeline. Do not move a GPU ownership transformation there to force reuse. Provider empirical configuration tables live in the corresponding Transforms/ or Transforms/Configuration/.
Add new implementations to the adjacent CMake list. Reuse an existing transformation wrapper's registration, dependent dialects, error propagation and completed-boundary verification. Insert the pass where its input conditions hold rather than adding a bypass for one program.
Changing complete empirical configurations does not require a new pass. When a provider owns collective trees, thread communication, distributed layouts or machine pipelines, supply legal input instead of rebuilding that mechanism in Intent.
intent-cpu-specialize-singleton-tasks branches on the actual task count. Only the
single-participant branch replaces relaxed atomic add with load/add/store while
preserving its old value. Concurrent participants retain atomics. Required task
dispatch lowering consumes the worker count in the current IR; Mojo and Weft
serializers do not dispatch the hardware's maximum thread count independently.
intent-mojo-vectorize-reduction-panels keeps a contiguous group of independent
outputs in vector registers while traversing their reduction members. Each lane
uses the original scalar combine and predicate. It checks output ownership and
strides, and uses the selected vector_width and register_replicas. Disabling
it leaves the structured reduction for ordinary Mojo lowering.
intent-weft-tile-scans consumes the selected finite panel parameter and forms
bounded prefixes, block carries and tails. Canonical Weft ScanOp owns the native
collective, with the source combine, inclusive/exclusive and reverse semantics.
Disabling this component retains the complete ordered traversal. Intent does not
duplicate the provider's SIMD/RVV shuffle tree.
intent-bangc-compose-private-versions coalesces unobserved private
copy/update/copy-back sequences and forwards complete initialization in the
BANG C physical program. Its proofs use storage aliasing, effects, dominance
and completion; unknown or asynchronous effects retain the copies. Matrix supply
can then consume computations previously separated by those copies. Disabling
the component leaves a legal explicit storage program.
intent-cutile-select-cluster-configurations follows matrix operand def-use to
select already declared complete single-CTA rows for computed operands. Ordinary
load-fed matrix computations retain cluster candidates. It invents no new
configuration. Pruning empirical rows for a configuration family only requires
changing the provider's configuration table.
intent-cutile-select-carried-reduction-configurations recognizes a reduction
over a full axis fed by a rank-two loop carry. The other axis's fragment width
controls both live state and the number of independent outputs. The component
prefers declared rows with narrow fragments and keeps the original portfolio
when every row is wide. Disabling it compiles all rows under the same numerical
contract.
Observe existing programs¶
Choose affected complete programs, inspect before/after IR and generated source, verify actual calls and observe warm execution for the same algorithm and input. Do not copy algorithms or expand a test matrix. Benefits on another related program show the reuse scope. Report generation, native compilation, execution, numerical checking and performance improvement separately.
Use a standard MLIR pipeline on already generated IR that satisfies the pass's preconditions:
Replace the pipeline with transformations listed by current intent-opt --help and applicable to that stage. Shared GPU passes cannot consume KIR or modules with provider-native forms already added. Native compiler MLIR IR-printing options locate a pass's input in the complete compilation. Re-run the corresponding complete program to observe the optimization; isolated IR optimization does not establish runtime results.
The repository contribution guide covers development setup; compiler development entry points locate public APIs, implementation layers and stage diagnostics.