Skip to content

Explicitly insert dialects in conversion passes - #3002

Merged
ScottTodd merged 1 commit into
iree-org:mainfrom
iml130:registry_insert
Aug 26, 2020
Merged

ScottTodd merged 1 commit into
iree-org:mainfrom
iml130:registry_insert

Conversation

@marbre

@marbre marbre commented Aug 26, 2020 •

Copy link
Copy Markdown
Member

This inserts the dialects required in conversion passes by overwriting getDependentDialects().
Makes progress on #2958.

Overwrites getDependentDialects() to insert required dialects.
Progress on #2958.
@marbre

marbre commented Aug 26, 2020

Copy link
Copy Markdown
Member Author

There might be some dialects missing in the conversion passes. Furthermore, I don't get why clang-format complains.


struct ConvertHLOToLinalgOnTensorsPass
: public PassWrapper<ConvertHLOToLinalgOnTensorsPass, FunctionPass> {
void getDependentDialects(DialectRegistry &registry) const override {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The clang-format complaint is on this line - it wants

-  void getDependentDialects(DialectRegistry &registry) const override {
+  void getDependentDialects(DialectRegistry& registry) const override {

we're using the DerivePointerAlignment option (see https://clang.llvm.org/docs/ClangFormatStyleOptions.html) [1], which chooses the most common alignment of & and * in the file and sticks with that. In this case, we should be using the style you have here (as this is compiler code, roughly following LLVM style), but the rest of the file uses the other alignment:
https://github.com/google/iree/blob/6bd3b1dc13236566d1f8ee651cd3ab9b03dd8a1d/iree/compiler/Conversion/HLOToLinalg/HLOToLinalgOnTensors.cpp#L58-L59
https://github.com/google/iree/blob/6bd3b1dc13236566d1f8ee651cd3ab9b03dd8a1d/iree/compiler/Conversion/HLOToLinalg/HLOToLinalgOnTensors.cpp#L75-L76

You can either listen to clang-format here, or fix the rest of the file (preferably as part of a separate commit... but whatever, it's a small change :D)

[1] We could actually clean this up (@GMNGeoffrey) - We're technically using BasedOnStyle: Google: https://github.com/google/iree/blob/6bd3b1dc13236566d1f8ee651cd3ab9b03dd8a1d/.clang-format#L15-L18 which sets that option, while the LLVM style does not set the option. The cleanup would be to disable the internal tooling which has those issues now that we're developing directly on GitHub, then add BasedOnStyle: LLVM under iree/compiler.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we can't really switch to BasedOnStyle: LLVM because we still format with google formatting on import and export (we can work towards not needing to do that). This particular issue has come up a couple times though. Since Google style just derives from the rest of the file, we could enforce a specific alignment (probably following LLVM makes sense) to avoid mismatch across the project.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

because we still format with google formatting on import and export (we can work towards not needing to do that)

Yeah, that's what I'm suggesting. That formatting is also causing extra diffs in markdown and python files (which aren't really worth the trouble) when merging google -> main.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah but that will take a bit. Not formatting C++ will also mess up includes. So if we care about the pointer alignment specifically we could fix that without all the fixes necessary to turn off migration formatting entirely.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Okay, fixed with #3008, which was merged into main. And thanks a lot @ScottTodd for the detailed response, I realy appreciate this. I wasn't aware of the DerivePointerAlignment clang-format setting.

@joker-eph

Copy link
Copy Markdown
Contributor

FYI: to track down every missing use I did this internally:

diff --git a/mlir/lib/IR/MLIRContext.cpp b/mlir/lib/IR/MLIRContext.cpp
--- a/mlir/lib/IR/MLIRContext.cpp
+++ b/mlir/lib/IR/MLIRContext.cpp
@@ -366,8 +366,8 @@ MLIRContext::MLIRContext(bool loadAllDia
 
   // Register dialects with this context.
   getOrLoadDialect<BuiltinDialect>();
-  if (loadAllDialects)
-    loadAllGloballyRegisteredDialects();
+  // if (loadAllDialects)
+  //   loadAllGloballyRegisteredDialects();
 
   // Initialize several common attributes and types to avoid the need to lock
   // the context when accessing them.
diff --git a/mlir/lib/Support/MlirOptMain.cpp b/mlir/lib/Support/MlirOptMain.cpp
--- a/mlir/lib/Support/MlirOptMain.cpp
+++ b/mlir/lib/Support/MlirOptMain.cpp
@@ -91,8 +91,8 @@ static LogicalResult processBuffer(raw_o
   // Parse the input file.
   MLIRContext context(/*loadAllDialects=*/preloadDialectsInContext);
   registry.appendTo(context.getDialectRegistry());
-  if (preloadDialectsInContext)
-    registry.loadAll(&context);
+  // if (preloadDialectsInContext)
+  //   registry.loadAll(&context);
   context.allowUnregisteredDialects(allowUnregisteredDialects);
   context.printOpOnDiagnostic(!verifyDiagnostics);
 

@ScottTodd
ScottTodd merged commit 8341d71 into iree-org:main Aug 26, 2020
@marbre

marbre commented Aug 26, 2020

Copy link
Copy Markdown
Member Author

Th

FYI: to track down every missing use I did this internally:

diff --git a/mlir/lib/IR/MLIRContext.cpp b/mlir/lib/IR/MLIRContext.cpp
--- a/mlir/lib/IR/MLIRContext.cpp
+++ b/mlir/lib/IR/MLIRContext.cpp
@@ -366,8 +366,8 @@ MLIRContext::MLIRContext(bool loadAllDia
 
   // Register dialects with this context.
   getOrLoadDialect<BuiltinDialect>();
-  if (loadAllDialects)
-    loadAllGloballyRegisteredDialects();
+  // if (loadAllDialects)
+  //   loadAllGloballyRegisteredDialects();
 
   // Initialize several common attributes and types to avoid the need to lock
   // the context when accessing them.
diff --git a/mlir/lib/Support/MlirOptMain.cpp b/mlir/lib/Support/MlirOptMain.cpp
--- a/mlir/lib/Support/MlirOptMain.cpp
+++ b/mlir/lib/Support/MlirOptMain.cpp
@@ -91,8 +91,8 @@ static LogicalResult processBuffer(raw_o
   // Parse the input file.
   MLIRContext context(/*loadAllDialects=*/preloadDialectsInContext);
   registry.appendTo(context.getDialectRegistry());
-  if (preloadDialectsInContext)
-    registry.loadAll(&context);
+  // if (preloadDialectsInContext)
+  //   registry.loadAll(&context);
   context.allowUnregisteredDialects(allowUnregisteredDialects);
   context.printOpOnDiagnostic(!verifyDiagnostics);
 

Thanks @joker-eph :) At least for iree-opt, is this equivalent to passing /*preloadDialectsInContext=*/false to MlirOptMain()?

@rsuderman rsuderman mentioned this pull request Aug 26, 2020
copybara-service Bot pushed a commit that referenced this pull request Aug 26, 2020
* 6282700 Expand the tf_module_to_compiler_module API (#3009)
* f7e561a Merge pull request #3006 from rsuderman/google-to-main
* 8341d71 Explicitly insert dialects in conversion passes (#3002)
* b7c2b60 Fix format by changing to LLVM style (#3008)
* 4286f17 Merge branch 'main' into google-to-main
* f0a07f6 Allow iree.placeholder as an op between splittable ops. (#2999)
* 6bd3b1d Use hidden visibility for all symbols by default (#2997)
* d650082 VMLA Dynamic Iota support with Shape dialect work. (#2965)
* c724ee4 Add function to hide SavedModel roundtrip (#2995)
* 2fedce6 Merge pull request #2996
* c5f7030 Merge branch 'main' into google-to-main
* cf3211d [vulkan] Reset TimePointFence status when releasing back to pool (#2905)
* ebc6a83 Add lint action to check for tabs (#2984)
* 932339c Merge pull request #2964 from silvasean/add-dynamic-dot-example
* df727ae Integrate MLIR-EmitC at iml130/mlir-emitc@560cd8c (#2990)
* e824d36 Refactor for explicit dialect registration (#2978)
* 38b7d2c Allow ModelRunner to receive an array of extra symbols available during JITing..
* 264a97d Fuse linalg.tensor_reshape operations with hal.interface* operations. (#2973)
* 0e3c737 Fold flow.tensor.update when all operands are constant (#2982)
* c7a21c2 Merge pull request #2983 from rsuderman/google-to-main
* fd55a86 Add a dynamically shaped mhlo.dot lowering example

COPYBARA_INTEGRATE_REVIEW=#3012 from rsuderman:main-to-google 6282700
PiperOrigin-RevId: 328632208
@joker-eph

Copy link
Copy Markdown
Contributor

At least for iree-opt, is this equivalent to passing /preloadDialectsInContext=/false to MlirOptMain()?

The second part of the patch, yes, the first hunk affects non MlirOptMain creation of an MLIRContext as well.

@rsuderman rsuderman mentioned this pull request Aug 27, 2020
copybara-service Bot pushed a commit that referenced this pull request Aug 27, 2020
* aa8d1c0 Enable simple.mlir test for iree-benchmark-module on vulkan (#3016)
* 6db4e7b [vulkan] Release timepoint fences more aggressively when possible (#2800)
* a1365d3 [vulkan] Do not request timeline semaphore if not available (#2904)
* a38c890 Add more type support to model builder matmul benchmark. (#2977)
* a293ca7 Fix hyperlink to getting started docs on python page. (#3015)
* b022e70 Release inputs before closing the session. (#3004)
* f1678df Dynamicly register benchmark for entry_function with name BM_{entry_function} ..
* 6282700 Expand the tf_module_to_compiler_module API (#3009)
* f7e561a Merge pull request #3006 from rsuderman/google-to-main
* 8341d71 Explicitly insert dialects in conversion passes (#3002)
* b7c2b60 Fix format by changing to LLVM style (#3008)
* 4286f17 Merge branch 'main' into google-to-main
* f0a07f6 Allow iree.placeholder as an op between splittable ops. (#2999)
* 6bd3b1d Use hidden visibility for all symbols by default (#2997)
* d650082 VMLA Dynamic Iota support with Shape dialect work. (#2965)
* c724ee4 Add function to hide SavedModel roundtrip (#2995)
* 2fedce6 Merge pull request #2996
* c5f7030 Merge branch 'main' into google-to-main
* cf3211d [vulkan] Reset TimePointFence status when releasing back to pool (#2905)
* ebc6a83 Add lint action to check for tabs (#2984)
* 932339c Merge pull request #2964 from silvasean/add-dynamic-dot-example
* df727ae Integrate MLIR-EmitC at iml130/mlir-emitc@560cd8c (#2990)
* e824d36 Refactor for explicit dialect registration (#2978)
* 38b7d2c Allow ModelRunner to receive an array of extra symbols available during JITing..
* 264a97d Fuse linalg.tensor_reshape operations with hal.interface* operations. (#2973)
* 0e3c737 Fold flow.tensor.update when all operands are constant (#2982)
* c7a21c2 Merge pull request #2983 from rsuderman/google-to-main
* fd55a86 Add a dynamically shaped mhlo.dot lowering example

COPYBARA_INTEGRATE_REVIEW=#3018 from rsuderman:main-to-google 4a9ea02
PiperOrigin-RevId: 328784816
This was referenced Aug 27, 2020
copybara-service Bot pushed a commit that referenced this pull request Aug 27, 2020
* 0c97a1c Merge pull request #3022 from rsuderman/google-to-main
* bf264f4 Merge branch 'main' into google-to-main
* 8524cb9 Split LLVM targets into subfolders to support CMake filtering. (#2960)
* 6e78211 Fixed Emulator Timeline Semaphore parameter name (#3019)
* aa8d1c0 Enable simple.mlir test for iree-benchmark-module on vulkan (#3016)
* 6db4e7b [vulkan] Release timepoint fences more aggressively when possible (#2800)
* a1365d3 [vulkan] Do not request timeline semaphore if not available (#2904)
* a38c890 Add more type support to model builder matmul benchmark. (#2977)
* a293ca7 Fix hyperlink to getting started docs on python page. (#3015)
* b022e70 Release inputs before closing the session. (#3004)
* f1678df Dynamicly register benchmark for entry_function with name BM_{entry_function} ..
* 6282700 Expand the tf_module_to_compiler_module API (#3009)
* f7e561a Merge pull request #3006 from rsuderman/google-to-main
* 8341d71 Explicitly insert dialects in conversion passes (#3002)
* b7c2b60 Fix format by changing to LLVM style (#3008)
* 4286f17 Merge branch 'main' into google-to-main
* f0a07f6 Allow iree.placeholder as an op between splittable ops. (#2999)
* 6bd3b1d Use hidden visibility for all symbols by default (#2997)
* d650082 VMLA Dynamic Iota support with Shape dialect work. (#2965)
* c724ee4 Add function to hide SavedModel roundtrip (#2995)
* 2fedce6 Merge pull request #2996
* c5f7030 Merge branch 'main' into google-to-main
* cf3211d [vulkan] Reset TimePointFence status when releasing back to pool (#2905)
* ebc6a83 Add lint action to check for tabs (#2984)
* 932339c Merge pull request #2964 from silvasean/add-dynamic-dot-example
* df727ae Integrate MLIR-EmitC at iml130/mlir-emitc@560cd8c (#2990)
* e824d36 Refactor for explicit dialect registration (#2978)
* 38b7d2c Allow ModelRunner to receive an array of extra symbols available during JITing..
* 264a97d Fuse linalg.tensor_reshape operations with hal.interface* operations. (#2973)
* 0e3c737 Fold flow.tensor.update when all operands are constant (#2982)
* c7a21c2 Merge pull request #2983 from rsuderman/google-to-main
* fd55a86 Add a dynamically shaped mhlo.dot lowering example

COPYBARA_INTEGRATE_REVIEW=#3025 from rsuderman:main-to-google 0c97a1c
PiperOrigin-RevId: 328804964
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.

4 participants