https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128977
Bug ID: 128977
Summary: [OpenMP] Wrong map start and length for a
non-contiguous assumed-shape dummy
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: jvdelisle at gcc dot gnu.org
Target Milestone: ---
Created attachment 66275
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=66275&action=edit
Draft patch that fixes this.
This one found while testing auto prallization of DO CONCURRENT.
When an assumed-shape dummy array is mapped to an offload device,
gfortran maps the range starting at its first element with length
stride(last dim) * extent(last dim) elements. That is the size of the
array only when it is contiguous. For other actual arguments:
- transpose(G), or any section whose strides are not increasing: the
length is too short, so part of the array is never mapped;
- a section strided in the last dimension, e.g. x(:,1:5:2): the length
runs past the last element (and past the end of x);
- a negative stride: elements lie below the first one, outside the
mapped range.
This affects implicit maps, explicit map clauses (including target
enter/exit data) and target update to/from.
Reproducer (needs an offload device; host fallback passes):
module diag3_m
contains
subroutine post(A, d, AD)
double precision, intent(in) :: A(:,:), d(:)
double precision, intent(out) :: AD(:,:)
integer column
!$omp target teams distribute parallel do
do column = 1, size(A,2)
AD(:,column) = A(:,column) * d(column)
end do
end subroutine
end module
program p
use diag3_m
double precision :: G(3,4), T(4,3), d(3), R(4,3), E(4,3)
integer :: i, j
G = reshape([(dble(i), i = 1, 12)], shape(G))
d = [1d0, 10d0, 100d0]
T = transpose(G)
do j = 1, 3
E(:,j) = T(:,j) * d(j)
end do
call post(T, d, R)
if (any(R /= E)) stop 1
call post(transpose(G), d, R)
if (any(R /= E)) stop 2
end program
$ gfortran -fopenmp diag3.f90 && ./a.out
STOP 2
(seen with amdgcn offloading). The second call passes transpose(G)
without a copy, so A has extents 4 and 3 with strides 3 and 1.
-fdump-tree-gimple shows the map length taken from the last dimension
only:
size.5 = stride.3 * NON_LVALUE_EXPR <ubound.2>;
...
map(tofrom:*a.0 [len: _29]) map(alloc:a.0 [pointer assign, bias: 0])
That maps 1*3 = 3 elements, but the elements of A span
3*3 + 1*2 + 1 = 12.
Expected: the mapped range runs from the lowest to the highest
addressed element of the dummy, so the program completes without
STOP.
Fix available -- patch attached.