[Mlir-commits] [mlir] [MLIR][OpenMP] Add OMP Declare Mapper MLIR Op definition (PR #117045)
Akash Banerjee
llvmlistbot at llvm.org
Mon Dec 23 07:01:11 PST 2024
https://github.com/TIFitis updated https://github.com/llvm/llvm-project/pull/117045
>From ff980db9ee7a6bfee89e991413ab3260dd334d99 Mon Sep 17 00:00:00 2001
From: Akash Banerjee <Akash.Banerjee at amd.com>
Date: Wed, 20 Nov 2024 20:44:23 +0000
Subject: [PATCH 1/4] [MLIR][OpenMP] Add OMP Declare Mapper MLIR Op definition
This patch adds the OMP.DeclareMapperOp to MLIR.
---
mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td | 28 +++++++++++++++++++
mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp | 8 ++++++
mlir/test/Dialect/OpenMP/ops.mlir | 8 ++++++
3 files changed, 44 insertions(+)
diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
index 65aa260a80cc01..6049f4cc918969 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
@@ -1689,6 +1689,34 @@ def CancellationPointOp : OpenMP_Op<"cancellation_point", clauses = [
let hasVerifier = 1;
}
+//===----------------------------------------------------------------------===//
+// 2.19.7.3 Declare Mapper Directive
+//===----------------------------------------------------------------------===//
+def DeclareMapperOp : OpenMP_Op<"declare_mapper", traits = [
+ Symbol], clauses = [
+ OpenMP_MapClause
+ ]> {
+ let summary = "declare mapper directive";
+ let description = [{
+ The declare mapper directive declares a user-defined mapper for a given
+ type, and may define a mapper-identifier that can be used in a map clause.
+ }] # clausesDescription;
+
+ let arguments = !con((ins SymbolNameAttr:$sym_name,
+ OpenMP_PointerLikeType:$var_ptr,
+ TypeAttr:$var_type), clausesArgs);
+
+ let builders = [
+ OpBuilder<(ins CArg<"const DeclareMapperOperands &">:$clauses)>
+ ];
+
+ // Override clause-based assemblyFormat.
+ let assemblyFormat = "$sym_name `:` $var_ptr `:` type($var_ptr) `:` $var_type" # " oilist(" #
+ clausesOptAssemblyFormat # ") attr-dict";
+
+ let hasVerifier = 1;
+}
+
//===----------------------------------------------------------------------===//
// 2.19.5.7 declare reduction Directive
//===----------------------------------------------------------------------===//
diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
index 3d62b3218869ea..20251dbc911fd6 100644
--- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
+++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
@@ -2204,6 +2204,14 @@ LogicalResult DistributeOp::verifyRegions() {
return success();
}
+//===----------------------------------------------------------------------===//
+// DeclareMapperOp
+//===----------------------------------------------------------------------===//
+
+LogicalResult DeclareMapperOp::verify() {
+ return verifyMapClause(*this, getMapVars());
+}
+
//===----------------------------------------------------------------------===//
// DeclareReductionOp
//===----------------------------------------------------------------------===//
diff --git a/mlir/test/Dialect/OpenMP/ops.mlir b/mlir/test/Dialect/OpenMP/ops.mlir
index 26943068ed95a4..e3eb6a611d34ff 100644
--- a/mlir/test/Dialect/OpenMP/ops.mlir
+++ b/mlir/test/Dialect/OpenMP/ops.mlir
@@ -879,6 +879,14 @@ cleanup {
omp.yield
}
+// CHECK: %[[DECL_VAR:.*]] = llvm.alloca %{{.*}}
+// CHECK: %[[DECL_MAP_INFO:.*]] = omp.map.info var_ptr(%[[DECL_VAR]] : !llvm.ptr, !llvm.struct<"my_type", (i32)>) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = ""}
+// CHECK: omp.declare_mapper @my_mapper : %[[DECL_VAR]] : !llvm.ptr : !llvm.struct<"my_type", (i32)> map_entries(%[[DECL_MAP_INFO]] : !llvm.ptr)
+%decl_c1 = arith.constant 1 : i64
+%decl_var = llvm.alloca %decl_c1 x !llvm.struct<"my_type", (i32)> : (i64) -> !llvm.ptr
+%decl_map_info = omp.map.info var_ptr(%decl_var : !llvm.ptr, !llvm.struct<"my_type", (i32)>) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = ""}
+omp.declare_mapper @my_mapper : %decl_var : !llvm.ptr : !llvm.struct<"my_type", (i32)> map_entries(%decl_map_info : !llvm.ptr)
+
// CHECK-LABEL: func @wsloop_reduction
func.func @wsloop_reduction(%lb : index, %ub : index, %step : index) {
%c1 = arith.constant 1 : i32
>From 7a8eb379e7f315631f0fa451dbf49c9c1ccca25d Mon Sep 17 00:00:00 2001
From: Akash Banerjee <Akash.Banerjee at amd.com>
Date: Fri, 22 Nov 2024 12:06:29 +0000
Subject: [PATCH 2/4] Updated description.
---
mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
index 6049f4cc918969..dd716e235b3eb5 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
@@ -1699,7 +1699,7 @@ def DeclareMapperOp : OpenMP_Op<"declare_mapper", traits = [
let summary = "declare mapper directive";
let description = [{
The declare mapper directive declares a user-defined mapper for a given
- type, and may define a mapper-identifier that can be used in a map clause.
+ type, and defines a mapper-identifier that can be used in a map clause.
}] # clausesDescription;
let arguments = !con((ins SymbolNameAttr:$sym_name,
>From d96aaa0864c0bdbb282be2ae7890092d06cc5efc Mon Sep 17 00:00:00 2001
From: Akash Banerjee <Akash.Banerjee at amd.com>
Date: Wed, 27 Nov 2024 19:05:26 +0000
Subject: [PATCH 3/4] Add region to DeclMapperOp. Move map clause to new
DeclMapperInfoOp.
---
mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td | 32 +++++++++++--------
mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp | 4 +--
mlir/test/Dialect/OpenMP/ops.mlir | 16 ++++++----
3 files changed, 29 insertions(+), 23 deletions(-)
diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
index dd716e235b3eb5..109e4e35d1854e 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
@@ -630,7 +630,7 @@ def DistributeOp : OpenMP_Op<"distribute", traits = [
will be executed in parallel by threads in the current context. These
iterations are spread across threads that already exist in the enclosing
region.
-
+
The body region can only contain a single block which must contain a single
operation. This operation must be another compatible loop wrapper or an
`omp.loop_nest`.
@@ -1692,28 +1692,32 @@ def CancellationPointOp : OpenMP_Op<"cancellation_point", clauses = [
//===----------------------------------------------------------------------===//
// 2.19.7.3 Declare Mapper Directive
//===----------------------------------------------------------------------===//
-def DeclareMapperOp : OpenMP_Op<"declare_mapper", traits = [
- Symbol], clauses = [
- OpenMP_MapClause
- ]> {
+def DeclareMapperOp : OpenMP_Op<"declare_mapper", singleRegion = 1> {
let summary = "declare mapper directive";
let description = [{
The declare mapper directive declares a user-defined mapper for a given
type, and defines a mapper-identifier that can be used in a map clause.
}] # clausesDescription;
- let arguments = !con((ins SymbolNameAttr:$sym_name,
- OpenMP_PointerLikeType:$var_ptr,
- TypeAttr:$var_type), clausesArgs);
+ let arguments = (ins SymbolNameAttr:$sym_name,
+ TypeAttr:$var_type);
+
+ let assemblyFormat = "$sym_name `:` $var_type $region attr-dict";
+}
+
+def DeclareMapperInfoOp : OpenMP_Op<"declare_mapper_info", clauses = [
+ OpenMP_MapClause
+ ]> {
+ let summary = "declare mapper info";
+ let description = [{
+ This Op is used to capture the map information related to it's
+ parent DeclareMapperOp.]>
+ }] # clausesDescription;
let builders = [
- OpBuilder<(ins CArg<"const DeclareMapperOperands &">:$clauses)>
+ OpBuilder<(ins CArg<"const DeclareMapperInfoOperands &">:$clauses)>
];
- // Override clause-based assemblyFormat.
- let assemblyFormat = "$sym_name `:` $var_ptr `:` type($var_ptr) `:` $var_type" # " oilist(" #
- clausesOptAssemblyFormat # ") attr-dict";
-
let hasVerifier = 1;
}
@@ -1829,7 +1833,7 @@ def MaskedOp : OpenMP_Op<"masked", clauses = [
], singleRegion = 1> {
let summary = "masked construct";
let description = [{
- Masked construct allows to specify a structured block to be executed by a subset of
+ Masked construct allows to specify a structured block to be executed by a subset of
threads of the current team.
}] # clausesDescription;
diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
index 20251dbc911fd6..b15d6ed15244ed 100644
--- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
+++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
@@ -2205,10 +2205,10 @@ LogicalResult DistributeOp::verifyRegions() {
}
//===----------------------------------------------------------------------===//
-// DeclareMapperOp
+// DeclareMapperInfoOp
//===----------------------------------------------------------------------===//
-LogicalResult DeclareMapperOp::verify() {
+LogicalResult DeclareMapperInfoOp::verify() {
return verifyMapClause(*this, getMapVars());
}
diff --git a/mlir/test/Dialect/OpenMP/ops.mlir b/mlir/test/Dialect/OpenMP/ops.mlir
index e3eb6a611d34ff..1822a88ede2766 100644
--- a/mlir/test/Dialect/OpenMP/ops.mlir
+++ b/mlir/test/Dialect/OpenMP/ops.mlir
@@ -879,13 +879,15 @@ cleanup {
omp.yield
}
-// CHECK: %[[DECL_VAR:.*]] = llvm.alloca %{{.*}}
-// CHECK: %[[DECL_MAP_INFO:.*]] = omp.map.info var_ptr(%[[DECL_VAR]] : !llvm.ptr, !llvm.struct<"my_type", (i32)>) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = ""}
-// CHECK: omp.declare_mapper @my_mapper : %[[DECL_VAR]] : !llvm.ptr : !llvm.struct<"my_type", (i32)> map_entries(%[[DECL_MAP_INFO]] : !llvm.ptr)
-%decl_c1 = arith.constant 1 : i64
-%decl_var = llvm.alloca %decl_c1 x !llvm.struct<"my_type", (i32)> : (i64) -> !llvm.ptr
-%decl_map_info = omp.map.info var_ptr(%decl_var : !llvm.ptr, !llvm.struct<"my_type", (i32)>) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = ""}
-omp.declare_mapper @my_mapper : %decl_var : !llvm.ptr : !llvm.struct<"my_type", (i32)> map_entries(%decl_map_info : !llvm.ptr)
+// CHECK: omp.declare_mapper @my_mapper : !llvm.struct<"my_type", (i32)>
+omp.declare_mapper @my_mapper : !llvm.struct<"my_type", (i32)> {
+^bb0(%arg: !llvm.ptr):
+ // CHECK: %[[DECL_MAP_INFO:.*]] = omp.map.info var_ptr(%{{.*}} : !llvm.ptr, !llvm.struct<"my_type", (i32)>) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = ""}
+ %decl_map_info = omp.map.info var_ptr(%arg : !llvm.ptr, !llvm.struct<"my_type", (i32)>) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = ""}
+ // CHECK: omp.declare_mapper_info map_entries(%[[DECL_MAP_INFO]] : !llvm.ptr)
+ omp.declare_mapper_info map_entries(%decl_map_info : !llvm.ptr)
+ omp.terminator
+}
// CHECK-LABEL: func @wsloop_reduction
func.func @wsloop_reduction(%lb : index, %ub : index, %step : index) {
>From 4b5c92e1080731142e68786c4a2b64fea97845f2 Mon Sep 17 00:00:00 2001
From: Akash Banerjee <Akash.Banerjee at amd.com>
Date: Mon, 23 Dec 2024 14:59:02 +0000
Subject: [PATCH 4/4] Add the necesary OpTraits to hoist the DeclareMapperOp to
the ModuleOp's region.
---
mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td | 19 +++++++++++++++----
mlir/test/Dialect/OpenMP/ops.mlir | 1 -
2 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
index 109e4e35d1854e..881f28d42e6312 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
@@ -1692,7 +1692,14 @@ def CancellationPointOp : OpenMP_Op<"cancellation_point", clauses = [
//===----------------------------------------------------------------------===//
// 2.19.7.3 Declare Mapper Directive
//===----------------------------------------------------------------------===//
-def DeclareMapperOp : OpenMP_Op<"declare_mapper", singleRegion = 1> {
+def DeclareMapperOp : OpenMP_Op<"declare_mapper", [
+ AffineScope,
+ AutomaticAllocationScope,
+ IsolatedFromAbove,
+ OutlineableOpenMPOpInterface,
+ RecipeInterface,
+ Symbol
+ ]> {
let summary = "declare mapper directive";
let description = [{
The declare mapper directive declares a user-defined mapper for a given
@@ -1702,12 +1709,16 @@ def DeclareMapperOp : OpenMP_Op<"declare_mapper", singleRegion = 1> {
let arguments = (ins SymbolNameAttr:$sym_name,
TypeAttr:$var_type);
- let assemblyFormat = "$sym_name `:` $var_type $region attr-dict";
+ let regions = (region AnyRegion:$body);
+
+ let assemblyFormat = "$sym_name `:` $var_type $body attr-dict";
}
-def DeclareMapperInfoOp : OpenMP_Op<"declare_mapper_info", clauses = [
+def DeclareMapperInfoOp : OpenMP_Op<"declare_mapper_info", [
+ Terminator
+ ], clauses = [
OpenMP_MapClause
- ]> {
+ ]> {
let summary = "declare mapper info";
let description = [{
This Op is used to capture the map information related to it's
diff --git a/mlir/test/Dialect/OpenMP/ops.mlir b/mlir/test/Dialect/OpenMP/ops.mlir
index 1822a88ede2766..a167c8bd1abbf9 100644
--- a/mlir/test/Dialect/OpenMP/ops.mlir
+++ b/mlir/test/Dialect/OpenMP/ops.mlir
@@ -886,7 +886,6 @@ omp.declare_mapper @my_mapper : !llvm.struct<"my_type", (i32)> {
%decl_map_info = omp.map.info var_ptr(%arg : !llvm.ptr, !llvm.struct<"my_type", (i32)>) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = ""}
// CHECK: omp.declare_mapper_info map_entries(%[[DECL_MAP_INFO]] : !llvm.ptr)
omp.declare_mapper_info map_entries(%decl_map_info : !llvm.ptr)
- omp.terminator
}
// CHECK-LABEL: func @wsloop_reduction
More information about the Mlir-commits
mailing list