Repository navigation
Build an e2e path for linalg on tensors. - #4368
Conversation
benvanik
left a comment
There was a problem hiding this comment.
Awesome!
meta: please add your name or issue numbers (even if just roll-up tracking issues) to TODOs (// TODO(nicolasvasilache): foo or // TODO(#githubissuenumber): foo).
|
|
||
| // Construct view memref from base memref in std land and cast to LLVM | ||
| SmallVector<Value, 4> dynamicSizes; // TODO: extract from push constant. | ||
| #if 0 |
There was a problem hiding this comment.
please add a TODO(nicolasvasilache) or TODO(#githubissuenumber) to things like this so it's clear that it's temporary until you do some more work vs. dead code/leftover debugging
There was a problem hiding this comment.
If you want to test this, there are e2e tests checked into to tests here that is an example for this. I would rather just assert/error out for the dynamic case.
There was a problem hiding this comment.
added assertion and dropped the #if 0
67c1281 to
db73ec7
Compare
|
@pifon2a FYI |
9d60aca to
3bcdc8e
Compare
|
@benvanik thanks for your review, updated and sent back for round 2. |
df7b4b8 to
c957e1d
Compare
|
Remaining test errors need an llvm bump past @GMNGeoffrey @MaheshRavishankar trying to do that in #4385 but I may be a bit naive since this is my first attempt at LLVM bump in IREE. |
|
|
||
| // Construct view memref from base memref in std land and cast to LLVM | ||
| SmallVector<Value, 4> dynamicSizes; // TODO: extract from push constant. | ||
| #if 0 |
There was a problem hiding this comment.
If you want to test this, there are e2e tests checked into to tests here that is an example for this. I would rather just assert/error out for the dynamic case.
| // workgroup_size[3]: !llvm.ptr<i32>) | ||
| TypeConverter::SignatureConversion signatureConverter(/*numOrigInputs=*/0); | ||
| MLIRContext *context = rewriter.getContext(); | ||
| auto packedBuffersArgsTy = LLVM::LLVMPointerType::get( |
There was a problem hiding this comment.
I am not totally in-tune with LLVM dialect and I am guessing this copy-pasted code, but you must be able to maintain the information that the argument is a pointer to a int[3]
There was a problem hiding this comment.
Yes this was copied from the existing impl.
I am not 100% sure whether it would be transparent re the ABI or whether something weird would happen.
I'll investigate tomorrow.
There was a problem hiding this comment.
Updated to !llvm.ptr<!llvm.array<3xi32>>, I am unclear whether this will end up being better or worse but it passes the test.
|
|
||
| // Traverse all transitive "TieShapeOp" uses of `tensor`, map them to `memref`. | ||
| // Replace all uses of any such transitive tensor in a "DimOp" by `memref`. | ||
| // TODO(nicolasvasilache): kill "TieShapeOp" with fire. |
There was a problem hiding this comment.
:D This is part of Shape Dialect. We have no other way of capturing dynamic shapes....
There was a problem hiding this comment.
We will once we can do tensor<shape-only> or extend the MLIR core shape dialect with a type that has the proper semantics, as discussed in https://llvm.discourse.group/t/linalg-and-shapes/2421/ :)
But this is left for a later cleanup.
| // RUN: iree-run-mlir -export-all -iree-hal-target-backends=vmla %s -function-input="1x128x128x1xf32" | IreeFileCheck %s | ||
| // RUN: [[ $IREE_LLVMAOT_DISABLE == 1 ]] || (iree-run-mlir -export-all -iree-hal-target-backends=dylib-llvm-aot %s -function-input="1x128x128x1xf32" | IreeFileCheck %s) | ||
| // RUN: [[ $IREE_VULKAN_DISABLE == 1 ]] || (iree-run-mlir -export-all -iree-hal-target-backends=vulkan-spirv %s -function-input="1x128x128x1xf32" | IreeFileCheck %s) | ||
| // RUN: [[ $IREE_LLVMAOT_DISABLE == 1 ]] || (iree-run-mlir -export-all -iree-hal-target-backends=dylib-llvm-aot -iree-enable-linalg-on-tensors %s -function-input="1x128x128x1xf32" | IreeFileCheck %s) |
There was a problem hiding this comment.
Why is this being removed?
There was a problem hiding this comment.
In the first implementation when I didn't duplicate stuff into flow, the path would break.
Now I think the test should pass but this is not how it should be used and the hal.interface.tensor.load.tile ops should disappear.
| dispatchOperands.reserve(root->getNumOperands()); | ||
| dispatchOperands.append(root.getInputs().begin(), root.getInputs().end()); | ||
| for (OpOperand &opOperand : root.getOutputOpOperands()) { | ||
| if (root.isInitTensor(&opOperand)) { |
There was a problem hiding this comment.
Not really sure why the operand value is used if this is an initTensor (you only need the shape then), but only the shape is needed if it is not. Is the condition reversed here or am I missing something?
There was a problem hiding this comment.
The core refactoring made isInitTensor a property that we check on output tensors.
If the output tensor has all the right properties and the corresponding scalar is used in the linalg.generic region, then isInitTensor returns true.
| } | ||
|
|
||
| // Rewrite pattern to ensure only ops with tensor semantics are tiled. | ||
| struct TileAndDistributeOnTensorsPattern |
There was a problem hiding this comment.
I am fine with landing this, but this will need to be seriously adapted if we used fusion. We will have to pull in multiple ops before tile + fuse and then tile + fuse.
My initial assumption here was we would just tile + distribute first, then create the dispatch region using the outer most loop.... This still be a phase ordering issue. Here we would need to
- Know why ops can be tile+fused
- Pull them within dispatch region
- Tile+fuse
Instead it would be better to
- Tile + fuse
- Pull each outer loop body into dispatch region.
There was a problem hiding this comment.
Let's start with this and iterate on a concrete use case if you don't mind.
I went with this implementation because it is significantly more elegant and easier to implement.
We can make it more complex to support relaxing the usage but I didn't want to commit to generality and complexity before I needed to.
I am not sure we have to sequence things like 1 + 2 + 3 though, there may be simpler ways like:
- move op to dispatch region
- tile op inside the dispatch region
- iteratively pull producers by moving them into dispatch region and then fusing.
TBD together in the future.
| } | ||
| // Need to insert new operands into operands and BB args at proper | ||
| // positions. | ||
| assert(newOperands.empty() && "unsupported new operands from capture"); |
There was a problem hiding this comment.
Not really sure how we can be sure everything needed has been pulled into dispatch region. This probably works only for the single op case handled here, but I am not sure this will work when we have multiple ops.
There was a problem hiding this comment.
That's why the assertion is here, this pass does not claim to support all use cases.
The whole PR is more general than making this pass work for all cases: learn to walk before we can run and all.
| originalDispatchOperands.begin(), originalDispatchOperands.end()); | ||
| SmallVector<Value, 4> newOperands, clones; | ||
| for (Value v : valuesDefinedAbove) { | ||
| if (v.getDefiningOp<ConstantOp>()) { |
There was a problem hiding this comment.
I dont think we do this for all constants. Only for splat constants.
There was a problem hiding this comment.
Good point, added a level of indirection and only supporting ConstantIndex/Int/Float for now.
We can extend on a per-need basis.
benvanik
left a comment
There was a problem hiding this comment.
Thanks for the tweaks!
LGTM but I'd want @MaheshRavishankar to say so too :)
|
Happy to land an iterate. LGTM. |
The LLVM bump happens with google -> main integrate. @KoolJBlack and @rsuderman, is there something blocking the google -> main integrate? |
Our team doesn't directly manage the LLVM bump, but you can see which commit we're tracking towards on the |
c957e1d to
55ea64a
Compare
55ea64a to
0f9c6b5
Compare
|
@ScottTodd I am a bit confused here. I see the last bump to submodules on Would it be easy to update main to this latest green one ? d8bc853#diff-227655881fc8052373149ace0b1846c3ecfccb1c103cb76c616b76be1cf2b870 That would unblock this PR. |
0f9c6b5 to
ce4aed7
Compare
|
All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the ℹ️ Googlers: Go here for more info. |
|
All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the ℹ️ Googlers: Go here for more info. |
This revision reorders transformations to allow dispatch region formation to be obtained from tiling linalg on tensors. This is expressed as an additive option to Linalg tiling to demonstrate a minimal incremental change. The experiemental flow is modified to allow updated destructive pattern and bufferization. Conversion to LLVM is spawned into a new pass that will gradually encompass the existing one. This is deemed necessary as some of the existing assumptions and implementation look more complex than they should. A linalg_tensor_ops directory is added with a matmul example that runs end to end.
49f50c9 to
e1cb964
Compare
* bb0f95e Enable all packages on all every OS. * 7cf454d Add dependencies properly for python install targets. * 827eccf Third attempt: Rename packages to not collide on 'compiler' term. * a3145cb Second attempt: fix some target names and change the docker image. * 763fc1b First attempt: enable all python packages as experimental on linux. * 9364f0f Add install targets for all python packages and configure in CI. * 6fe74ac Correctly get binary name in android run_binary_test (#4403) * b1bc038 Remove special handling for runtime -> compiler dep (#4396) * 38d3c14 Disable run_binary_test on Android (#4402) * 35d4b32 Build an e2e path for linalg on tensors. (#4368) * c0e362c Merge google -> main (#4401) * 7aecc34 Merge branch 'main' into google-to-main * 7dc756b Attempt to appease linter on SUBMODULE_VERSIONS for mlir-emitc * c83f594 Use backward buffer allocation in HLOToLinalgOnBuffers (#4318) * 4889612 Avoid running slow benchmarks as part of testing (#4364) * 9b72435 Default to quoting strings in Bazel -> CMake (#4394) * 2a52c0f Fix m1 builds (#4361) * 30f67df Update cross-compilation for changed experimental flag names (#4365) * dc7d633 Merge pull request #4386 from google/benvanik-hal-pre * 3d577af Move macos out of experimental now that it builds. * 1c2a4bf Note that iree_task_list_discard leaves the list in a usable state. * dcd1b53 Adding utils for common string view and allocator operations. * d2af7f3 Adding iree_atomic_thread_fence (like (std::)atomic_thread_fence). * c691e23 Bazel -> CMake cleanup (#4362) * e002f99 Attempt to pin the python executable more robustly for macos. * eb184f9 Link Foundation and Metal frameworks on macos. * cc8c1b2 Turn -Wunused-variable back on (#4360) * 52ebf7b Use existing script in submodule synchronize action (#4358) * 0f0fffd Get remote name in a more portable way in gh scripting (#4357) * 4868a49 Add one-shot runtime MacOS sanity check workflow. * 44ca211 Actually use the platlib install command for linux wheels. * fd36682 [spirv] Replace SPIRVOpLowering with a local class (#4383) * cf10473 Fix macos matrix spec. * 197f33b Enable windows build as non experimental. * 05190e1 Make pyiree compiler package compatible with manylinux2014. * 626d45a Add missing dep on HLOToLinalg (#4377) * b0e8243 Integrate MLIR-EmitC at iml130/mlir-emitc@a438d3b (#4375) * f0514e4 NFC: Fix some pre-existing yaml lint. * bb1de96 Plumb package suffix, version, and revision info to release packages. * 995d0b7 Moved iree-check-module-main.cc to iree/tools (#4312) * 56e40ac Remove suspected merge conflict in darwin_threading.c. * 938875f Enable macos and windows builds. * 921b46d Rename cmake_configure_ci.py -> cmake_ci.py. * 57435cd Fix typo build_iree -> iree_build. * fd1d06c Fix typo in install-iree -> iree-install. * 2ab4dfc Update workflow dispatch token. * 29f1596 Re-enable tag fetching * f8f4031 Fix issues in snapshot schedule. * bd6cf1f Add scheduled workflow to trigger snapshot releases. * 442b35e Fix typo in runtime matrix check. * b4981b2 Configure pipeline to build IREE runtime wheels. * 77a63cd Make the main python packages cmake installable. * 4e1602a Add cmake_configure_ci.py. * 723ff37 Remove typo from GCC iree_atomic_load_auto macro. * 847ac69 Disable workflow on push to cidev * e666fbf Fixing the casting behavior of atomic compare exchange on windows. * 25c4cb3 Adding merge_from support for IntrusiveList unique_ptr/ref_ptr. * 334d3e2 Update getting_started_linux_cmake.md (#4367) * c9687d4 Update bazel_to_cmake to support testonly for iree_bytecode_module (#4337) * 0657be2 Fix mlir-hlo path in Submodule update scripting (#4356) * d146a3d Add scripting to update mlir-hlo to match LLVM commit (#4348) * 3010d3c Clean up naming in LLVM sync script (#4346) * af6c2d4 Merge pull request #4227 from google/benvanik-tasks-core * 01600a5 Adding an entire RTOS-scale task scheduling system. * b47e6f0 Clarifying note on iree_wait_set_erase. * a60332c Tweaking thread affinity groups to have an SMT flag. This allows us to keep th.. * c5b440d Adding tracing to thread name setters. Turns out, setting the thread name can .. * b544ef6 Allowing threads to be created running (not always suspended). Though creating.. * c3af92e Adding IREE_TRACE_ZONE_SET_COLOR macro. * ed727e2 Plumbing tracy mutex support into iree_slim_mutex_t. * 122d6b8 Adding benoit's MiniLcg pseudo-random number generator. * 142bc6a Adding and/or/xor atomic operations. * 9853806 Adding IREE_ASSERT macros. COPYBARA_INTEGRATE_REVIEW=#4413 from KoolJBlack:main-to-google 594e06c PiperOrigin-RevId: 350634605
* bb0f95e Enable all packages on all every OS. * 7cf454d Add dependencies properly for python install targets. * 827eccf Third attempt: Rename packages to not collide on 'compiler' term. * a3145cb Second attempt: fix some target names and change the docker image. * 763fc1b First attempt: enable all python packages as experimental on linux. * 9364f0f Add install targets for all python packages and configure in CI. * 6fe74ac Correctly get binary name in android run_binary_test (#4403) * b1bc038 Remove special handling for runtime -> compiler dep (#4396) * 38d3c14 Disable run_binary_test on Android (#4402) * 35d4b32 Build an e2e path for linalg on tensors. (#4368) * c0e362c Merge google -> main (#4401) * 7aecc34 Merge branch 'main' into google-to-main * 7dc756b Attempt to appease linter on SUBMODULE_VERSIONS for mlir-emitc * c83f594 Use backward buffer allocation in HLOToLinalgOnBuffers (#4318) * 4889612 Avoid running slow benchmarks as part of testing (#4364) * 9b72435 Default to quoting strings in Bazel -> CMake (#4394) * 2a52c0f Fix m1 builds (#4361) * 30f67df Update cross-compilation for changed experimental flag names (#4365) * dc7d633 Merge pull request #4386 from google/benvanik-hal-pre * 3d577af Move macos out of experimental now that it builds. * 1c2a4bf Note that iree_task_list_discard leaves the list in a usable state. * dcd1b53 Adding utils for common string view and allocator operations. * d2af7f3 Adding iree_atomic_thread_fence (like (std::)atomic_thread_fence). * c691e23 Bazel -> CMake cleanup (#4362) * e002f99 Attempt to pin the python executable more robustly for macos. * eb184f9 Link Foundation and Metal frameworks on macos. * cc8c1b2 Turn -Wunused-variable back on (#4360) * 52ebf7b Use existing script in submodule synchronize action (#4358) * 0f0fffd Get remote name in a more portable way in gh scripting (#4357) * 4868a49 Add one-shot runtime MacOS sanity check workflow. * 44ca211 Actually use the platlib install command for linux wheels. * fd36682 [spirv] Replace SPIRVOpLowering with a local class (#4383) * cf10473 Fix macos matrix spec. * 197f33b Enable windows build as non experimental. * 05190e1 Make pyiree compiler package compatible with manylinux2014. * 626d45a Add missing dep on HLOToLinalg (#4377) * b0e8243 Integrate MLIR-EmitC at iml130/mlir-emitc@a438d3b (#4375) * f0514e4 NFC: Fix some pre-existing yaml lint. * bb1de96 Plumb package suffix, version, and revision info to release packages. * 995d0b7 Moved iree-check-module-main.cc to iree/tools (#4312) * 56e40ac Remove suspected merge conflict in darwin_threading.c. * 938875f Enable macos and windows builds. * 921b46d Rename cmake_configure_ci.py -> cmake_ci.py. * 57435cd Fix typo build_iree -> iree_build. * fd1d06c Fix typo in install-iree -> iree-install. * 2ab4dfc Update workflow dispatch token. * 29f1596 Re-enable tag fetching * f8f4031 Fix issues in snapshot schedule. * bd6cf1f Add scheduled workflow to trigger snapshot releases. * 442b35e Fix typo in runtime matrix check. * b4981b2 Configure pipeline to build IREE runtime wheels. * 77a63cd Make the main python packages cmake installable. * 4e1602a Add cmake_configure_ci.py. * 723ff37 Remove typo from GCC iree_atomic_load_auto macro. * 847ac69 Disable workflow on push to cidev * e666fbf Fixing the casting behavior of atomic compare exchange on windows. * 25c4cb3 Adding merge_from support for IntrusiveList unique_ptr/ref_ptr. * 334d3e2 Update getting_started_linux_cmake.md (#4367) * c9687d4 Update bazel_to_cmake to support testonly for iree_bytecode_module (#4337) * 0657be2 Fix mlir-hlo path in Submodule update scripting (#4356) * d146a3d Add scripting to update mlir-hlo to match LLVM commit (#4348) * 3010d3c Clean up naming in LLVM sync script (#4346) * af6c2d4 Merge pull request #4227 from google/benvanik-tasks-core * 01600a5 Adding an entire RTOS-scale task scheduling system. * b47e6f0 Clarifying note on iree_wait_set_erase. * a60332c Tweaking thread affinity groups to have an SMT flag. This allows us to keep th.. * c5b440d Adding tracing to thread name setters. Turns out, setting the thread name can .. * b544ef6 Allowing threads to be created running (not always suspended). Though creating.. * c3af92e Adding IREE_TRACE_ZONE_SET_COLOR macro. * ed727e2 Plumbing tracy mutex support into iree_slim_mutex_t. * 122d6b8 Adding benoit's MiniLcg pseudo-random number generator. * 142bc6a Adding and/or/xor atomic operations. * 9853806 Adding IREE_ASSERT macros. COPYBARA_INTEGRATE_REVIEW=#4413 from KoolJBlack:main-to-google 594e06c PiperOrigin-RevId: 350634605
This revision reorders transformations to allow dispatch region formation to be
obtained from tiling linalg on tensors. This is expressed as an additive option to Linalg tiling to demonstrate a minimal incremental change.
The experiemental flow is modified to allow updated destructive pattern and bufferization.
Conversion to LLVM is spawned into a new pass that will gradually encompass the existing one. This is deemed necessary as some of the existing assumptions and implementation look more complex than they should.
A linalg_tensor_ops directory is added with a matmul example that runs end to end.