Skip to content

Commit 2e353a6

Browse files
authored
[flang][openacc] Relax constraint on OpenACC declare statement (#135238)
OpenACC declare statements are restricted from having having clauses that reference assumed size arrays. It should be the case that we can implement `deviceptr` and `present` clauses for assumed-size arrays. This is a first step towards relaxing this restriction. Note running flang on the following example results in an error in lowering. ``` $ cat t.f90 subroutine vadd (a, b, c, n) real(8) :: a(*), b(*), c(*) !$acc declare deviceptr(a, b, c) !$acc parallel loop do i = 1,n c(i) = a(i) + b(i) enddo end subroutine $ flang -fopenacc -c t.f90 error: loc("/home/akuhlenschmi/work/p4/ta/tests/openacc/src/t.f90":3:7): expect declare attribute on variable in declare operation error: Lowering to LLVM IR failed error: loc("/home/akuhlenschmi/work/p4/ta/tests/openacc/src/t.f90":4:7): unsupported OpenACC operation: acc.private.recipe error: loc("/home/akuhlenschmi/work/p4/ta/tests/openacc/src/t.f90":4:7): LLVM Translation failed for operation: acc.private.recipe error: failed to create the LLVM module ``` I would like to to share this code, because others are currently working on the implementation of `deviceptr`, but it is obviously not running end-to-end. I think the cleanest approach to this would be to put this exception to the rule behind some feature flag, but I am not certain what the precedence for that is.
1 parent 71d1059 commit 2e353a6

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

flang/docs/OpenACC.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ local:
2525
logical expression.
2626
* `!$acc routine` directive can be placed at the top level.
2727
* `!$acc cache` directive accepts scalar variable.
28+
* The `!$acc declare` directive accepts assumed size array arguments for
29+
`deviceptr` and `present` clauses.
2830

2931
## Remarks about incompatibilities with other implementations
3032
* Array element references in the data clauses are equivalent to array sections

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,14 @@ void AccAttributeVisitor::Post(
953953
const auto &clauseList = std::get<parser::AccClauseList>(x.t);
954954
for (const auto &clause : clauseList.v) {
955955
// Restriction - line 2414
956-
DoNotAllowAssumedSizedArray(GetAccObjectList(clause));
956+
// We assume the restriction is present because clauses that require
957+
// moving data would require the size of the data to be present, but
958+
// the deviceptr and present clauses do not require moving data and
959+
// thus we permit them.
960+
if (!std::holds_alternative<parser::AccClause::Deviceptr>(clause.u) &&
961+
!std::holds_alternative<parser::AccClause::Present>(clause.u)) {
962+
DoNotAllowAssumedSizedArray(GetAccObjectList(clause));
963+
}
957964
}
958965
}
959966

flang/test/Semantics/OpenACC/acc-declare-validity.f90

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,21 @@ end function fct1
6262
subroutine sub2(cc)
6363
real(8), dimension(*) :: cc
6464
!ERROR: Assumed-size dummy arrays may not appear on the DECLARE directive
65-
!$acc declare present(cc)
65+
!$acc declare copyin(cc)
6666
end subroutine sub2
6767

68+
subroutine sub2e1(cc)
69+
real(8), dimension(*) :: cc
70+
!OK
71+
!$acc declare present(cc)
72+
end subroutine sub2e1
73+
74+
subroutine sub2e2(cc)
75+
real(8), dimension(*) :: cc
76+
!OK
77+
!$acc declare deviceptr(cc)
78+
end subroutine sub2e2
79+
6880
subroutine sub3()
6981
real :: aa(100)
7082
!ERROR: The ZERO modifier is not allowed for the COPYOUT clause on the DECLARE directive

0 commit comments

Comments
 (0)