[Mlir-commits] [mlir] [mlir][gpu] Add vector::CombiningKind conversion helper (PR #107134)
Andrea Faulds
llvmlistbot at llvm.org
Tue Sep 3 10:45:52 PDT 2024
https://github.com/andfau-amd created https://github.com/llvm/llvm-project/pull/107134
This mirrors the existing conversion in the other direction.
>From 3f3699852050a9fc987c00ff7d79e7413849a310 Mon Sep 17 00:00:00 2001
From: Andrea Faulds <andrea.faulds at amd.com>
Date: Tue, 3 Sep 2024 19:44:06 +0200
Subject: [PATCH] [mlir][gpu] Add vector::CombiningKind conversion helper
This mirrors the existing conversion in the other direction.
---
.../mlir/Dialect/GPU/Transforms/Utils.h | 2 ++
mlir/lib/Dialect/GPU/Transforms/Utils.cpp | 26 +++++++++++++++++++
2 files changed, 28 insertions(+)
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
More information about the Mlir-commits
mailing list