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

Support default configs for BATCH_MATMUL_* in MaterializeEncoding pass #14762

Merged
merged 1 commit into from
Aug 24, 2023

Conversation

pzread
Copy link
Contributor

@pzread pzread commented Aug 21, 2023

In #14705 we added BATCH_MATMUL_* encoding users and handled the materialization in IREE codegen path by providing a custom MaterializeEncodingFn. However MaterializeEncoding pass also can be called standalone, this change updates the default chooseEncodingInfo function to support new encoding users.

This is done by moving chooseEncodingInfoForMatmul under LinalgExt to reuse the logic of deciding materialization based on matmul encoding.

The problem was found when adding tests for MaterializeEncoding with BATCH_MATMUL_* encoding users, since MaterializeEncoding pass is called standalone by --iree-linalg-ext-materialize-encoding

#14431

Copy link
Contributor Author

@pzread pzread Aug 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to add this code in to LinalgExt/Utils/Utils.h, but LinalgExt/Utils/Utils.h is used in LinalgExt/IR/LinalgExtOps.cpp. And we need to use linalg_ext ops, which results in cyclic library dependencies.

I'm not sure what the better way is to solve this. Here I simply creates a separate utils library.

If I put this code into LinalgExt/Utils/Utils.h and add IREELinalgExtDialect to the dependencies of IREELinalgExtUtils, I'll get the error:

CMake Error: The inter-target dependency graph contains the following strongly connected component (cycle):
  "obj.IREELinalgExtDialect" of type OBJECT_LIBRARY
  depends on "IREELinalgExtUtils" (strong)
  "IREELinalgExtDialect" of type STATIC_LIBRARY
  depends on "obj.IREELinalgExtDialect" (strong)
  depends on "IREELinalgExtUtils" (strong)
  "obj.IREELinalgExtUtils" of type OBJECT_LIBRARY
  depends on "IREELinalgExtDialect" (strong)
  "IREELinalgExtUtils" of type STATIC_LIBRARY
  depends on "IREELinalgExtDialect" (strong)
  depends on "obj.IREELinalgExtUtils" (strong)
  
At least one of these targets is not a STATIC_LIBRARY.  Cyclic dependencies are allowed only among static libraries.
CMake Generate step failed.  Build files cannot be regenerated correctly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WHy does Utils needs IR ?

Copy link
Contributor Author

@pzread pzread Aug 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new code added here needs IREE::LinalgExt::EncodingUser, which is defined in LinalgExt/IR/LinalgExtOps.h. So if we add the code into LinalgExt/Utils/Utils.h instead, IIUC IREELinalgExtUtils will have a dependency to IREELinalgExtDialect.

On the other hand, LinalgExtOps.cpp is using getDimValue and computeInterchangeFromDimPos defined in Utils.cpp, so it currently has a dependecy to IREELinalgExtUtils

https://github.com/openxla/iree/blob/5142828f9d6fb761c98900e45f4e398c6da9af6d/llvm-external-projects/iree-dialects/lib/Dialect/LinalgExt/IR/CMakeLists.txt#L12-L13

Copy link
Contributor Author

@pzread pzread Aug 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify, here I'm trying to move chooseEncodingInfoForMatmul from IREE codegen into LinalgExt so we can reuse the same logic to choose tiling and permutations for materialization based on LinExt::EncodingUser.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've seen similar issues in MLIR repo. I think the solution is that *IR should not depends on *Util. The common methods are moved to *IR.h in upstream, and we can probably follow the convention. Dependency issue looks fine to me, and we can refactor it later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MaheshRavishankar Kindly ping : ) Do you have further comments on this PR?

@pzread pzread marked this pull request as ready for review August 21, 2023 17:25
@pzread pzread changed the title Add default configs for BATCH_MATMUL_* in MaterializeEncoding pass Support default configs for BATCH_MATMUL_* in MaterializeEncoding pass Aug 21, 2023
@hanhanW hanhanW requested a review from bjacob August 21, 2023 22:01
@pzread
Copy link
Contributor Author

pzread commented Aug 24, 2023

@RoboTux FYI

Copy link
Contributor

@MaheshRavishankar MaheshRavishankar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Sorry I didnt know you were waiting for me to approve. I saw Hanhan approve so I just left it at that.

@pzread pzread merged commit 8314b5c into iree-org:main Aug 24, 2023
50 checks passed
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

Successfully merging this pull request may close these issues.

3 participants