https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129255

            Bug ID: 129255
           Summary: [OpenMP] Deep mapping of a strided array with
                    allocatable components maps the wrong elements
           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: ---

When a strided array of a derived type with allocatable components is
mapped, the allocatable components are mapped for the wrong elements.
The deep-mapping loop generated by gfc_omp_deep_mapping_item steps
through the array from its data pointer by the element length, for as
many elements as the array has, and ignores the strides in the
descriptor:

  D.4986 = q.data;
  D.4987 = q.dtype.elem_len;
  D.4988 = idx.41 * D.4987;
  D.4989 = D.4986 + D.4988;
  D.4992 = D.4989->a.data;

For q => arr(1:20:2) below it maps arr(1:10)%a instead of
arr(1:19:2)%a, so the kernel dereferences the host addresses of
arr(11:19:2)%a and the GPU faults:

  Memory access fault by GPU node-1 (Agent handle: ...) on address
  0x2ca20000. Reason: Page not present or supervisor privilege.

The same happens at -O0 and -O2.  With a contiguous q => arr(1:10) the
program passes.

$ gfortran -fopenmp pr.f90 && ./a.out

program p
  implicit none
  type t
    integer, allocatable :: a(:)
  end type
  type(t), target :: arr(20)
  type(t), pointer :: q(:)
  integer :: i
  do i = 1, 20
    allocate (arr(i)%a(3), source=i)
  end do
  q => arr(1:20:2)
  !$omp target map(tofrom: q)
  do i = 1, 10
    q(i)%a(1) = q(i)%a(1) + 100
  end do
  !$omp end target
  do i = 1, 20
    if (arr(i)%a(1) /= merge (i + 100, i, mod (i, 2) == 1)) stop 1
  end do
  print *, 'OK'
end program

Configuration: x86_64-pc-linux-gnu host configured with
--enable-offload-targets=amdgcn-amdhsa, device gfx1032 (Navi 23).
Trunk basepoints/gcc-17-6999-g8de88fb84e7 plus local gfortran patches,
none of which changes gfc_omp_deep_mapping_item.  Older releases not
checked.

Found while testing a fix for PR128977.
  • [Bug fortran/129255] New: [OpenM... jvdelisle at gcc dot gnu.org via Gcc-bugs

Reply via email to