OffTarget

Observed issues › oop/cce-copy-parent-to-component-tofrom-lost

Appears to behave incorrectlyWrong answer · Fortran · OpenMP · Open

map(to: x) with map(tofrom: x%a) loses the component's copy back

Legality: independently confirmed. One independent reading was uncertain; 2 adjudicating readings that weighed both find the program legal and the result required: The restriction allows two list items sharing original storage when one is the containing structure of the other, so map(to: x) with map(tofrom: x%a) is legal. x%a is an explicit list item, so the default-mapper treatment of allocatable components does not apply to it, and its tofrom map type copies the updated data back at exit. The loop writes distinct elements, so there is no race. How this is checked

With map(to: x) map(tofrom: x%a) on one target construct (x a structure with an allocatable array component a), the device's writes to x%a do not come back to the host with CCE 19, 20 and 21 when memory is separate. Mapping x%a alone works. AFAR and GCC are correct.

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.0correctbehaves incorrectlyunknown
not run
unknown
not run
unknown
not run
n/an/a
CCE 20.0.2correctbehaves incorrectlyunknown
not run
unknown
not run
unknown
not run
n/an/a
CCE 21.0.3correctbehaves incorrectlyunknown
not run
unknown
not run
unknown
not run
n/an/a
CCE 21.0.4correctbehaves incorrectlyunknown
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 incorrectlyCCE 19.0.0, MI300A copy
CCE 20.0.2, MI300A copy
CCE 21.0.3, MI300A copy
CCE 21.0.4, MI300A copy
show
r1= 2080
RESULT ran_on_host=0 check=fail

Reproduce

CCE 19.0.0, MI300A copy

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=0 OMP_TARGET_OFFLOAD=mandatory ./repro

CCE 20.0.2, MI300A copy

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=0 OMP_TARGET_OFFLOAD=mandatory ./repro

CCE 21.0.3, MI300A copy

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=0 OMP_TARGET_OFFLOAD=mandatory ./repro

CCE 21.0.4, MI300A copy

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=0 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 (58 lines)
! # Finding (fortran-oop): map(to: x) map(tofrom: x%a): the allocatable component is not copied back (copy mode)
!
! - toolchains and modes that fail: cce19 (CCE 19.0.0: copy), cce20 (CCE 20.0.2: copy), cce21 (CCE 21.0.3: copy), cce21_4 (CCE
!   21.0.4: copy); -O2
! - build: ftn -fopenmp -O2 (module load cce/<v> craype-accel-amd-gfx942 rocm/<r>; OpenACC: ftn -h acc)
! - failure: wrong_answer (check=fail); OMP_TARGET_OFFLOAD=mandatory
! - observed: `r1= 2080` (the host values) at HSA_XNACK=0 on every CCE release; HSA_XNACK=1 correct
! - expected: `r1= 2528`
! - rule: 5.2 §5.8.3 p.156 l.6-7 (a structure and its element may both be list items); the component is mapped tofrom, so it is
!   copied back on exit (§5.8.3 p.154 exit step 1a)
! - same-compiler control: the same program without map(to: x) (controls/parent-and-comp-component-only.f90, one change): correct
!   (check=pass) on CCE 19, 20, 21.0.3 and 21.0.4 in both modes, in the stored run and the gate's four environments a-d with (c)
!   on another node (results/oop/probe/ctl2.*.parent-and-comp-component-only.*.jsonl)
! - other families: AFAR and GCC 16.2 correct
! - gate and confirmer: 4 cells, 4 confirmed in the gate's four environments (a-d; results/oop/main/gate_reruns*.jsonl); confirmer
!   (results/oop/main/confirm.jsonl): needs_human (R22-expected-weak) 4; R22-expected-weak means the expected value has one
!   source, the generator's Python model; the values follow from the program's arithmetic (checked by hand), and AFAR, GCC 16.2
!   (gfx90a), GCC 16.2 (sm_80), NVHPC 25.11, NVHPC 26.9 print them on this program
! - programs (1): oop-alloccomp-parent-and-comp (offload/engine/oop_gen.py; this file is the first one)
! - legality: for the cce cells: the rules (offload.engine.rules, with the fortran-oop restrictions) and AFAR's flang front end
!   (-fsyntax-only) and NVHPC 26.9 nvfortran (compile only) (tools/campaigns/oop.py legality, results/oop/main/legality.json)
module oop_m
  implicit none
  integer, parameter :: n = 64
  type vec
    integer :: n = 0
    integer, allocatable :: a(:)
  end type vec
end module oop_m

program oop
  use omp_lib
  use oop_m
  implicit none
  integer :: host_flag
  logical :: ok
  integer :: r1
  type(vec) :: x
  integer :: i
  host_flag = 1
  !$omp target map(from: host_flag)
  host_flag = merge(1, 0, omp_is_initial_device())
  !$omp end target
  allocate(x%a(n))
  x%n = n
  do i = 1, n
    x%a(i) = i
  end do
  !$omp target teams distribute parallel do map(to: x) map(tofrom: x%a)
  do i = 1, n
    x%a(i) = x%a(i) + 7
  end do
  r1 = sum(x%a)
  ok = .true.
  ok = ok .and. (r1 == 2528)
  print '(a,i0)', 'r1= ', r1
  print '(a,i0,a,a)', 'RESULT ran_on_host=', host_flag, ' check=', merge('pass', 'fail', ok)
end program oop

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

r1= 2528

Observed where it behaves incorrectly

r1= 2080
RESULT ran_on_host=0 check=fail

What the specification requires

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

OpenMP 5.2 §5.8.3 p.156 l.6-7

OpenMP 5.2 §5.8.3 p.154

Evidence

Same compiler, one change

  • the same program without map(to: x): not run yet
    Control program
    ! control for oop-alloccomp-parent-and-comp: the same program; one change: no map(to: x) beside map(tofrom: x%a)
    ! fortran-oop alloccomp/parent-and-comp (OpenMP 5.2, free-form Fortran):
    ! map(to:) of the structure and map(tofrom:) of its allocatable component on one construct
    ! spec: OpenMP 5.2 §5.8.3 p.151-155 (map clause); OpenMP 5.2 §5.8.3 p.151 l.29-37 (components from the
    !   predefined default mapper); OpenMP 6.0 §B.5 p.909 l.35-37 (5.0: mapping of allocatable and
    !   pointer components); OpenMP 5.2 §5.8.3 p.156 l.6-7
    ! legality: defined
    ! expected (computed by compliance/oop_gen.py): r1= 2528
    module oop_m
      implicit none
      integer, parameter :: n = 64
      type vec
        integer :: n = 0
        integer, allocatable :: a(:)
      end type vec
    end module oop_m
    
    program oop
      use omp_lib
      use oop_m
      implicit none
      integer :: host_flag
      logical :: ok
      integer :: r1
      type(vec) :: x
      integer :: i
      host_flag = 1
      !$omp target map(from: host_flag)
      host_flag = merge(1, 0, omp_is_initial_device())
      !$omp end target
      allocate(x%a(n))
      x%n = n
      do i = 1, n
        x%a(i) = i
      end do
      !$omp target teams distribute parallel do map(tofrom: x%a)
      do i = 1, n
        x%a(i) = x%a(i) + 7
      end do
      r1 = sum(x%a)
      ok = .true.
      ok = ok .and. (r1 == 2528)
      print '(a,i0)', 'r1= ', r1
      print '(a,i0,a,a)', 'RESULT ran_on_host=', host_flag, ' check=', merge('pass', 'fail', ok)
    end program oop
    

Other compilers run it correctly

AFAR 24.3.0, NVHPC 25.11, NVHPC 26.9, GCC 16.2.0