-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[flang][openacc] Disable CUDA argument checks in OpenACC regions #72310
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
Conversation
Checks for CUDA Fortran data attribute compatibility don't need to be applied in OpenACC regions.
@llvm/pr-subscribers-flang-semantics Author: Peter Klausler (klausler) ChangesChecks for CUDA Fortran data attribute compatibility don't need to be applied in OpenACC regions. Full diff: https://github.com/llvm/llvm-project/pull/72310.diff 6 Files Affected:
diff --git a/flang/include/flang/Semantics/scope.h b/flang/include/flang/Semantics/scope.h
index d2d42d0a79af8c5..21072772d184b66 100644
--- a/flang/include/flang/Semantics/scope.h
+++ b/flang/include/flang/Semantics/scope.h
@@ -61,7 +61,7 @@ class Scope {
public:
ENUM_CLASS(Kind, Global, IntrinsicModules, Module, MainProgram, Subprogram,
BlockData, DerivedType, BlockConstruct, Forall, OtherConstruct,
- ImpliedDos)
+ OpenACCConstruct, ImpliedDos)
using ImportKind = common::ImportKind;
// Create the Global scope -- the root of the scope tree
diff --git a/flang/include/flang/Semantics/tools.h b/flang/include/flang/Semantics/tools.h
index 633787f45e85255..b245081847016b6 100644
--- a/flang/include/flang/Semantics/tools.h
+++ b/flang/include/flang/Semantics/tools.h
@@ -44,7 +44,8 @@ const Scope &GetProgramUnitOrBlockConstructContaining(const Symbol &);
const Scope *FindModuleContaining(const Scope &);
const Scope *FindModuleFileContaining(const Scope &);
const Scope *FindPureProcedureContaining(const Scope &);
-const Scope *FindPureProcedureContaining(const Symbol &);
+const Scope *FindOpenACCConstructContaining(const Scope *);
+
const Symbol *FindPointerComponent(const Scope &);
const Symbol *FindPointerComponent(const DerivedTypeSpec &);
const Symbol *FindPointerComponent(const DeclTypeSpec &);
diff --git a/flang/lib/Semantics/check-call.cpp b/flang/lib/Semantics/check-call.cpp
index efc2cb0a291ddce..b3f3b74b04ee111 100644
--- a/flang/lib/Semantics/check-call.cpp
+++ b/flang/lib/Semantics/check-call.cpp
@@ -856,9 +856,12 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
}
}
- // CUDA
+ // CUDA specific checks
+ // TODO: These are disabled in OpenACC constructs, which may not be
+ // correct when the target is not a GPU.
if (!intrinsic &&
- !dummy.attrs.test(characteristics::DummyDataObject::Attr::Value)) {
+ !dummy.attrs.test(characteristics::DummyDataObject::Attr::Value) &&
+ !FindOpenACCConstructContaining(scope)) {
std::optional<common::CUDADataAttr> actualDataAttr, dummyDataAttr;
if (const auto *actualObject{actualLastSymbol
? actualLastSymbol->detailsIf<ObjectEntityDetails>()
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 8f15f2f51da7c89..5fa31d6b4f3f77d 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -1332,6 +1332,8 @@ class AccVisitor : public virtual DeclarationVisitor {
bool Pre(const parser::OpenACCBlockConstruct &);
void Post(const parser::OpenACCBlockConstruct &);
+ bool Pre(const parser::OpenACCCombinedConstruct &);
+ void Post(const parser::OpenACCCombinedConstruct &);
bool Pre(const parser::AccBeginBlockDirective &x) {
AddAccSourceRange(x.source);
return true;
@@ -1377,7 +1379,7 @@ void AccVisitor::AddAccSourceRange(const parser::CharBlock &source) {
bool AccVisitor::Pre(const parser::OpenACCBlockConstruct &x) {
if (NeedsScope(x)) {
- PushScope(Scope::Kind::OtherConstruct, nullptr);
+ PushScope(Scope::Kind::OpenACCConstruct, nullptr);
}
return true;
}
@@ -1388,6 +1390,13 @@ void AccVisitor::Post(const parser::OpenACCBlockConstruct &x) {
}
}
+bool AccVisitor::Pre(const parser::OpenACCCombinedConstruct &x) {
+ PushScope(Scope::Kind::OpenACCConstruct, nullptr);
+ return true;
+}
+
+void AccVisitor::Post(const parser::OpenACCCombinedConstruct &x) { PopScope(); }
+
// Create scopes for OpenMP constructs
class OmpVisitor : public virtual DeclarationVisitor {
public:
diff --git a/flang/lib/Semantics/tools.cpp b/flang/lib/Semantics/tools.cpp
index 7d6ab2c83cc5952..39d6fdc97512aaa 100644
--- a/flang/lib/Semantics/tools.cpp
+++ b/flang/lib/Semantics/tools.cpp
@@ -108,6 +108,14 @@ const Scope *FindPureProcedureContaining(const Scope &start) {
}
}
+const Scope *FindOpenACCConstructContaining(const Scope *scope) {
+ return scope ? FindScopeContaining(*scope,
+ [](const Scope &s) {
+ return s.kind() == Scope::Kind::OpenACCConstruct;
+ })
+ : nullptr;
+}
+
// 7.5.2.4 "same derived type" test -- rely on IsTkCompatibleWith() and its
// infrastructure to detect and handle comparisons on distinct (but "same")
// sequence/bind(C) derived types
diff --git a/flang/test/Semantics/cuf10.cuf b/flang/test/Semantics/cuf10.cuf
index 0d05222d446df1f..047503b3cca4eac 100644
--- a/flang/test/Semantics/cuf10.cuf
+++ b/flang/test/Semantics/cuf10.cuf
@@ -1,4 +1,4 @@
-! RUN: %python %S/test_errors.py %s %flang_fc1
+! RUN: %python %S/test_errors.py %s %flang_fc1 -fopenacc
module m
real, device :: a(4,8)
real, managed, allocatable :: b(:,:)
@@ -9,9 +9,18 @@ module m
real a(n,m), c(n,m)
real, managed :: b(n,m)
end
+ attributes(device) subroutine devsub(a,n)
+ integer, value :: n
+ real, device :: a(n)
+ end
subroutine test
+ real c(4)
allocate(b(4,8))
!ERROR: dummy argument 'm=' has ATTRIBUTES(DEVICE) but its associated actual argument has no CUDA data attribute
call kernel<<<1,32>>>(a,b,b,4,8)
+ !$acc parallel loop copy(c)
+ do j = 1, 1
+ call devsub(c,4) ! not checked in OpenACC construct
+ end do
end
end
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Checks for CUDA Fortran data attribute compatibility don't need to be applied in OpenACC regions.