Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tuner] Offload op_matchers.py logic to IREE compiler #1110

Open
Max191 opened this issue Mar 18, 2025 · 0 comments
Open

[Tuner] Offload op_matchers.py logic to IREE compiler #1110

Max191 opened this issue Mar 18, 2025 · 0 comments
Assignees

Comments

@Max191
Copy link
Contributor

Max191 commented Mar 18, 2025

As we want to add more and more op support in the tuner, we need a more maintainable solution for matching ops and extracting relevant problem size information in the tuner. Currently, this logic lives in https://github.com/nod-ai/shark-ai/blob/main/tuner/tuner/op_matchers.py.

ContractionOpInterface

We should offload this logic to the python bindings in IREE, and directly use the python bindings in the tuner. Most of the logic in op_matchers.py is there to match and extract information about ContractionOpInterface ops, but this logic already exists in upstream MLIR:
https://github.com/llvm/llvm-project/blob/d85a81b4e4cfc0fdc7c259d64f847e7bbeee56d2/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.h#L41-L71

We want to expose those functions to the MLIR python bindings, so we can use it in the tuner instead of rewriting the logic in python.

Root Op Matching

The other part of the op_matchers.py logic is for picking out the "root op" from the dispatch. We want this logic to be exposed in the IREE python bindings, and then we can remove the python logic in the tuner. See iree-org/iree#20292 for more details.

Tuner Work

Once we have exposed the necessary utils in the bindings, we should ideally remove the op_matchers.py file altogether. The op_matchers.py file primarily defines a set of matcher classes for the types of ops we care about (mainly some named ops and contraction ops). We should delete these classes, and replace the uses of them with a few simple calls to the relevant python bindings. For example, the section here:

contraction_op = match_root_op(ir_module, matcher)
assert contraction_op is not None, f"contraction op not found"
contraction_dims = matcher.contraction_dimensions

Can be replaced by a call to the binding for the exposed root op matching, followed by calls to linalg::isaContractionOpInterface, and linalg::inferContractionDims bindings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant