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

Create a canonicalization pass in TT-MLIR compiler #1264

Open
sdjordjevicTT opened this issue Nov 14, 2024 · 0 comments
Open

Create a canonicalization pass in TT-MLIR compiler #1264

sdjordjevicTT opened this issue Nov 14, 2024 · 0 comments
Assignees
Labels
TTIR Dialect Issues related to TTIR dialect

Comments

@sdjordjevicTT
Copy link
Contributor

To improve the efficiency and reliability of our MLIR compiler, we need to introduce a canonicalizer pass. This pass should apply a range of canonicalization patterns that simplify and normalize the intermediate representation (IR). Canonicalization makes IR easier to optimize and analyze by reducing redundant patterns and ensuring consistency in how operations are represented. Currently, our compiler lacks a centralized approach for defining and managing these patterns, making it difficult to ensure consistent transformations across components.

@sdjordjevicTT sdjordjevicTT added the TTIR Dialect Issues related to TTIR dialect label Nov 15, 2024
azecevicTT added a commit that referenced this issue Jan 15, 2025
Canonicalization can be roughly divided into three forms:
1. Traits (properties) of some ops that allows them to be folded
(Involution, Idempotence)
2. Per op foldings
4. Per op canonicalization (pattern rewriters)

The first one allows us to decleratively add folding for a large class
of ops. While traits like `Involution` already exists in `MLIR`
infrastructure it doesn't account for DPS, so I added a new one that
takes care of it.
The second one allows us in practice to define some simple graph
rewritings where we replace the producing value of op with some existing
value (or constant).
The third one gives us the most freedom, where we can do arbitrary graph
rewritings, we usually use it when we have to create a new op during
rewriting.

I added a `canonicalize` pass both before and after
`ttir-to-ttir-decomposition-pass` in `ttir-to-ttnn-backend-pipeline`, as
there are many graph rewritings during that pass, so we might benefit
form canonicalization both before and after.

I plan to cover one big part of canonicalization in the future, and
that's constant folding. I will also write a short document on adding a
canonicalization for new and existing ops. While this PR covers a lot of
patterns, it's definitely not an exhaustive list. This MLIR
[doc](https://mlir.llvm.org/docs/Canonicalization/) is already a great
source of information, I just believe we might also benefit from the
additional context of TTIR dialect.

This PR should cover a big part of
#1264, as I said the
missing part is constant folding.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TTIR Dialect Issues related to TTIR dialect
Projects
None yet
Development

No branches or pull requests

2 participants