OffTarget

Observed issues › fuzz/650-afar

Appears to behave incorrectlyWrong answer · Fortran · OpenMP · Open

amdflang: a parallel region with firstprivate nested in a distribute loop loses the writes of its worksharing loop

Legality: independently confirmed. 2 independent readings find the program legal and the result required. 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.0behaves incorrectlybehaves incorrectlyunknown
not run
behaves incorrectlybehaves incorrectlyn/an/a
CCE 19.0.0correctcorrectunknown
not run
unknown
not run
unknown
not run
n/an/a
CCE 20.0.2correctcorrectunknown
not run
unknown
not run
unknown
not run
n/an/a
CCE 21.0.3correctcorrectunknown
not run
unknown
not run
unknown
not run
n/an/a
CCE 21.0.4correctcorrectunknown
not run
unknown
not run
unknown
not run
n/an/a
NVHPC 25.11n/an/an/an/an/acorrectcorrect
NVHPC 26.9n/an/an/an/an/acorrectcorrect
GCC 16.2.0correctcorrectcorrectcorrectcorrectcorrectn/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 incorrectlyAFAR 24.3.0, MI300A unified
AFAR 24.3.0, MI300A copy
AFAR 24.3.0, MI300X
AFAR 24.3.0, MI350X
show
RESULT checksum=0

Reproduce

AFAR 24.3.0, MI300A unified

$AFAR/bin/amdflang -fopenmp --offload-arch=gfx942 -O2 repro.f90 -o repro
HSA_XNACK=1 OMP_TARGET_OFFLOAD=mandatory ./repro

CCE 19.0.0, MI300A unified (runs correctly)

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
Program (54 lines)
! Minimized by compliance.fuzz_min from fuzz seed 650 (fuzz-1).
! toolchain: afar (-O2, HSA_XNACK=1, OMP_TARGET_OFFLOAD=mandatory)
! failure: wrong_code
! expected: the host reference checksum (host reference (afar/cce19) checksum=649664593)
! observed: device checksum=0 ran_on_host=0
! also observed (reductions of this family, data/reports/fuzz5-oop-afar.md, cluster B): at HSA_XNACK=0 an
!   explicit-shape array written in the nested parallel region, and an implicitly mapped allocatable, fault
!   (GPU memory access fault) instead of giving a wrong value; the same program without firstprivate(i) is correct.
! Legal OpenMP 5.2: offload.engine.rules accepts it (offload.engine.prerun.check, rerun: with the
!   race rule and the restriction checks); nvfortran/nvc 26.9 and 25.11 (NVHPC, not under test
!   here) compile it; the check's other witness, the AFAR flang front end, is the compiler under
!   test and is not counted; no gfortran or gcc is a legality witness.
program fuzz_prog
  use omp_lib, only: omp_is_initial_device
  implicit none
  integer, parameter :: n = 100, m = 3
  integer, allocatable :: o1(:, :)
  integer :: i, j
  logical :: lt
  integer(8) :: cs
  allocate(o1(n, m))
  o1 = 0
  lt = .true.
  ! fuzz: kernels
  !$omp target teams distribute
  do i = 1, n
    !$omp parallel firstprivate(i)
      !$omp do
      do j = 1, m
        o1(i, j) = i
      end do
      !$omp end do
    !$omp end parallel
  end do
  ! fuzz: checksum
  cs = 0
  do j = 1, m
    do i = 1, n
      cs = modulo(cs * 31_8 + int(o1(i, j), 8), 2147483629_8)
    end do
  end do
  print '(a,i0,a,i0)', 'RESULT checksum=', cs, ' ran_on_host=', 0
end program fuzz_prog
! spec (requirement): a firstprivate clause gives the construct a private, initialized copy of the named list item only, and an
!   array that a target region references and no clause names is mapped tofrom, so the writes of the worksharing loop in the
!   parallel region reach the shared array.
! "In addition, the new list item is initialized from the original list item that exists before the construct. The
!   initialization of the new list item is done once for each task that references the list item in any statement in the
!   construct. The initialization is done prior to the execution of the construct." (5.2 §5.4.4 p.112 l.11-14)
! "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)
! spec (this program): parallel firstprivate(i) with a worksharing do loop that stores o1(i, j) = i, nested in the distribute
!   loop of a target teams construct, must leave o1 filled; AFAR loses the writes (checksum 0, or a memory fault at HSA_XNACK=0),
!   while the same program without firstprivate(i) is correct.

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=0

What the specification requires

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

OpenMP 5.2 §5.4.4 p.112 l.11-14

In addition, the new list item is initialized from the original list item that exists before the construct. The initialization of the new list item is done once for each task that references the list item in any statement in the construct. The initialization is done prior to the execution of the construct.

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.

Evidence

Same compiler, one change

  • firstprivate(i) removed from the parallel construct: 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
      implicit none
      integer, parameter :: n = 100, m = 3
      integer, allocatable :: o1(:, :)
      integer :: i, j
      integer(8) :: cs
      allocate(o1(n, m))
      o1 = 0
      !$omp target teams distribute
      do i = 1, n
        !$omp parallel
          !$omp do
          do j = 1, m
            o1(i, j) = i
          end do
          !$omp end do
        !$omp end parallel
      end do
      cs = 0
      do j = 1, m
        do i = 1, n
          cs = modulo(cs * 31_8 + int(o1(i, j), 8), 2147483629_8)
        end do
      end do
      print '(a,i0)', 'RESULT checksum=', cs
    end program fuzz_prog
    

Other compilers run it correctly

CCE 19.0.0, CCE 20.0.2, CCE 21.0.3, CCE 21.0.4, NVHPC 25.11, NVHPC 26.9, GCC 16.2.0

Reproducers of this issue