OffTarget

Observed issues › fuzz/b3-61-cce20

Appears to behave incorrectlyWrong answer · Fortran · OpenMP · Open

ftn: a target construct with in_reduction in an internal subroutine loses the writes to an implicitly mapped dummy array

Legality: not independently confirmed. Independent readings are uncertain: in_reduction on target inside a matching taskgroup task_reduction is allowed. The base variable r3a is mapped tofrom with always, and a private copy may be created and implicitly mapped, so whether the host value r3a=45 survives depends on unspecified copy-back and combination order. The text does not pin the expected checksum, so a differing result cannot be shown to be an error. Both readings reach this; neither identifies a required value. How this is checked

Affected variants

CompilerMI300A gfx942
unified memory (XNACK 1)
MI300A gfx942
copy (XNACK 0)
MI250X gfx90a
copy (XNACK 0)
MI300X gfx942
copy (XNACK 0)
MI350X gfx950
copy (XNACK 0)
A100 sm_80
separate memory
A100 sm_80
managed memory
AFAR 24.3.0correctcorrectunknown
not run
correctcorrectn/an/a
CCE 19.0.0behaves incorrectlybehaves incorrectlyunknown
not run
unknown
not run
unknown
not run
n/an/a
CCE 20.0.2behaves incorrectlybehaves incorrectlyunknown
not run
unknown
not run
unknown
not run
n/an/a
CCE 21.0.3behaves incorrectlybehaves incorrectlyunknown
not run
unknown
not run
unknown
not run
n/an/a
CCE 21.0.4behaves incorrectlybehaves incorrectlyunknown
not run
unknown
not run
unknown
not run
n/an/a
NVHPC 25.11n/an/an/an/an/afails another wayfails another way
NVHPC 26.9n/an/an/an/an/afails another wayfails another way
GCC 16.2.0fails another wayfails another wayfails another wayfails another wayfails another wayfails another wayn/a

"behaves incorrectly" / "not supported": this issue, confirmed in up to four environments (another build directory, another node, a repeat). "fails another way": a different failure, not counted as this issue. "unknown": not run there, or the runs disagree.

Messages

ResultCompiler and GPUMessage
behaves incorrectlyCCE 19.0.0, MI300A unified
CCE 19.0.0, MI300A copy
CCE 20.0.2, MI300A unified
CCE 20.0.2, MI300A copy
CCE 21.0.3, MI300A unified
CCE 21.0.3, MI300A copy
CCE 21.0.4, MI300A unified
CCE 21.0.4, MI300A copy
show
RESULT checksum=1451519883 ran_on_host=0
fails another wayNVHPC 25.11, A100 separate
NVHPC 25.11, A100 managed
show
NVFORTRAN-S-0034-Syntax error at or near identifier task_reduction (fuzz-b3-61-cce20.f90: 22)
NVFORTRAN-S-0034-Syntax error at or near identifier in_reduction (fuzz-b3-61-cce20.f90: 23)
NVFORTRAN/x86-64 Linux 25.11-0: compilation completed with severe errors
fails another wayNVHPC 26.9, A100 separate
NVHPC 26.9, A100 managed
show
NVFORTRAN-S-0034-Syntax error at or near identifier task_reduction (fuzz-b3-61-cce20.f90: 22)
NVFORTRAN-S-0034-Syntax error at or near identifier in_reduction (fuzz-b3-61-cce20.f90: 23)
NVFORTRAN/x86-64 Linux 26.9-0: compilation completed with severe errors
fails another wayGCC 16.2.0, MI300A unified
GCC 16.2.0, MI300A copy
GCC 16.2.0, MI250X
GCC 16.2.0, MI300X
GCC 16.2.0, MI350X
GCC 16.2.0, A100 separate
show
libgomp: OMP_TARGET_OFFLOAD is set to MANDATORY, but device not found

Reproduce

CCE 19.0.0, MI300A unified

module load cce/19.0.0 craype-accel-amd-gfx942 rocm/6.4.3
module unload cray-mpich
ftn -fopenmp -O2 repro.f90 -o repro
HSA_XNACK=1 OMP_TARGET_OFFLOAD=mandatory ./repro

CCE 20.0.2, MI300A unified

module load cce/20.0.2 craype-accel-amd-gfx942 rocm/6.4.3
module unload cray-mpich
ftn -fopenmp -O2 repro.f90 -o repro
HSA_XNACK=1 OMP_TARGET_OFFLOAD=mandatory ./repro

CCE 21.0.3, MI300A unified

module load cce/21.0.3 craype-accel-amd-gfx942 rocm/7.2.0
module unload cray-mpich
ftn -fopenmp -O2 repro.f90 -o repro
HSA_XNACK=1 OMP_TARGET_OFFLOAD=mandatory ./repro

CCE 21.0.4, MI300A unified

module load cce/21.0.4 craype-accel-amd-gfx942 rocm/7.2.0
module unload cray-mpich
ftn -fopenmp -O2 repro.f90 -o repro
HSA_XNACK=1 OMP_TARGET_OFFLOAD=mandatory ./repro

AFAR 24.3.0, MI300A unified (runs correctly)

$AFAR/bin/amdflang -fopenmp --offload-arch=gfx942 -O2 repro.f90 -o repro
HSA_XNACK=1 OMP_TARGET_OFFLOAD=mandatory ./repro
Program (95 lines)
! Minimized by compliance.fuzz_min from fuzz seed 61 (fuzz-3).
! toolchain: cce20 (-O2, HSA_XNACK=1, OMP_TARGET_OFFLOAD=mandatory)
! failure: wrong_code
! expected: the host reference checksum (host reference (elision) checksum=234479309)
! observed: device checksum=1451519883 ran_on_host=0
! Legal OpenMP 5.2: offload.engine.prerun.check accepts it (rerun: offload.engine.rules with the
!   race rule and the restriction checks, and the AFAR flang front end, not under test here); no
!   compiler under test, gfortran or gcc is a legality witness.
! also fails on: cce19, cce21
program fuzz_prog
  use omp_lib, only: omp_is_initial_device
  implicit none
  integer, parameter :: n = 200, m = 3
  type :: rec_t
  end type rec_t
  type(rec_t) :: dr
  integer, allocatable :: ia(:)
  integer, allocatable :: ib(:)
  integer, allocatable :: ic(:, :)
  integer :: o1(n)
  integer :: o2(n)
  integer, allocatable :: o3(:)
  integer :: i, j, p1, r3a, hf3
  integer(8) :: cs
  allocate(ia(n))
  allocate(ib(n))
  allocate(ic(n, m))
  allocate(o3(n))
  do i = 1, n
    ia(i) = mod(i * 25 + 45, 97) - 25
  end do
  do i = 1, n
    ib(i) = mod(i * 25 + 39, 211) - 4
  end do
  do j = 1, m
    do i = 1, n
      ic(i, j) = mod((i + 2 * j) * 60 + 25, 101) - 8
    end do
  end do
  o1 = 0
  o2 = 0
  o3 = 0
  p1 = 6
  r3a = 45
  hf3 = 0
  ! fuzz: kernels
  call kp2(ib, o1, o2, o3, dr, p1)
  ! fuzz: checksum
  cs = 0
  do i = 1, n
    cs = modulo(cs * 31_8 + int(o1(i), 8), 2147483629_8)
  end do
  do i = 1, n
    cs = modulo(cs * 31_8 + int(o2(i), 8), 2147483629_8)
  end do
  cs = modulo(cs * 31_8 + int(r3a, 8), 2147483629_8)
  do i = 1, n
    cs = modulo(cs * 31_8 + int(o3(i), 8), 2147483629_8)
  end do
  print '(a,i0,a,i0)', 'RESULT checksum=', cs, ' ran_on_host=', max(hf3, 0)
contains
  subroutine kp1(ia, ic, o1, dr)
    integer, intent(inout) :: ia(n)
    integer, intent(inout) :: ic(n, m)
    integer, intent(inout) :: o1(n)
    type(rec_t), intent(inout) :: dr
  end subroutine kp1
  subroutine kp2(ib, o1, o2, o3, dr, p1)
    integer, intent(inout) :: ib(n)
    integer, intent(inout) :: o1(n)
    integer, intent(inout) :: o2(:)
    integer, intent(inout) :: o3(n)
    type(rec_t), intent(inout) :: dr
    integer, value :: p1
    !$omp taskgroup task_reduction(+: r3a)
      !$omp target map(tofrom: hf3) in_reduction(+: r3a)
        hf3 = merge(1, 0, omp_is_initial_device())
        do i = 1, n
          o3(i) = 9973
        end do
      !$omp end target
    !$omp end taskgroup
  end subroutine kp2
end program fuzz_prog
! spec (requirement): an array that a target region references and no clause names is mapped tofrom, and an in_reduction clause
!   on a target construct maps the reduction list item tofrom with the always modifier, so the writes to the other arrays reach
!   the host.
! "If a variable is not a scalar then it is treated as if it had appeared in a map clause with a map-type of tofrom." (5.2
!   §5.8.1 p.149 l.4-5)
! "If a variable is the base variable of a list item in an in_reduction clause on a target construct then it is treated as if
!   the list item had appeared in a map clause with a map-type of tofrom and a map-type-modifier of always." (5.2 §5.8.1 p.148
!   l.15-17)
! spec (this program): the target region in an internal subroutine, with in_reduction(+: r3a) and map(tofrom: hf3), stores 9973
!   in the dummy array o3; CCE 19, 20 and 21 lose those writes (checksum differs from the host's), and the program is correct when
!   taskgroup, task_reduction and in_reduction are removed.

Source in the repository

Something to add? Dispute its legality · Report it fixed in a newer release · Report a mistake on this page

Expected and observed

Observed where it behaves incorrectly

RESULT checksum=1451519883 ran_on_host=0

What the specification requires

The specification text this program relies on and the compiler is expected to support.

OpenMP 5.2 §5.8.1 p.149 l.4-5

If a variable is not a scalar then it is treated as if it had appeared in a map clause with a map-type of tofrom.

OpenMP 5.2 §5.8.1 p.148 l.15-17

If a variable is the base variable of a list item in an in_reduction clause on a target construct then it is treated as if the list item had appeared in a map clause with a map-type of tofrom and a map-type-modifier of always.

Evidence

Same compiler, one change

  • the taskgroup/task_reduction and the in_reduction clause removed: AFAR 24.3.0: correct; CCE 19.0.0: correct; CCE 20.0.2: correct; CCE 21.0.3: correct; CCE 21.0.4: correct
    Control program
    program fuzz_prog
      use omp_lib, only: omp_is_initial_device
      implicit none
      integer, parameter :: n = 200
      integer, allocatable :: o3(:)
      integer :: i, r3a, hf3
      integer(8) :: cs
      allocate(o3(n))
      o3 = 0
      r3a = 45
      hf3 = 0
      call kp2(o3)
      cs = 0
      cs = modulo(cs * 31_8 + int(r3a, 8), 2147483629_8)
      do i = 1, n
        cs = modulo(cs * 31_8 + int(o3(i), 8), 2147483629_8)
      end do
      print '(a,i0,a,i0)', 'RESULT checksum=', cs, ' ran_on_host=', max(hf3, 0)
    contains
      subroutine kp2(o3)
        integer, intent(inout) :: o3(n)
          !$omp target map(tofrom: hf3)
            hf3 = merge(1, 0, omp_is_initial_device())
            do i = 1, n
              o3(i) = 9973
            end do
          !$omp end target
      end subroutine kp2
    end program fuzz_prog
    

Other compilers run it correctly

AFAR 24.3.0

Reproducers of this issue