[Mlir-commits] [mlir] 6a95042 - [OpenMP][MLIR] Add OpenMP version attribute to OMP OffloadModuleInterface
Dominik Adamski
llvmlistbot at llvm.org
Fri May 19 03:40:45 PDT 2023
Author: Dominik Adamski
Date: 2023-05-19T05:34:45-05:00
New Revision: 6a950422f3bcaf91b26ce6436c6658e503c5c87b
URL: https://github.com/llvm/llvm-project/commit/6a950422f3bcaf91b26ce6436c6658e503c5c87b
DIFF: https://github.com/llvm/llvm-project/commit/6a950422f3bcaf91b26ce6436c6658e503c5c87b.diff
LOG: [OpenMP][MLIR] Add OpenMP version attribute to OMP OffloadModuleInterface
The intent of OpenMP version attribute is to be applied to a module
and then hold information on OpenMP version flag.
Information about OpenMP version can be specified in Clang
by flag -fopenmp-version and it is stored in LLVM-IR module metadata:
!llvm.module.flags = !{!0, !1}
!0 = !{i32 7, !"openmp", i32 51}
!1 = !{i32 7, !"openmp-device", i32 51}
OpenMP MLIR version attributes will allow to lower Flang frontend flag
to OpenMP MLIR code and then to LLVM IR.
There are two OpenMP MLIR version attributes. The first one "omp.version"
MLIR attribute corresponds to host OpenMP version. The second one
corresponds to "openmp-device" LLVM-IR metadata. "openmp-device" LLVM-IR
metadata is attached only for offloaded code.
Differential Revision: https://reviews.llvm.org/D150351
Reviewed By: kiranchandramohan
Added:
Modified:
flang/include/flang/Tools/CrossToolHelpers.h
mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td
mlir/test/Dialect/OpenMP/attr.mlir
Removed:
################################################################################
diff --git a/flang/include/flang/Tools/CrossToolHelpers.h b/flang/include/flang/Tools/CrossToolHelpers.h
index a28b45ca27612..983a968218972 100644
--- a/flang/include/flang/Tools/CrossToolHelpers.h
+++ b/flang/include/flang/Tools/CrossToolHelpers.h
@@ -61,7 +61,8 @@ void setOffloadModuleInterfaceAttributes(
if (Opts.OpenMPIsDevice) {
offloadMod.setFlags(Opts.OpenMPTargetDebug, Opts.OpenMPTeamSubscription,
Opts.OpenMPThreadSubscription, Opts.OpenMPNoThreadState,
- Opts.OpenMPNoNestedParallelism);
+ Opts.OpenMPNoNestedParallelism,
+ 50 /* Default OpenMP Device version */);
if (!Opts.OMPHostIRFile.empty())
offloadMod.setHostIRFilePath(Opts.OMPHostIRFile);
diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
index e5ced046eea14..02ccca8a3d7b0 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
@@ -53,6 +53,14 @@ def IsDeviceAttr : OpenMP_Attr<"IsDevice", "isdevice"> {
let assemblyFormat = "`<` struct(params) `>`";
}
+def VersionAttr : OpenMP_Attr<"Version", "version"> {
+ let parameters = (ins
+ "uint32_t":$version
+ );
+
+ let assemblyFormat = "`<` struct(params) `>`";
+}
+
//===----------------------------------------------------------------------===//
// Runtime library flag's attribute that holds information for lowering to LLVM
//===----------------------------------------------------------------------===//
@@ -63,7 +71,8 @@ def FlagsAttr : OpenMP_Attr<"Flags", "flags"> {
DefaultValuedParameter<"bool", "false">:$assume_teams_oversubscription,
DefaultValuedParameter<"bool", "false">:$assume_threads_oversubscription,
DefaultValuedParameter<"bool", "false">:$assume_no_thread_state,
- DefaultValuedParameter<"bool", "false">:$assume_no_nested_parallelism
+ DefaultValuedParameter<"bool", "false">:$assume_no_nested_parallelism,
+ DefaultValuedParameter<"uint32_t", "50">:$openmp_device_version
);
let assemblyFormat = "`<` struct(params) `>`";
diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td
index f43eead18b300..15df11b08cc09 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td
@@ -104,11 +104,12 @@ def OffloadModuleInterface : OpInterface<"OffloadModuleInterface"> {
"bool":$assumeTeamsOversubscription,
"bool":$assumeThreadsOversubscription,
"bool":$assumeNoThreadState,
- "bool":$assumeNoNestedParallelism), [{}], [{
+ "bool":$assumeNoNestedParallelism,
+ "uint32_t":$openmpDeviceVersion), [{}], [{
$_op->setAttr(("omp." + mlir::omp::FlagsAttr::getMnemonic()).str(),
mlir::omp::FlagsAttr::get($_op->getContext(), debugKind,
assumeTeamsOversubscription, assumeThreadsOversubscription,
- assumeNoThreadState, assumeNoNestedParallelism));
+ assumeNoThreadState, assumeNoNestedParallelism, openmpDeviceVersion));
}]>,
InterfaceMethod<
/*description=*/[{
diff --git a/mlir/test/Dialect/OpenMP/attr.mlir b/mlir/test/Dialect/OpenMP/attr.mlir
index af0ca8f5e9546..4c7a7d48ed1cf 100644
--- a/mlir/test/Dialect/OpenMP/attr.mlir
+++ b/mlir/test/Dialect/OpenMP/attr.mlir
@@ -1,7 +1,7 @@
// RUN: mlir-opt %s | mlir-opt | FileCheck %s
// CHECK: module attributes {omp.flags = #omp.flags<>} {
-module attributes {omp.flags = #omp.flags<debug_kind = 0, assume_teams_oversubscription = false, assume_threads_oversubscription = false, assume_no_thread_state = false, assume_no_nested_parallelism = false>} {}
+module attributes {omp.flags = #omp.flags<debug_kind = 0, assume_teams_oversubscription = false, assume_threads_oversubscription = false, assume_no_thread_state = false, assume_no_nested_parallelism = false, openmp_device_version = 50>} {}
// CHECK: module attributes {omp.flags = #omp.flags<debug_kind = 20>} {
module attributes {omp.flags = #omp.flags<debug_kind = 20, assume_teams_oversubscription = false, assume_threads_oversubscription = false, assume_no_thread_state = false, assume_no_nested_parallelism = false>} {}
@@ -29,3 +29,30 @@ module attributes {omp.flags = #omp.flags<assume_teams_oversubscription = true,
// CHECK: module attributes {omp.flags = #omp.flags<assume_teams_oversubscription = true, assume_no_thread_state = true>} {
module attributes {omp.flags = #omp.flags<assume_no_thread_state = true, assume_teams_oversubscription = true>} {}
+
+// CHECK: module attributes {omp.flags = #omp.flags<debug_kind = 20, openmp_device_version = 51>} {
+module attributes {omp.flags = #omp.flags<debug_kind = 20, assume_teams_oversubscription = false, assume_threads_oversubscription = false, assume_no_thread_state = false, assume_no_nested_parallelism = false, openmp_device_version = 51>} {}
+
+//: module attributes {omp.flags = #omp.flags<debug_kind = 100, assume_teams_oversubscription = true, openmp_device_version = 51>} {
+module attributes {omp.flags = #omp.flags<debug_kind = 100, assume_teams_oversubscription = true, assume_threads_oversubscription = false, assume_no_thread_state = false, assume_no_nested_parallelism = false, openmp_device_version = 51>} {}
+
+// CHECK: module attributes {omp.flags = #omp.flags<debug_kind = 200, assume_teams_oversubscription = true, assume_threads_oversubscription = true, openmp_device_version = 51>} {
+module attributes {omp.flags = #omp.flags<debug_kind = 200, assume_teams_oversubscription = true, assume_threads_oversubscription = true, assume_no_thread_state = false, assume_no_nested_parallelism = false, openmp_device_version = 51>} {}
+
+// CHECK: module attributes {omp.flags = #omp.flags<debug_kind = 300, assume_teams_oversubscription = true, assume_threads_oversubscription = true, assume_no_thread_state = true, openmp_device_version = 51>} {
+module attributes {omp.flags = #omp.flags<debug_kind = 300, assume_teams_oversubscription = true, assume_threads_oversubscription = true, assume_no_thread_state = true, assume_no_nested_parallelism = false, openmp_device_version = 51>} {}
+
+// CHECK: module attributes {omp.flags = #omp.flags<debug_kind = 400, assume_teams_oversubscription = true, assume_threads_oversubscription = true, assume_no_thread_state = true, assume_no_nested_parallelism = true, openmp_device_version = 51>} {
+module attributes {omp.flags = #omp.flags<debug_kind = 400, assume_teams_oversubscription = true, assume_threads_oversubscription = true, assume_no_thread_state = true, assume_no_nested_parallelism = true, openmp_device_version = 51>} {}
+
+// CHECK: module attributes {omp.flags = #omp.flags<assume_teams_oversubscription = true, openmp_device_version = 51>} {
+module attributes {omp.flags = #omp.flags<assume_teams_oversubscription = true, openmp_device_version = 51>} {}
+
+// CHECK: module attributes {omp.flags = #omp.flags<assume_teams_oversubscription = true, assume_no_thread_state = true, openmp_device_version = 51>} {
+module attributes {omp.flags = #omp.flags<assume_teams_oversubscription = true, assume_no_thread_state = true, openmp_device_version = 51>} {}
+
+// CHECK: module attributes {omp.flags = #omp.flags<assume_teams_oversubscription = true, assume_no_thread_state = true, openmp_device_version = 51>} {
+module attributes {omp.flags = #omp.flags<assume_no_thread_state = true, assume_teams_oversubscription = true, openmp_device_version = 51>} {}
+
+// CHECK: module attributes {omp.version = #omp.version<version = 51>} {
+module attributes {omp.version = #omp.version<version = 51>} {}
More information about the Mlir-commits
mailing list