OffTarget

Observed issues › stress/afar-target-scalar-implicit-firstprivate

Appears to behave incorrectlyWrong answer · Fortran · OpenMP · Open

Scalar with the TARGET attribute is treated as firstprivate in a target region (device write 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.0behaves incorrectlybehaves incorrectlybehaves incorrectlybehaves incorrectlybehaves incorrectlyn/an/a
CCE 19.0.0correctcorrectcorrectunknown
not run
unknown
not run
n/an/a
CCE 20.0.2correctcorrectcorrectunknown
not run
unknown
not run
n/an/a
CCE 21.0.3correctcorrectcorrectunknown
not run
unknown
not run
n/an/a
CCE 21.0.4correctcorrectcorrectunknown
not run
unknown
not run
n/an/a
NVHPC 25.11n/an/an/an/an/abehaves incorrectlybehaves incorrectly
NVHPC 26.9n/an/an/an/an/abehaves incorrectlybehaves incorrectly
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, MI250X
AFAR 24.3.0, MI300X
AFAR 24.3.0, MI350X
NVHPC 25.11, A100 separate
NVHPC 25.11, A100 managed
NVHPC 26.9, A100 separate
NVHPC 26.9, A100 managed
show
rd= 101 s= 101 dev= 1

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

NVHPC 25.11, A100 separate

export LD_LIBRARY_PATH=$NVHPC_25_11/compilers/lib
nvfortran -mp=gpu -gpu=cc80 -gpu=mem:separate -O2 repro.f90 -o repro
OMP_TARGET_OFFLOAD=mandatory ./repro

NVHPC 26.9, A100 separate

export LD_LIBRARY_PATH=$NVHPC_26_9/compilers/lib
nvfortran -mp=gpu -gpu=cc80 -gpu=mem:separate -O2 repro.f90 -o repro
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 (41 lines)
! # Draft finding: data/reports/fuzz-stress-audit/r1-target-scalar.f90 on afar
!
! - compiler: afar
! - toolchain: afar; arch: gfx942; machine: tuolumne; memory mode: copy; opt: -O2
! - program: file data/reports/fuzz-stress-audit/r1-target-scalar.f90 (f90, version 52, sha256 b1d59bfc76fdc1b7)
! - expected: rd= 101 s= 203 dev= 1 (trusted; metamorphic + model)
! - actual: wrong_answer rd= 101 s= 101 dev= 1 (expected rd= 101 s= 203 dev= 1)
! - verdict: compiler_bug by rule R20-runtime-bug: a legal program fails at run time, deterministically, against an expected value
!   from two or more independent sources with an executed witness, and another toolchain, mode, arch or the elision gives the
!   expected value
! - reason: expected trusted rd= 101 s= 203 dev= 1 (metamorphic + model): metamorphic + model agree; witnesses: cce19/gfx942/copy,
!   cce20/gfx942/copy, cce21/gfx942/copy
! - citations: RUL-DERIVED-NEEDS-EXECUTION (rulings.md); RUL-WITNESS-PER-MODE (rulings.md);
!   RUL-SAME-COMPILER-RUNS (rulings.md); RUL-PRESENCE-WITNESS (rulings.md); RUL-METAMORPHIC-OTHER-FAMILY
!   (rulings.md)
! - legality: legal: read against the spec (audit and a later check); checked by scope, offload.engine.rules (no checker of the
!   family under test)
! - witnesses: cce19/gfx942/copy, cce20/gfx942/copy, cce21/gfx942/copy
! - withdrawn: none
!
! Audit, candidate 1: a scalar with the TARGET attribute referenced
! in a target region is implicitly map(tofrom) (OpenMP 5.0 §2.19.7 p.315,
! 5.2 §5.8.1 p.149, 6.0 §7.9.3 p.277: "If a scalar variable has the TARGET,
! ALLOCATABLE or POINTER attribute then it is treated as if it had appeared
! in a map clause with a map-type of tofrom"). Expected: rd= 101 s= 203 dev= 1
program target_scalar_tofrom
  use omp_lib
  implicit none
  integer(8), target :: s
  integer(8) :: rd
  integer :: dev
  s = 101
  rd = -1
  dev = -1
  !$omp target map(tofrom: rd, dev)
    rd = s
    s = 2 * s + 1
    dev = merge(0, 1, omp_is_initial_device())
  !$omp end target
  print '(a,i0,a,i0,a,i0)', 'rd= ', rd, ' s= ', s, ' dev= ', dev
end program target_scalar_tofrom

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

Expected

rd= 101 s= 203 dev= 1

Observed where it behaves incorrectly

rd= 101 s= 101 dev= 1

What the specification requires

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

OpenMP 5.0 §2.19.7 p.315

OpenMP 5.2 §5.8.1 p.149

OpenMP 6.0 §7.9.3 p.277

If a scalar variable has the TARGET, ALLOCATABLE or POINTER attribute then it is treated as if it had appeared in a map clause with a map-type of tofrom

Evidence

Same compiler, one change

  • s mapped explicitly: map(tofrom: rd, dev, s): 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 target_scalar_tofrom
      use omp_lib
      implicit none
      integer(8), target :: s
      integer(8) :: rd
      integer :: dev
      s = 101
      rd = -1
      dev = -1
      !$omp target map(tofrom: rd, dev, s)
        rd = s
        s = 2 * s + 1
        dev = merge(0, 1, omp_is_initial_device())
      !$omp end target
      print '(a,i0,a,i0,a,i0)', 'rd= ', rd, ' s= ', s, ' dev= ', dev
    end program target_scalar_tofrom
    

Other compilers run it correctly

CCE 19.0.0, CCE 20.0.2, CCE 21.0.3, CCE 21.0.4, GCC 16.2.0