Skip to content

Add TMTensorToLinalgExtPass - #8575

Merged
GMNGeoffrey merged 3 commits into
iree-org:mainfrom
cathyzhyi:tmtensor
Mar 29, 2022
Merged

GMNGeoffrey merged 3 commits into
iree-org:mainfrom
cathyzhyi:tmtensor

Conversation

@cathyzhyi

@cathyzhyi cathyzhyi commented Mar 18, 2022 •

Copy link
Copy Markdown
Contributor

This PR adds the conversions from tm_tensor to linalg_extops. The goal is to use tm_tensor as an interface dialect to bridge between projects. The tm_tensor dialect will be upstreamed eventually. A high level description about tm_tensor dialect can be found in
torch-mlir-dialects/include/torch-mlir-dialects/Dialect/TMTensor/IR/TMTensorBase.td

The change are broken up in to 3 commits:

  1. Copy over torch-mlir-dialects from https://github.com/llvm/torch-mlir without any changes.
  2. Hook up the tmtensor dialect in third_party/torch-mlir-dialects with new BUILD.overlay file, register dialects and update the third_party/torch-mlir-dialects/README.md to include instructions on how to pull in torch-mlir-dialects from upstream.
  3. Add TMTensorToLinalgExtPass which is a 1 to 1 mapping
    from tm_tensor ops to linalg.ext ops. The syntax of the ops from the
    two dialects are identical. Add --iree-input-type=tmtensor input type.

@cathyzhyi cathyzhyi changed the title Add TMTensorToLinalgExtPass WIP: Add TMTensorToLinalgExtPass Mar 18, 2022
@cathyzhyi
cathyzhyi force-pushed the tmtensor branch 2 times, most recently from 8a68366 to 34faa63 Compare March 18, 2022 01:36
@cathyzhyi cathyzhyi changed the title WIP: Add TMTensorToLinalgExtPass Add TMTensorToLinalgExtPass Mar 18, 2022
@ScottTodd
ScottTodd removed their request for review March 18, 2022 15:37
@cathyzhyi
cathyzhyi force-pushed the tmtensor branch 9 times, most recently from 82adb38 to f114022 Compare March 18, 2022 20:48
@GMNGeoffrey

Copy link
Copy Markdown
Member

Is this ready for review or still in progress? Could you please add a description? This is a lot of code to have no description :-)

@cathyzhyi
cathyzhyi force-pushed the tmtensor branch 2 times, most recently from caf4841 to 8bcdeec Compare March 18, 2022 22:25
@cathyzhyi

Copy link
Copy Markdown
Contributor Author

Is this ready for review or still in progress? Could you please add a description? This is a lot of code to have no description :-)

Sry, I just added the description. Yea, it's ready for review though I am still fixing errors reported from the bazel build.

@MaheshRavishankar MaheshRavishankar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hi Yi, Sorry for the delay. First round of comments, mostly structural.

Comment thread iree/compiler/Pipelines/Pipelines.cpp Outdated
MHLO::buildMHLOInputConversionPassPipeline(passManager);
break;
}
passManager.addNestedPass<FuncOp>(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is OK as long as there are no more passes to be added here. If there are more TM Tensor specific stuff to be done here will probably need to add a new "input" type. Just an FYI, and something for you to consider to do right now depending on whats in store here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the note. There are no more passes AFAICT. Will add the new input type if things change.

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'm not as familiar with these, but reading the code I'd expect this to actually need a new input type for consistency. In the future we may autodetect which input type is needed based on the source IR.

Comment thread iree/tools/ireec_lib.cc Resolved
Comment thread iree/compiler/Pipelines/Pipelines.cpp Outdated
MHLO::buildMHLOInputConversionPassPipeline(passManager);
break;
}
passManager.addNestedPass<FuncOp>(

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'm not as familiar with these, but reading the code I'd expect this to actually need a new input type for consistency. In the future we may autodetect which input type is needed based on the source IR.

Comment thread iree/tools/init_dialects.h Resolved
Comment thread iree/tools/init_dialects.h Resolved
@@ -0,0 +1,328 @@
// RUN: iree-opt -split-input-file -verify-diagnostics %s

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.

You can include torch-mlir specific tests in IREE's third_party/, but we won't run them (just like we don't run any other tests for dependencies). If they are relevant to the integration of torch-mlir into IREE (input conversion, e2e correctness of programs coming from torch) then the tests need to be placed in a directory like the TOSA integration.

I'll also reiterate that third party code must be pristine copies (no modifications at all), at least in the initial check-in. Separating your PR into one that adds the third party code, one that gets it building in IREE (CMake + Bazel), and one that hooks it up to the rest of the system (input type, dialect registration, e2e tests) will make code review much easier. As this is all bundled together there are multiple review threads going on for very different stages of review.

On the license compliance side (https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)), starting with a commit that just adds code makes it easy to see the base, then any patches on top of that can be clearly labeled.

For general docs, see https://opensource.google/documentation/reference/thirdparty

@stellaraccident

Copy link
Copy Markdown
Collaborator

Vacation snipped: these kind of IR "stubs" should just be copied into a project that needs them. Per policy, these need to be in third_party if originating "outside".
In hindsight, I may have put llvm-external-projects in third_party to better scalably comply with this bit of policy, but I don't think it is worth changing for this.
Please don't nit pick this and escalate to a very heavyweight (from an integration perspective) solution like submodules for such a thing. Policy compliance and minimizing llvm integrate pain should be the only thing in play here from a decision making standpoint.

@ScottTodd

Copy link
Copy Markdown
Member

Vacation snipped: these kind of IR "stubs" should just be copied into a project that needs them. Per policy, these need to be in third_party if originating "outside". In hindsight, I may have put llvm-external-projects in third_party to better scalably comply with this bit of policy, but I don't think it is worth changing for this. Please don't nit pick this and escalate to a very heavyweight (from an integration perspective) solution like submodules for such a thing. Policy compliance and minimizing llvm integrate pain should be the only thing in play here from a decision making standpoint.

Fair points. I think most of my concerns go away by structuring this as one commit that adds the pristine import (with a readme explaining how to pull in updates), then any modifications to that code (including new cmake files) as separate git commits. The current state of the PR is pretty much there now, but going step by step from the start could have streamlined the review process.

@stellaraccident

stellaraccident commented Mar 28, 2022 •

Copy link
Copy Markdown
Collaborator

Fair points. I think most of my concerns go away by structuring this as one commit that adds the pristine import

Don't get me wrong: I am definitely in favor of getting the mechanics of complying with our policies right, and this is the first of this kind of dependency to be taken ("ir stubs") so is worth some discussion... It won't be the last and for these transient things, we need to be optimizing for developer throughput. The sooner in and working, the sooner the upstream shape of it takes, and the sooner we get it off our project specific books (which will play out over ~months of code movement). That's the real thing to optimize for here.

Ok, I'm out. Beach time :)

@ScottTodd ScottTodd added the integrations Relating to high-level frontend integrations label Mar 28, 2022

@ScottTodd ScottTodd left a comment

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.

Thanks for your patience with this, LGTM!

@cathyzhyi

Copy link
Copy Markdown
Contributor Author

Thanks for your patience with this, LGTM!

Thanks for all the reviews and feedbacks!!

@cathyzhyi
cathyzhyi force-pushed the tmtensor branch 2 times, most recently from 186f2e4 to 0d2380b Compare March 29, 2022 16:58

@GMNGeoffrey GMNGeoffrey left a comment

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.

Thank you for splitting this apart. That made it much much easier to review. I still would've preferred this land as three separate PRs, but this is certainly much better :-)

I've left a few minor comments that should be straightforward to address.

Because the commit history here is now meaningful and useful, let's merge this with a merge commit. Please still include your nice PR description as the message for the merge commit.

Copy over torch-mlir-dialects from https://github.com/llvm/torch-mlir
with command:
rsync -av --exclude=tools \
  --exclude=test \
  --exclude=lib/Dialect/TMTensor/Transforms \
  --exclude=include/torch-mlir-dialects/Dialect/TMTensor/Transforms \
  PATH_TO_TORCH_MLIR_REPO/externals/llvm-external-projects/torch-mlir-dialects \
  PATH_TO_IREE_REPO/third_party

Note this commit doesn't change the torch-mlir-dialects/README.md. The
following commit will update the README.md with instructions on how to
pull the code from torch-mlir upstream.
- Add torch-mlir-dialects as an external project and add the
  BUILD.overlay file for bazel build.
- Update the third_party/torch-mlir-dialects/README.md to include
  instructions on how to pull in torch-mlir-dialects from upstream.
- Register the torch-mlir tmtensor dialect and update related build and
  cmake files.
This change adds the `TMTensorToLinalgExtPass` which is a 1 to 1 mapping
from `tm_tensor` ops to `linalg.ext` ops. The syntax of the ops from the
two dialects are identical. The goal is to use `tm_tensor` as an interface
dialect to bridge between projects. The `tm_tensor` dialect will be
upstreamed eventually. A high level description about `tm_tensor` dialect
can be found in
torch-mlir-dialects/include/torch-mlir-dialects/Dialect/TMTensor/IR/TMTensorBase.td

A new input type --iree-input-type=tmtensor is added to specify the
input contains tmtensor ops.
@cathyzhyi

Copy link
Copy Markdown
Contributor Author

hmm, after rebasing to the head the iree/test/e2e/matmul/e2e_matmul_direct_f32_large_split_k_dylib-llvm-aot_dylib started to fail.

@ScottTodd

Copy link
Copy Markdown
Member

hmm, after rebasing to the head the iree/test/e2e/matmul/e2e_matmul_direct_f32_large_split_k_dylib-llvm-aot_dylib started to fail.

That's preexisting and should be fixed by #8674.

cathyzhyi added a commit to cathyzhyi/torch-mlir that referenced this pull request Mar 29, 2022
This is the llvm version used by IREE.
Also, based on reviews of iree-org/iree#8575
There are some changes to the
llvm-external-projects/torch-mlir-dialects.
@GMNGeoffrey

Copy link
Copy Markdown
Member

I can merge this past the failing test if you'd like (admin powers)

cathyzhyi added a commit to cathyzhyi/torch-mlir that referenced this pull request Mar 29, 2022
This is the llvm version used by IREE.
Also, based on reviews of iree-org/iree#8575
There are some changes to the
llvm-external-projects/torch-mlir-dialects.
@cathyzhyi

Copy link
Copy Markdown
Contributor Author

I can merge this past the failing test if you'd like (admin powers)

yes, please! Thanks a lot!

@GMNGeoffrey

Copy link
Copy Markdown
Member

Verified that it is only a single test failing in each of the workflows and it is a known failure. Merging past failing checks

@GMNGeoffrey

Copy link
Copy Markdown
Member

Also, merging with a merge commit, per my above comment that the commit history here is interesting and useful

@GMNGeoffrey
GMNGeoffrey merged commit 13900bf into iree-org:main Mar 29, 2022
cathyzhyi added a commit to cathyzhyi/torch-mlir that referenced this pull request Mar 29, 2022
This is the llvm version used by IREE.
Also, based on reviews of iree-org/iree#8575
There are some changes to the
llvm-external-projects/torch-mlir-dialects.
GMNGeoffrey added a commit that referenced this pull request Mar 31, 2022
This reverts commit 13900bf, reversing
changes made to 09a78f5.
GMNGeoffrey added a commit that referenced this pull request Apr 6, 2022
This reverts commit 13900bf, reversing
changes made to 09a78f5.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integrations Relating to high-level frontend integrations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants