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

[mlir][Vector] Deprecate vector.extractelement/vector.insertelement #113829

Merged
merged 3 commits into from
Feb 19, 2025

Conversation

@Groverkss
Copy link
Member Author

Depends on #113827

@llvmbot
Copy link
Member

llvmbot commented Oct 27, 2024

@llvm/pr-subscribers-mlir

Author: Kunwar Grover (Groverkss)

Changes

See https://discourse.llvm.org/t/rfc-psa-remove-vector-extractelement-and-vector-insertelement-ops-in-favor-of-vector-extract-and-vector-insert-ops/71116/6 for more information.


Full diff: https://github.com/llvm/llvm-project/pull/113829.diff

1 Files Affected:

  • (modified) mlir/include/mlir/Dialect/Vector/IR/VectorOps.td (+6-2)
diff --git a/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td b/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td
index e859270cf9a5e5..46de656a67054a 100644
--- a/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td
+++ b/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td
@@ -635,11 +635,13 @@ def Vector_ExtractElementOp :
     Results<(outs AnyType:$result)> {
   let summary = "extractelement operation";
   let description = [{
+    Note: This operation is depreciated. Please use vector.extract insert.
+
     Takes a 0-D or 1-D vector and a optional dynamic index position and
     extracts the scalar at that position.
 
     Note that this instruction resembles vector.extract, but is restricted to
-    0-D and 1-D vectors and relaxed to dynamic indices.
+    0-D and 1-D vectors.
     If the vector is 0-D, the position must be std::nullopt.
 
 
@@ -819,11 +821,13 @@ def Vector_InsertElementOp :
      Results<(outs AnyVectorOfAnyRank:$result)> {
   let summary = "insertelement operation";
   let description = [{
+    Note: This operation is depreciated. Please use vector.insert instead.
+
     Takes a scalar source, a 0-D or 1-D destination vector and a dynamic index
     position and inserts the source into the destination at the proper position.
 
     Note that this instruction resembles vector.insert, but is restricted to 0-D
-    and 1-D vectors and relaxed to dynamic indices.
+    and 1-D vectors.
 
     It is meant to be closer to LLVM's version:
     https://llvm.org/docs/LangRef.html#insertelement-instruction

@llvmbot
Copy link
Member

llvmbot commented Oct 27, 2024

@llvm/pr-subscribers-mlir-vector

Author: Kunwar Grover (Groverkss)

Changes

See https://discourse.llvm.org/t/rfc-psa-remove-vector-extractelement-and-vector-insertelement-ops-in-favor-of-vector-extract-and-vector-insert-ops/71116/6 for more information.


Full diff: https://github.com/llvm/llvm-project/pull/113829.diff

1 Files Affected:

  • (modified) mlir/include/mlir/Dialect/Vector/IR/VectorOps.td (+6-2)
diff --git a/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td b/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td
index e859270cf9a5e5..46de656a67054a 100644
--- a/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td
+++ b/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td
@@ -635,11 +635,13 @@ def Vector_ExtractElementOp :
     Results<(outs AnyType:$result)> {
   let summary = "extractelement operation";
   let description = [{
+    Note: This operation is depreciated. Please use vector.extract insert.
+
     Takes a 0-D or 1-D vector and a optional dynamic index position and
     extracts the scalar at that position.
 
     Note that this instruction resembles vector.extract, but is restricted to
-    0-D and 1-D vectors and relaxed to dynamic indices.
+    0-D and 1-D vectors.
     If the vector is 0-D, the position must be std::nullopt.
 
 
@@ -819,11 +821,13 @@ def Vector_InsertElementOp :
      Results<(outs AnyVectorOfAnyRank:$result)> {
   let summary = "insertelement operation";
   let description = [{
+    Note: This operation is depreciated. Please use vector.insert instead.
+
     Takes a scalar source, a 0-D or 1-D destination vector and a dynamic index
     position and inserts the source into the destination at the proper position.
 
     Note that this instruction resembles vector.insert, but is restricted to 0-D
-    and 1-D vectors and relaxed to dynamic indices.
+    and 1-D vectors.
 
     It is meant to be closer to LLVM's version:
     https://llvm.org/docs/LangRef.html#insertelement-instruction

@Groverkss Groverkss requested review from banach-space, dcaballe, kuhar, hanhanW and nicolasvasilache and removed request for kuhar October 27, 2024 18:27
Copy link
Member

@kuhar kuhar left a comment

Choose a reason for hiding this comment

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

We should also list this on https://mlir.llvm.org/deprecation/

@kuhar kuhar changed the title [mlir][Vector] Depreciate vector.extractelement/vector.insertelement [mlir][Vector] Deprecate vector.extractelement/vector.insertelement Oct 27, 2024
Copy link
Member

@kuhar kuhar left a comment

Choose a reason for hiding this comment

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

Before we deprecate this, we should also handle the dynamic case in vector-to-spirv. We support it for insertelement/extractelement but not insert/extract:

  • int32_t id = getFirstIntValue(insertOp.getMixedPosition());
    rewriter.replaceOpWithNewOp<spirv::CompositeInsertOp>(
    insertOp, adaptor.getSource(), adaptor.getDest(), id);
  • APInt cstPos;
    if (matchPattern(adaptor.getPosition(), m_ConstantInt(&cstPos)))
    rewriter.replaceOpWithNewOp<spirv::CompositeInsertOp>(
    insertOp, adaptor.getSource(), adaptor.getDest(),
    cstPos.getSExtValue());
    else
    rewriter.replaceOpWithNewOp<spirv::VectorInsertDynamicOp>(
    insertOp, vectorType, insertOp.getDest(), adaptor.getSource(),
    adaptor.getPosition());
    return success();

@dcaballe
Copy link
Contributor

LGTM. Final approval should come from @kuhar after addressing his concerns. Thanks!

@Groverkss
Copy link
Member Author

Before we deprecate this, we should also handle the dynamic case in vector-to-spirv. We support it for insertelement/extractelement but not insert/extract:

  • int32_t id = getFirstIntValue(insertOp.getMixedPosition());
    rewriter.replaceOpWithNewOp<spirv::CompositeInsertOp>(
    insertOp, adaptor.getSource(), adaptor.getDest(), id);
  • APInt cstPos;
    if (matchPattern(adaptor.getPosition(), m_ConstantInt(&cstPos)))
    rewriter.replaceOpWithNewOp<spirv::CompositeInsertOp>(
    insertOp, adaptor.getSource(), adaptor.getDest(),
    cstPos.getSExtValue());
    else
    rewriter.replaceOpWithNewOp<spirv::VectorInsertDynamicOp>(
    insertOp, vectorType, insertOp.getDest(), adaptor.getSource(),
    adaptor.getPosition());
    return success();

#114137

@banach-space
Copy link
Contributor

Hey @Groverkss , how's progress with this? Is this blocked?

@Groverkss
Copy link
Member Author

Hey @Groverkss , how's progress with this? Is this blocked?

Hi! It's not blocked, I just got held up by some other work. I plan to finish sending the final patch to remove all uses of vector.extractelement/vector.insertelement this week.

@banach-space
Copy link
Contributor

banach-space commented Dec 10, 2024

Hey @Groverkss , how's progress with this? Is this blocked?

Hi! It's not blocked, I just got held up by some other work. I plan to finish sending the final patch to remove all uses of vector.extractelement/vector.insertelement this week.

Sure, no rush. I've just realised that @kuhar has one outstanding request - I guess that's what we're waiting for? I'd be tempted to land this as is, but will defer to Jakub - I'm happy either way :)

I really appreciate your work in this area 🙏🏻

@kuhar
Copy link
Member

kuhar commented Dec 10, 2024

The typos from this review are not fixed yet: #113829 (review)

@Groverkss Groverkss force-pushed the depreciate-vector-extractelemenmt branch from e19d7f3 to 12efb83 Compare February 19, 2025 19:52
@Groverkss Groverkss requested a review from kuhar February 19, 2025 19:52
@Groverkss Groverkss merged commit 1a6ed4d into llvm:main Feb 19, 2025
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants