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

            Bug ID: 129002
           Summary: [OpenMP] Scalar ASSOCIATE name in a target region is
                    mapped as its host pointer
           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: ---

Summary:   [OpenMP] Scalar ASSOCIATE name in a target region is mapped
           as its host pointer
An associate name whose selector is a scalar variable is a pointer to
the selector.  In a target region gfortran maps that pointer itself
instead of the variable it points to, so the device dereferences a
host address.

module m
contains
  subroutine upd (w, lr)
    real :: w(8)
    real, intent(in) :: lr
    integer :: i
    associate (eta => lr)
      !$omp target
      do i = 1, 8
        w(i) = w(i) - eta
      end do
      !$omp end target
    end associate
  end subroutine
end module
program p
  use m
  real :: w(8)
  w = 1.0
  call upd (w, 0.5)
  if (any (w /= 0.5)) stop 1
end program

$ gfortran -fopenmp pr.f90 && OMP_TARGET_OFFLOAD=mandatory ./a.out
Memory access fault by GPU node-1 (Agent handle: ...) on address
0x400000. Reason: Page not present or supervisor privilege.

-fdump-tree-gimple shows map(tofrom:eta [len: 8] [runtime_implicit]).
OPTIONAL selectors and target teams distribute parallel do fail the
same way; writing lr instead of eta works.

Expected: the program completes.  By OpenMP 5.2, 5.8.1, a scalar
without TARGET, POINTER or ALLOCATABLE that is not mapped is
firstprivate in a target region; a non-scalar associate name is mapped
tofrom.  On the host such names are predetermined firstprivate (a copy
of the pointer), where 5.1.1 says shared; that gives no wrong results
but the fix makes them shared.

Found in the fiats package (associate (eta => learning_rate) around an
offloaded loop).
  • [Bug fortran/129002] New: [OpenM... jvdelisle at gcc dot gnu.org via Gcc-bugs

Reply via email to