-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[flang][cuda] Allow SHARED actual to DEVICE dummy #115215
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-flang-semantics Author: Valentin Clement (バレンタイン クレメン) (clementval) ChangesUpdate the compatibility rules to allow SHARED actual argument passed to DEVICE dummy argument. Emit a warning in that case. Full diff: https://github.com/llvm/llvm-project/pull/115215.diff 5 Files Affected:
diff --git a/flang/include/flang/Common/Fortran.h b/flang/include/flang/Common/Fortran.h
index 5b2ed43a8f99c0..cb109ad574cf6e 100644
--- a/flang/include/flang/Common/Fortran.h
+++ b/flang/include/flang/Common/Fortran.h
@@ -118,7 +118,8 @@ static constexpr IgnoreTKRSet ignoreTKRAll{IgnoreTKR::Type, IgnoreTKR::Kind,
std::string AsFortran(IgnoreTKRSet);
bool AreCompatibleCUDADataAttrs(std::optional<CUDADataAttr>,
- std::optional<CUDADataAttr>, IgnoreTKRSet, bool allowUnifiedMatchingRule,
+ std::optional<CUDADataAttr>, IgnoreTKRSet, std::optional<std::string> *,
+ bool allowUnifiedMatchingRule,
const LanguageFeatureControl *features = nullptr);
static constexpr char blankCommonObjectName[] = "__BLNK__";
diff --git a/flang/lib/Common/Fortran.cpp b/flang/lib/Common/Fortran.cpp
index c014b1263a67f0..dc0c9d6406474d 100644
--- a/flang/lib/Common/Fortran.cpp
+++ b/flang/lib/Common/Fortran.cpp
@@ -103,7 +103,8 @@ std::string AsFortran(IgnoreTKRSet tkr) {
/// dummy argument attribute while `y` represents the actual argument attribute.
bool AreCompatibleCUDADataAttrs(std::optional<CUDADataAttr> x,
std::optional<CUDADataAttr> y, IgnoreTKRSet ignoreTKR,
- bool allowUnifiedMatchingRule, const LanguageFeatureControl *features) {
+ std::optional<std::string> *warning, bool allowUnifiedMatchingRule,
+ const LanguageFeatureControl *features) {
bool isCudaManaged{features
? features->IsEnabled(common::LanguageFeature::CudaManaged)
: false};
@@ -134,8 +135,12 @@ bool AreCompatibleCUDADataAttrs(std::optional<CUDADataAttr> x,
} else {
if (*x == CUDADataAttr::Device) {
if ((y &&
- (*y == CUDADataAttr::Managed || *y == CUDADataAttr::Unified)) ||
+ (*y == CUDADataAttr::Managed || *y == CUDADataAttr::Unified ||
+ *y == CUDADataAttr::Shared)) ||
(!y && (isCudaUnified || isCudaManaged))) {
+ if (y && *y == CUDADataAttr::Shared) {
+ *warning = "SHARED attribute ignored"s;
+ }
return true;
}
} else if (*x == CUDADataAttr::Managed) {
diff --git a/flang/lib/Evaluate/characteristics.cpp b/flang/lib/Evaluate/characteristics.cpp
index 2496e4427fe7ae..a835aecfaf5ece 100644
--- a/flang/lib/Evaluate/characteristics.cpp
+++ b/flang/lib/Evaluate/characteristics.cpp
@@ -371,7 +371,7 @@ bool DummyDataObject::IsCompatibleWith(const DummyDataObject &actual,
}
if (!attrs.test(Attr::Value) &&
!common::AreCompatibleCUDADataAttrs(cudaDataAttr, actual.cudaDataAttr,
- ignoreTKR,
+ ignoreTKR, warning,
/*allowUnifiedMatchingRule=*/false)) {
if (whyNot) {
*whyNot = "incompatible CUDA data attributes";
@@ -1762,6 +1762,7 @@ bool DistinguishUtils::Distinguishable(
bool DistinguishUtils::Distinguishable(
const DummyDataObject &x, const DummyDataObject &y) const {
using Attr = DummyDataObject::Attr;
+ std::optional<std::string> warning;
if (Distinguishable(x.type, y.type, x.ignoreTKR | y.ignoreTKR)) {
return true;
} else if (x.attrs.test(Attr::Allocatable) && y.attrs.test(Attr::Pointer) &&
@@ -1771,7 +1772,7 @@ bool DistinguishUtils::Distinguishable(
x.intent != common::Intent::In) {
return true;
} else if (!common::AreCompatibleCUDADataAttrs(x.cudaDataAttr, y.cudaDataAttr,
- x.ignoreTKR | y.ignoreTKR,
+ x.ignoreTKR | y.ignoreTKR, &warning,
/*allowUnifiedMatchingRule=*/false)) {
return true;
} else if (features_.IsEnabled(
diff --git a/flang/lib/Semantics/check-call.cpp b/flang/lib/Semantics/check-call.cpp
index fa2d59da10f827..a161d2bdf9dbb8 100644
--- a/flang/lib/Semantics/check-call.cpp
+++ b/flang/lib/Semantics/check-call.cpp
@@ -976,8 +976,9 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
actualDataAttr = common::CUDADataAttr::Device;
}
}
+ std::optional<std::string> warning;
if (!common::AreCompatibleCUDADataAttrs(dummyDataAttr, actualDataAttr,
- dummy.ignoreTKR,
+ dummy.ignoreTKR, &warning,
/*allowUnifiedMatchingRule=*/true, &context.languageFeatures())) {
auto toStr{[](std::optional<common::CUDADataAttr> x) {
return x ? "ATTRIBUTES("s +
@@ -988,6 +989,10 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
"%s has %s but its associated actual argument has %s"_err_en_US,
dummyName, toStr(dummyDataAttr), toStr(actualDataAttr));
}
+ if (warning && context.ShouldWarn(common::UsageWarning::CUDAUsage)) {
+ messages.Say(common::UsageWarning::CUDAUsage, "%s"_warn_en_US,
+ std::move(*warning));
+ }
}
// Warning for breaking F'2023 change with character allocatables
diff --git a/flang/test/Semantics/cuf17.cuf b/flang/test/Semantics/cuf17.cuf
new file mode 100644
index 00000000000000..daeb59033561cf
--- /dev/null
+++ b/flang/test/Semantics/cuf17.cuf
@@ -0,0 +1,18 @@
+! RUN: bbc -emit-hlfir -fcuda %s 2>&1 | FileCheck %s
+
+module mod1
+contains
+
+attributes(device) subroutine sub1(adev)
+ real, device :: adev(10)
+end
+
+attributes(global) subroutine sub2()
+ real, shared :: adev(10)
+ !WARNING: SHARED attribute ignored
+ call sub1(adev)
+end subroutine
+
+end module
+
+! CHECK: warning: SHARED attribute ignored
|
klausler
reviewed
Nov 6, 2024
klausler
approved these changes
Nov 6, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Update the compatibility rules to allow SHARED actual argument passed to DEVICE dummy argument. Emit a warning in that case.