Skip to content

[OpenMPOpt] Initialize OpenMPIRBuilderConfig::IsGPU flag #104456

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
Sep 5, 2024

Conversation

skatrak
Copy link
Member

@skatrak skatrak commented Aug 15, 2024

This patch ensures the IsGPU flag is set by the OpenMPOpt pass, so that it can be relied upon by OpenMPIRBuilder methods when called by that pass as well.

Since currently there are very limited callers for the OpenMPIRBuilder::isGPU() method, no assertions are being triggered by the lack of initialization of this flag. However, when more offloading-related features are implemented, it will eventually start happening.

@llvmbot llvmbot added llvm:transforms clang:openmp OpenMP related changes to Clang labels Aug 15, 2024
@llvmbot
Copy link
Member

llvmbot commented Aug 15, 2024

@llvm/pr-subscribers-llvm-transforms

Author: Sergio Afonso (skatrak)

Changes

This patch ensures the IsGPU flag is set by the OpenMPOpt pass, so that it can be relied upon by OpenMPIRBuilder methods when called by that pass as well.

Since currently there are very limited callers for the OpenMPIRBuilder::isGPU() method, no assertions are being triggered by the lack of initialization of this flag. However, when more offloading-related features are implemented, it will eventually start happening.


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

1 Files Affected:

  • (modified) llvm/lib/Transforms/IPO/OpenMPOpt.cpp (+13)
diff --git a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
index 798bcb77328fc..8c2e8e5039510 100644
--- a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
+++ b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
@@ -286,6 +286,19 @@ struct OMPInformationCache : public InformationCache {
         OpenMPPostLink(OpenMPPostLink) {
 
     OMPBuilder.Config.IsTargetDevice = isOpenMPDevice(OMPBuilder.M);
+    const Triple T(OMPBuilder.M.getTargetTriple());
+    switch (T.getArch()) {
+    case llvm::Triple::nvptx:
+    case llvm::Triple::nvptx64:
+    case llvm::Triple::amdgcn:
+      assert(OMPBuilder.Config.IsTargetDevice &&
+             "OpenMP AMDGPU/NVPTX is only prepared to deal with device code.");
+      OMPBuilder.Config.IsGPU = true;
+      break;
+    default:
+      OMPBuilder.Config.IsGPU = false;
+      break;
+    }
     OMPBuilder.initialize();
     initializeRuntimeFunctions(M);
     initializeInternalControlVars();

@shiltian
Copy link
Contributor

The change is fine but I wonder in what cases the assertion can be triggered.

@skatrak
Copy link
Member Author

skatrak commented Aug 19, 2024

The change is fine but I wonder in what cases the assertion can be triggered.

Thank you @shiltian for giving this a look. At the moment it would be difficult (maybe impossible?) to trigger, since OpenMPIRBuilder::isGPU() is barely called at all. We do have downstream features (which we plan on upstreaming hopefully soon) that introduce more uses of that flag within the OMPIRBuilder, and those do trigger the assertion if it's not initialized by the OpenMPOpt pass.

Even if the assert doesn't currently trigger, I think it's worth making sure this property is initialized since it's a bit of a hidden bug.

@skatrak
Copy link
Member Author

skatrak commented Sep 2, 2024

Ping for review!

This patch ensures the `IsGPU` flag is set by the OpenMPOpt pass, so that it
can be relied upon by `OpenMPIRBuilder` methods when called by that pass as
well.

Since currently there are very limited callers for the
`OpenMPIRBuilder::isGPU()` method, no assertions are being triggered by the
lack of initialization of this flag. However, when more offloading-related
features are implemented, it will eventually start happening.
@skatrak skatrak merged commit 07bef02 into llvm:main Sep 5, 2024
8 checks passed
@skatrak skatrak deleted the omp-opt-isgpu branch September 5, 2024 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:openmp OpenMP related changes to Clang llvm:transforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants