Skip to content

[MLIR][OpenMP] Add omp.target_triples attribute to the OffloadModuleInterface #100154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 2, 2024

Conversation

skatrak
Copy link
Member

@skatrak skatrak commented Jul 23, 2024

The OffloadModuleInterface holds getter/setter methods to access OpenMP dialect module-level discardable attributes used to hold general OpenMP compilation information.

This patch adds the omp.target_triples attribute, which is intended to hold the list of offloading target triples linked to the host module in which it appears. This attribute should be empty when omp.is_target_device=true.

@llvmbot
Copy link
Member

llvmbot commented Jul 23, 2024

@llvm/pr-subscribers-mlir-openmp
@llvm/pr-subscribers-flang-openmp

@llvm/pr-subscribers-mlir

Author: Sergio Afonso (skatrak)

Changes

The OffloadModuleInterface holds getter/setter methods to access OpenMP dialect module-level discardable attributes used to hold general OpenMP compilation information.

This patch adds the omp.target_triples attribute, which is intended to hold the list of offloading target triples linked to the host module in which it appears. This attribute should be empty when omp.is_target_device=true.


Full diff: https://github.com/llvm/llvm-project/pull/100154.diff

1 Files Affected:

  • (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td (+28)
diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td
index 385aa8b1b016a..9e62dcd9253d6 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td
@@ -351,6 +351,34 @@ def OffloadModuleInterface : OpInterface<"OffloadModuleInterface"> {
       (ins "::mlir::omp::ClauseRequires":$clauses), [{}], [{
         $_op->setAttr(mlir::StringAttr::get($_op->getContext(), "omp.requires"),
           mlir::omp::ClauseRequiresAttr::get($_op->getContext(), clauses));
+      }]>,
+    InterfaceMethod<
+      /*description=*/[{
+        Get the omp.target_triples attribute on the operator if it's present and
+        return its value. If it doesn't exist, return an empty array by default.
+      }],
+      /*retTy=*/"::llvm::ArrayRef<::mlir::Attribute>",
+      /*methodName=*/"getTargetTriples",
+      (ins), [{}], [{
+        if (Attribute triplesAttr = $_op->getAttr("omp.target_triples"))
+          if (auto triples = ::llvm::dyn_cast<::mlir::ArrayAttr>(triplesAttr))
+            return triples.getValue();
+        return {};
+      }]>,
+    InterfaceMethod<
+      /*description=*/[{
+        Set the omp.target_triples attribute on the operation.
+      }],
+      /*retTy=*/"void",
+      /*methodName=*/"setTargetTriples",
+      (ins "::llvm::ArrayRef<::std::string>":$targetTriples), [{}], [{
+        auto names = ::llvm::to_vector(::llvm::map_range(
+            targetTriples, [&](::std::string str) -> ::mlir::Attribute {
+              return mlir::StringAttr::get($_op->getContext(), str);
+            }));
+        $_op->setAttr(
+            ::mlir::StringAttr::get($_op->getContext(), "omp.target_triples"),
+            ::mlir::ArrayAttr::get($_op->getContext(), names));
       }]>
   ];
 }

Copy link
Member

@Meinersbur Meinersbur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@skatrak
Copy link
Member Author

skatrak commented Jul 25, 2024

I'm thinking that perhaps omp.offload_targets would be a better name for this attribute. Do you have any opinions @bhandarkar-pranav, @Meinersbur?

@skatrak skatrak force-pushed the users/skatrak/target-host-02-mlir branch from 3dbb225 to 81fddab Compare July 26, 2024 12:28
@skatrak skatrak force-pushed the users/skatrak/target-host-01-driver branch 2 times, most recently from 3861b28 to e59c38d Compare August 1, 2024 11:50
Base automatically changed from users/skatrak/target-host-01-driver to main August 1, 2024 13:27
…nterface

The `OffloadModuleInterface` holds getter/setter methods to access OpenMP
dialect module-level discardable attributes used to hold general OpenMP
compilation information.

This patch adds the `omp.target_triples` attribute, which is intended to hold
the list of offloading target triples linked to the host module in which it
appears. This attribute should be empty when `omp.is_target_device=true`.
@skatrak skatrak force-pushed the users/skatrak/target-host-02-mlir branch from 81fddab to 2fd8456 Compare August 1, 2024 15:42
@skatrak skatrak merged commit a6a462f into main Aug 2, 2024
7 checks passed
@skatrak skatrak deleted the users/skatrak/target-host-02-mlir branch August 2, 2024 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants