Skip to content

Commit

Permalink
[flang][cuda] Allow SHARED actual to DEVICE dummy (#115215)
Browse files Browse the repository at this point in the history
Update the compatibility rules to allow SHARED actual argument passed to
DEVICE dummy argument. Emit a warning in that case.
  • Loading branch information
clementval authored Nov 7, 2024
1 parent 29a5c05 commit 30d8000
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
3 changes: 2 additions & 1 deletion flang/include/flang/Common/Fortran.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__";
Expand Down
9 changes: 7 additions & 2 deletions flang/lib/Common/Fortran.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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) {
*warning = "SHARED attribute ignored"s;
}
return true;
}
} else if (*x == CUDADataAttr::Managed) {
Expand Down
4 changes: 2 additions & 2 deletions flang/lib/Evaluate/characteristics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -1771,7 +1771,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, nullptr,
/*allowUnifiedMatchingRule=*/false)) {
return true;
} else if (features_.IsEnabled(
Expand Down
7 changes: 6 additions & 1 deletion flang/lib/Semantics/check-call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 +
Expand All @@ -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
Expand Down
18 changes: 18 additions & 0 deletions flang/test/Semantics/cuf17.cuf
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 30d8000

Please sign in to comment.