OffTarget

Observed issues › fuzz/b2-209-cce19

Appears to behave incorrectlyWrong answer · Fortran · OpenMP · Open

ftn: lastprivate(conditional:) on target simd does not imply map(tofrom), value lost

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.0fails another wayfails another wayunknown
not run
fails another wayfails another wayn/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.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 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=0
fails another wayAFAR 24.3.0, MI300A unified
AFAR 24.3.0, MI300A copy
AFAR 24.3.0, MI300X
AFAR 24.3.0, MI350X
show
error: loc("fuzz-b2-209-cce19.f90":7:9): /__w/TheRock/TheRock/compiler/amd-llvm/flang/lib/Lower/OpenMP/OpenMP.cpp:5232: not yet implemented: lastprivate(conditional:) on simd construct
LLVM ERROR: aborting
fails another wayNVHPC 25.11, A100 separate
NVHPC 25.11, A100 managed
NVHPC 26.9, A100 separate
NVHPC 26.9, A100 managed
show
NVFORTRAN-S-0034-Syntax error at or near : (fuzz-b2-209-cce19.f90: 7)
  0 inform,   0 warnings,   1 severes, 0 fatal for fuzz_prog

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

GCC 16.2.0, MI300A unified (runs correctly)

export LD_LIBRARY_PATH=$GCC_16_2/lib64:/opt/rocm-7.2.1/lib
$GCC_16_2/bin/gfortran -fopenmp -foffload=amdgcn-amdhsa -foffload-options=amdgcn-amdhsa=-march=gfx942 -O2 repro.f90 -o repro
HSA_XNACK=1 OMP_TARGET_OFFLOAD=mandatory ./repro
Program (47 lines)
! Minimized by compliance.fuzz_min from fuzz seed 209 (fuzz-3).
! toolchain: cce19 (-O2, HSA_XNACK=1, OMP_TARGET_OFFLOAD=mandatory)
! failure: wrong_code
! expected: the host reference checksum (host reference (elision) checksum=16)
! observed: device checksum=0 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: cce20, cce21
module fuzz_mod
  implicit none
contains
end module fuzz_mod
program fuzz_prog
  implicit none
  integer, parameter :: n = 16, m = 3
  type :: rec_t
  end type rec_t
  type :: el_t
  end type el_t
  type(rec_t) :: dr
  type(el_t) :: ds(n)
  integer :: i, j, jj, lp1, acc1
  integer(8) :: cs
  lp1 = 0
  ! fuzz: kernels
  !$omp target simd lastprivate(conditional: lp1) private(acc1, jj)
  do i = 1, n
    acc1 = 0
    if (mod(i, 2) == 0) lp1 = i
  end do
  ! fuzz: checksum
  cs = 0
  cs = modulo(cs * 31_8 + int(lp1, 8), 2147483629_8)
  print '(a,i0,a,i0)', 'RESULT checksum=', cs, ' ran_on_host=', 0
end program fuzz_prog
! spec (requirement): on a combined construct that includes target, a list item of a lastprivate clause is mapped as if with
!   map-type tofrom, and with the conditional modifier the original list item receives the value that sequential execution of the
!   loop would leave.
! "If the target construct is among the constituent constructs and the list item is not the base variable or base pointer of a
!   list item that appears in a map clause, the effect of the lastprivate clause is as if the same list item appears in a map
!   clause with a map-type of tofrom." (5.2 §17.2 p.340 l.27-30)
! "When the conditional modifier appears on the clause or the list item is an iteration variable of one of the associated loops,
!   if sequential execution of the loop nest would assign a value to the list item then the original list item is assigned the
!   value that the list item would have after sequential execution of the loop nest." (5.2 §5.4.5 p.115 l.16-19)
! spec (this program): target simd lastprivate(conditional: lp1) implies map(tofrom: lp1), so the host must see lp1 = 16 after
!   the loop; CCE 19, 20 and 21 return 0, and the program is correct when lp1 is also mapped explicitly with map(tofrom: lp1).

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 §17.2 p.340 l.27-30

If the target construct is among the constituent constructs and the list item is not the base variable or base pointer of a list item that appears in a map clause, the effect of the lastprivate clause is as if the same list item appears in a map clause with a map-type of tofrom.

OpenMP 5.2 §5.4.5 p.115 l.16-19

When the conditional modifier appears on the clause or the list item is an iteration variable of one of the associated loops, if sequential execution of the loop nest would assign a value to the list item then the original list item is assigned the value that the list item would have after sequential execution of the loop nest.

Evidence

Same compiler, one change

  • lp1 also mapped explicitly: map(tofrom: lp1): AFAR 24.3.0: fails another way; 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 = 16
      integer :: i, jj, lp1, acc1
      integer(8) :: cs
      lp1 = 0
      !$omp target simd lastprivate(conditional: lp1) private(acc1, jj) map(tofrom: lp1)
      do i = 1, n
        acc1 = 0
        if (mod(i, 2) == 0) lp1 = i
      end do
      cs = 0
      cs = modulo(cs * 31_8 + int(lp1, 8), 2147483629_8)
      print '(a,i0)', 'RESULT checksum=', cs
    end program fuzz_prog
    

Other compilers run it correctly

GCC 16.2.0