Repository navigation
[mlir][gpu] Add vector::CombiningKind conversion helper - #107134
Closed
andfau-amd wants to merge 1 commit into
Closed
andfau-amd wants to merge 1 commit into
andfau-amd wants to merge 1 commit into
Conversation
This mirrors the existing conversion in the other direction.
Member
|
@llvm/pr-subscribers-mlir-gpu Author: Andrea Faulds (andfau-amd) ChangesThis mirrors the existing conversion in the other direction. 2 Files Affected:
diff --git a/mlir/include/mlir/Dialect/GPU/Transforms/Utils.h b/mlir/include/mlir/Dialect/GPU/Transforms/Utils.h
index 073493971e6b7c..349b2cff20ce8e 100644
--- a/mlir/include/mlir/Dialect/GPU/Transforms/Utils.h
+++ b/mlir/include/mlir/Dialect/GPU/Transforms/Utils.h
@@ -29,6 +29,8 @@ class LaunchOp;
/// Returns the matching vector combining kind.
vector::CombiningKind convertReductionKind(gpu::AllReduceOperation mode);
+/// Returns the matching reduce operation.
+gpu::AllReduceOperation convertReductionKind(vector::CombiningKind mode);
} // namespace gpu
/// Get a gpu.func created from outlining the region of a gpu.launch op with the
diff --git a/mlir/lib/Dialect/GPU/Transforms/Utils.cpp b/mlir/lib/Dialect/GPU/Transforms/Utils.cpp
index e91aa18128c7b9..7ebb0c23d3e64f 100644
--- a/mlir/lib/Dialect/GPU/Transforms/Utils.cpp
+++ b/mlir/lib/Dialect/GPU/Transforms/Utils.cpp
@@ -41,4 +41,30 @@ vector::CombiningKind convertReductionKind(gpu::AllReduceOperation mode) {
llvm_unreachable("Vector and GPU reduction kinds should match 1:1");
}
+gpu::AllReduceOperation convertReductionKind(vector::CombiningKind op) {
+ switch (unsigned(op)) {
+#define MAP_CASE(X) \
+ case unsigned(vector::CombiningKind::X): \
+ return gpu::AllReduceOperation::X
+
+ MAP_CASE(ADD);
+ MAP_CASE(MUL);
+ MAP_CASE(MINUI);
+ MAP_CASE(MINSI);
+ MAP_CASE(MINNUMF);
+ MAP_CASE(MAXSI);
+ MAP_CASE(MAXUI);
+ MAP_CASE(MAXNUMF);
+ MAP_CASE(AND);
+ MAP_CASE(OR);
+ MAP_CASE(XOR);
+ MAP_CASE(MINIMUMF);
+ MAP_CASE(MAXIMUMF);
+
+#undef MAP_CASE
+ }
+
+ llvm_unreachable("Vector and GPU reduction kinds should match 1:1");
+}
+
} // namespace mlir::gpu
|
Member
|
@llvm/pr-subscribers-mlir Author: Andrea Faulds (andfau-amd) ChangesThis mirrors the existing conversion in the other direction. 2 Files Affected:
diff --git a/mlir/include/mlir/Dialect/GPU/Transforms/Utils.h b/mlir/include/mlir/Dialect/GPU/Transforms/Utils.h
index 073493971e6b7c..349b2cff20ce8e 100644
--- a/mlir/include/mlir/Dialect/GPU/Transforms/Utils.h
+++ b/mlir/include/mlir/Dialect/GPU/Transforms/Utils.h
@@ -29,6 +29,8 @@ class LaunchOp;
/// Returns the matching vector combining kind.
vector::CombiningKind convertReductionKind(gpu::AllReduceOperation mode);
+/// Returns the matching reduce operation.
+gpu::AllReduceOperation convertReductionKind(vector::CombiningKind mode);
} // namespace gpu
/// Get a gpu.func created from outlining the region of a gpu.launch op with the
diff --git a/mlir/lib/Dialect/GPU/Transforms/Utils.cpp b/mlir/lib/Dialect/GPU/Transforms/Utils.cpp
index e91aa18128c7b9..7ebb0c23d3e64f 100644
--- a/mlir/lib/Dialect/GPU/Transforms/Utils.cpp
+++ b/mlir/lib/Dialect/GPU/Transforms/Utils.cpp
@@ -41,4 +41,30 @@ vector::CombiningKind convertReductionKind(gpu::AllReduceOperation mode) {
llvm_unreachable("Vector and GPU reduction kinds should match 1:1");
}
+gpu::AllReduceOperation convertReductionKind(vector::CombiningKind op) {
+ switch (unsigned(op)) {
+#define MAP_CASE(X) \
+ case unsigned(vector::CombiningKind::X): \
+ return gpu::AllReduceOperation::X
+
+ MAP_CASE(ADD);
+ MAP_CASE(MUL);
+ MAP_CASE(MINUI);
+ MAP_CASE(MINSI);
+ MAP_CASE(MINNUMF);
+ MAP_CASE(MAXSI);
+ MAP_CASE(MAXUI);
+ MAP_CASE(MAXNUMF);
+ MAP_CASE(AND);
+ MAP_CASE(OR);
+ MAP_CASE(XOR);
+ MAP_CASE(MINIMUMF);
+ MAP_CASE(MAXIMUMF);
+
+#undef MAP_CASE
+ }
+
+ llvm_unreachable("Vector and GPU reduction kinds should match 1:1");
+}
+
} // namespace mlir::gpu
|
Contributor
Author
|
I don't know if it has an immediate application in this repo, but it will be used for iree-org/iree#18142. In order to replace manual building of |
Contributor
Author
|
Abandoning in favor of downstream implementation (iree-org/iree#18443). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This mirrors the existing conversion in the other direction.