Skip to content

Commit 89165e8

Browse files
authored
[flang][openacc] Disable CUDA argument checks in OpenACC regions (#72310)
Checks for CUDA Fortran data attribute compatibility don't need to be applied in OpenACC regions.
1 parent 169db80 commit 89165e8

File tree

6 files changed

+36
-6
lines changed

6 files changed

+36
-6
lines changed

flang/include/flang/Semantics/scope.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class Scope {
6161
public:
6262
ENUM_CLASS(Kind, Global, IntrinsicModules, Module, MainProgram, Subprogram,
6363
BlockData, DerivedType, BlockConstruct, Forall, OtherConstruct,
64-
ImpliedDos)
64+
OpenACCConstruct, ImpliedDos)
6565
using ImportKind = common::ImportKind;
6666

6767
// Create the Global scope -- the root of the scope tree

flang/include/flang/Semantics/tools.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ const Scope &GetProgramUnitOrBlockConstructContaining(const Symbol &);
4444
const Scope *FindModuleContaining(const Scope &);
4545
const Scope *FindModuleFileContaining(const Scope &);
4646
const Scope *FindPureProcedureContaining(const Scope &);
47-
const Scope *FindPureProcedureContaining(const Symbol &);
47+
const Scope *FindOpenACCConstructContaining(const Scope *);
48+
4849
const Symbol *FindPointerComponent(const Scope &);
4950
const Symbol *FindPointerComponent(const DerivedTypeSpec &);
5051
const Symbol *FindPointerComponent(const DeclTypeSpec &);

flang/lib/Semantics/check-call.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -856,9 +856,12 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
856856
}
857857
}
858858

859-
// CUDA
859+
// CUDA specific checks
860+
// TODO: These are disabled in OpenACC constructs, which may not be
861+
// correct when the target is not a GPU.
860862
if (!intrinsic &&
861-
!dummy.attrs.test(characteristics::DummyDataObject::Attr::Value)) {
863+
!dummy.attrs.test(characteristics::DummyDataObject::Attr::Value) &&
864+
!FindOpenACCConstructContaining(scope)) {
862865
std::optional<common::CUDADataAttr> actualDataAttr, dummyDataAttr;
863866
if (const auto *actualObject{actualLastSymbol
864867
? actualLastSymbol->detailsIf<ObjectEntityDetails>()

flang/lib/Semantics/resolve-names.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1332,6 +1332,8 @@ class AccVisitor : public virtual DeclarationVisitor {
13321332

13331333
bool Pre(const parser::OpenACCBlockConstruct &);
13341334
void Post(const parser::OpenACCBlockConstruct &);
1335+
bool Pre(const parser::OpenACCCombinedConstruct &);
1336+
void Post(const parser::OpenACCCombinedConstruct &);
13351337
bool Pre(const parser::AccBeginBlockDirective &x) {
13361338
AddAccSourceRange(x.source);
13371339
return true;
@@ -1377,7 +1379,7 @@ void AccVisitor::AddAccSourceRange(const parser::CharBlock &source) {
13771379

13781380
bool AccVisitor::Pre(const parser::OpenACCBlockConstruct &x) {
13791381
if (NeedsScope(x)) {
1380-
PushScope(Scope::Kind::OtherConstruct, nullptr);
1382+
PushScope(Scope::Kind::OpenACCConstruct, nullptr);
13811383
}
13821384
return true;
13831385
}
@@ -1388,6 +1390,13 @@ void AccVisitor::Post(const parser::OpenACCBlockConstruct &x) {
13881390
}
13891391
}
13901392

1393+
bool AccVisitor::Pre(const parser::OpenACCCombinedConstruct &x) {
1394+
PushScope(Scope::Kind::OpenACCConstruct, nullptr);
1395+
return true;
1396+
}
1397+
1398+
void AccVisitor::Post(const parser::OpenACCCombinedConstruct &x) { PopScope(); }
1399+
13911400
// Create scopes for OpenMP constructs
13921401
class OmpVisitor : public virtual DeclarationVisitor {
13931402
public:

flang/lib/Semantics/tools.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ const Scope *FindPureProcedureContaining(const Scope &start) {
108108
}
109109
}
110110

111+
const Scope *FindOpenACCConstructContaining(const Scope *scope) {
112+
return scope ? FindScopeContaining(*scope,
113+
[](const Scope &s) {
114+
return s.kind() == Scope::Kind::OpenACCConstruct;
115+
})
116+
: nullptr;
117+
}
118+
111119
// 7.5.2.4 "same derived type" test -- rely on IsTkCompatibleWith() and its
112120
// infrastructure to detect and handle comparisons on distinct (but "same")
113121
// sequence/bind(C) derived types

flang/test/Semantics/cuf10.cuf

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
! RUN: %python %S/test_errors.py %s %flang_fc1
1+
! RUN: %python %S/test_errors.py %s %flang_fc1 -fopenacc
22
module m
33
real, device :: a(4,8)
44
real, managed, allocatable :: b(:,:)
@@ -9,9 +9,18 @@ module m
99
real a(n,m), c(n,m)
1010
real, managed :: b(n,m)
1111
end
12+
attributes(device) subroutine devsub(a,n)
13+
integer, value :: n
14+
real, device :: a(n)
15+
end
1216
subroutine test
17+
real c(4)
1318
allocate(b(4,8))
1419
!ERROR: dummy argument 'm=' has ATTRIBUTES(DEVICE) but its associated actual argument has no CUDA data attribute
1520
call kernel<<<1,32>>>(a,b,b,4,8)
21+
!$acc parallel loop copy(c)
22+
do j = 1, 1
23+
call devsub(c,4) ! not checked in OpenACC construct
24+
end do
1625
end
1726
end

0 commit comments

Comments
 (0)