OffTarget

Observed issues › afar-cce19-character-defaultmap

Appears to behave incorrectlyWrong answer · Fortran · OpenMP · Open

A Fortran character scalar referenced in a target region is treated as a firstprivate scalar (writes lost)

Legality: independently confirmed. One independent reading was uncertain; 1 adjudicating readings that weighed both find the program legal and the result required: For Fortran, character type is excluded from scalar and is an aggregate variable. ch and s are therefore not scalars and are implicitly mapped tofrom, so the target-region assignments reach the host (ch=b, s=wxyz). k is an integer scalar without TARGET/ALLOCATABLE/POINTER, so it is firstprivate and stays 1. 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.0behaves incorrectlybehaves incorrectlybehaves incorrectlyunknown
not run
unknown
not run
n/an/a
CCE 20.0.2behaves incorrectlybehaves incorrectlybehaves incorrectlyunknown
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/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, MI250X
AFAR 24.3.0, MI300X
AFAR 24.3.0, MI350X
CCE 19.0.0, MI300A unified
CCE 19.0.0, MI300A copy
CCE 19.0.0, MI250X
CCE 20.0.2, MI300A unified
CCE 20.0.2, MI300A copy
CCE 20.0.2, MI250X
show
ch=a s=abcd k=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

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

NVHPC 25.11, A100 separate (runs correctly)

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
Program (22 lines)
program p
  implicit none
  character :: ch
  character(len=4) :: s
  integer :: k
  ch = 'a'; s = 'abcd'; k = 1
  !$omp target
  ch = 'b'; s = 'wxyz'; k = 2
  !$omp end target
  print '(a,a,a,a,a,i0)', 'ch=', ch, ' s=', s, ' k=', k
end program
! spec (requirement): In Fortran a character variable is not a scalar variable for OpenMP: the scalar variable
!   definition excludes the character type.
! "For Fortran, a scalar variable with intrinsic type, as defined by the base language, excluding character type."
!   (5.2 §1.2.6 p.14 l.7-8)
! spec (requirement): A variable referenced in a target construct that is not a scalar is implicitly mapped with
!   map-type tofrom, so a character variable is mapped and its modification is visible after the region.
! "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): ch and s are character variables referenced in the target region with no map or defaultmap
!   clause, so both are implicitly mapped tofrom and come back as b and wxyz; amdflang treats them as firstprivate
!   scalars and the writes are lost (k, an integer scalar, is firstprivate and keeps its value).

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

ch=b s=wxyz k=1

Observed where it behaves incorrectly

ch=a s=abcd k=1

What the specification requires

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

OpenMP 5.2 §1.2.6 p.14 l.7-8

For Fortran, a scalar variable with intrinsic type, as defined by the base language, excluding character type.

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

  • ch and s mapped explicitly: map(tofrom: ch, 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 p
      implicit none
      character :: ch
      character(len=4) :: s
      integer :: k
      ch = 'a'; s = 'abcd'; k = 1
      !$omp target map(tofrom: ch, s)
      ch = 'b'; s = 'wxyz'; k = 2
      !$omp end target
      print '(a,a,a,a,a,i0)', 'ch=', ch, ' s=', s, ' k=', k
    end program
    

Other compilers run it correctly

NVHPC 25.11, NVHPC 26.9, GCC 16.2.0