llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.61k stars 11.82k forks source link

[mlir][Vector] Improve support for 0-d vectors in vector dialect lowerings #112913

Open Groverkss opened 3 days ago

Groverkss commented 3 days ago

A number of patterns in vector dialect lowerings predate 0-d vector support and side step from 0-d vectors by converting them to scalars and then broadcasting them. An example patch fixing this: https://github.com/llvm/llvm-project/pull/112907

Some example issues:

I have tested removing these, and the llvm ir generated from llvm.store with 0-d vectors is correct. (Good first issue)

llvmbot commented 3 days ago

Hi!

This issue may be a good introductory issue for people new to working on LLVM. If you would like to work on this issue, your first steps are:

  1. Check that no other contributor has already been assigned to this issue. If you believe that no one is actually working on it despite an assignment, ping the person. After one week without a response, the assignee may be changed.
  2. In the comments of this issue, request for it to be assigned to you, or just create a pull request after following the steps below. Mention this issue in the description of the pull request.
  3. Fix the issue locally.
  4. Run the test suite locally. Remember that the subdirectories under test/ create fine-grained testing targets, so you can e.g. use make check-clang-ast to only run Clang's AST tests.
  5. Create a Git commit.
  6. Run git clang-format HEAD~1 to format your changes.
  7. Open a pull request to the upstream repository on GitHub. Detailed instructions can be found in GitHub's documentation. Mention this issue in the description of the pull request.

If you have any further questions about this issue, don't hesitate to ask via a comment in the thread below.

llvmbot commented 3 days ago

@llvm/issue-subscribers-good-first-issue

Author: Kunwar Grover (Groverkss)

A number of patterns in vector dialect lowerings predate 0-d vector support and side step from 0-d vectors by converting them to scalars and then broadcasting them. An example patch fixing this: https://github.com/llvm/llvm-project/pull/112907 Some example issues: - https://github.com/llvm/llvm-project/blob/main/mlir/lib/Dialect/Vector/Transforms/LowerVectorTransfer.cpp has patterns that convert vector.load/vector.store on 0-d vectors to memref.load/memref.store on scalars: https://github.com/llvm/llvm-project/blob/0a3347dc638594bef802d8148a77052c198ec27b/mlir/lib/Dialect/Vector/Transforms/LowerVectorTransfer.cpp#L524 . I have tested removing these, and the llvm ir generated from llvm.store with 0-d vectors is correct. - vector.multi_reduction (https://mlir.llvm.org/docs/Dialects/Vector/#vectormulti_reduction-vectormultidimreductionop) requires the result to be a scalar when all dimensions are reduced. This causes additional corner case handling for scalars in vector.multi_reduction patterns. A better solution would be to allow 0-d vectors as result of vector.multi_reduction.
harrisonGPU commented 2 days ago

Hi @Groverkss, do you mean a draft like this? https://github.com/llvm/llvm-project/pull/112937, to merge AnyVector and AnyVectorOfAnyRank type constraints?