[Mlir-commits] [mlir] [mlir][gpu] Add vector::CombiningKind conversion helper (PR #107134)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Sep 3 10:46:29 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-gpu
Author: Andrea Faulds (andfau-amd)
<details>
<summary>Changes</summary>
This mirrors the existing conversion in the other direction.
---
Full diff: https://github.com/llvm/llvm-project/pull/107134.diff
2 Files Affected:
- (modified) mlir/include/mlir/Dialect/GPU/Transforms/Utils.h (+2)
- (modified) mlir/lib/Dialect/GPU/Transforms/Utils.cpp (+26)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/107134
More information about the Mlir-commits
mailing list