Observed issues › catalog/cce-acc-loop-seq-in-routine-wrong
Appears to behave incorrectlyWrong answer · Fortran · OpenACC · Open
ftn -h acc: a loop seq construct inside a routine seq procedure gives wrong sums
Legality: independently confirmed. 2 independent readings find the program legal and the result required. How this is checked
Affected variants
| Compiler | MI300A 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.0 | n/a | n/a | n/a | n/a | n/a | n/a | n/a |
| CCE 19.0.0 | behaves incorrectly | behaves incorrectly | behaves incorrectly | unknown not run | unknown not run | n/a | n/a |
| CCE 20.0.2 | behaves incorrectly | behaves incorrectly | behaves incorrectly | unknown not run | unknown not run | n/a | n/a |
| CCE 21.0.3 | behaves incorrectly | behaves incorrectly | behaves incorrectly | unknown not run | unknown not run | n/a | n/a |
| CCE 21.0.4 | behaves incorrectly | behaves incorrectly | behaves incorrectly | unknown not run | unknown not run | n/a | n/a |
| NVHPC 25.11 | n/a | n/a | n/a | n/a | n/a | correct | correct |
| NVHPC 26.9 | n/a | n/a | n/a | n/a | n/a | correct | correct |
| GCC 16.2.0 | correct | correct | correct | correct | correct | correct | n/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
| Result | Compiler and GPU | Message |
|---|---|---|
| behaves incorrectly | 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 CCE 21.0.3, MI300A unified CCE 21.0.3, MI300A copy CCE 21.0.3, MI250X CCE 21.0.4, MI300A unified CCE 21.0.4, MI300A copy CCE 21.0.4, MI250X | showRESULT ran_on_host=0 check=fail |
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 -h acc -O2 repro.f90 -o repro HSA_XNACK=1 ./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 -h acc -O2 repro.f90 -o repro HSA_XNACK=1 ./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 -h acc -O2 repro.f90 -o repro HSA_XNACK=1 ./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 -h acc -O2 repro.f90 -o repro HSA_XNACK=1 ./repro
NVHPC 25.11, A100 separate (runs correctly)
export LD_LIBRARY_PATH=$NVHPC_25_11/compilers/lib nvfortran -acc=gpu -gpu=cc80 -gpu=mem:separate -O2 repro.f90 -o repro ./repro
Program (77 lines)
! # Draft finding: acc34-w-loop-in-routine on cce19
!
! - compiler: cce19
! - toolchain: cce19; arch: gfx942; machine: tuolumne; memory mode: unified; opt: -O2
! - program: catalog acc34-w-loop-in-routine (f90, version 34, sha256 1499c90f659f38cf)
! - expected: check=pass (trusted; elision + model)
! - actual: wrong_answer check=fail (check_fail: ran_on_host=0 check=fail)
! - 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 check=pass (elision + model): stored main verdict: elision + model agree; witnesses: elision
! - 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: 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
! - witnesses: elision
! - withdrawn: none
!
! Generated by compliance.widen (OpenACC 3.4, free-form Fortran; catalog widening). Do not edit.
! id: acc34-w-loop-in-routine
! primary atom: base.device.loop_in_routine
! atoms: base.device.loop_in_routine
! legal: yes
! observable: yes
! ran_on_host: inside the compute region of interest (acc_on_device)
! evidence: construct
! needs: none
! std: f2008
! feature: a loop seq construct inside a routine seq procedure called in a parallel loop
! spec: OpenACC 3.4 §2.9 (loop construct) and §2.15.1 (routine seq: a loop construct in it must be seq)
module wmod
implicit none
contains
subroutine rowsum(x, s)
!$acc routine seq
integer, intent(in) :: x(:)
integer, intent(out) :: s
integer :: k
s = 0
!$acc loop seq
do k = 1, size(x)
s = s + x(k)
end do
end subroutine rowsum
end module wmod
program wide_prog
use openacc, only: acc_device_host, acc_on_device
use wmod
implicit none
integer, parameter :: n = 64
integer :: a(n), b(n), ref(n)
integer :: a2(4, n)
integer :: k
integer :: i, host_flag
logical :: ok
do i = 1, n
a(i) = i
b(i) = 0
ref(i) = 10*i
end do
do i = 1, n
do k = 1, 4
a2(k, i) = k*i
end do
end do
host_flag = 1
!$acc parallel loop copyin(a2) copyout(b) copy(host_flag)
do i = 1, n
call rowsum(a2(:, i), b(i))
if (i == 1) host_flag = merge(1, 0, acc_on_device(acc_device_host))
end do
ok = all(b == ref)
print '(a,i0,a,a)', 'RESULT ran_on_host=', host_flag, ' check=', merge('pass', 'fail', ok)
end program wide_prog
Something to add? Dispute its legality · Report it fixed in a newer release · Report a mistake on this page
Expected and observed
Expected
check=pass
Observed where it behaves incorrectly
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.
OpenACC 3.4 §2.9
OpenACC 3.4 §2.15.1
Evidence
Same compiler, one change
- the loop seq directive removed: CCE 19.0.0: correct; CCE 20.0.2: correct; CCE 21.0.3: correct; CCE 21.0.4: correct
Control program
module wmod implicit none contains subroutine rowsum(x, s) !$acc routine seq integer, intent(in) :: x(:) integer, intent(out) :: s integer :: k s = 0 do k = 1, size(x) s = s + x(k) end do end subroutine rowsum end module wmod program wide_prog use openacc, only: acc_device_host, acc_on_device use wmod implicit none integer, parameter :: n = 64 integer :: a(n), b(n), ref(n) integer :: a2(4, n) integer :: k integer :: i, host_flag logical :: ok do i = 1, n a(i) = i b(i) = 0 ref(i) = 10*i end do do i = 1, n do k = 1, 4 a2(k, i) = k*i end do end do host_flag = 1 !$acc parallel loop copyin(a2) copyout(b) copy(host_flag) do i = 1, n call rowsum(a2(:, i), b(i)) if (i == 1) host_flag = merge(1, 0, acc_on_device(acc_device_host)) end do ok = all(b == ref) print '(a,i0,a,a)', 'RESULT ran_on_host=', host_flag, ' check=', merge('pass', 'fail', ok) end program wide_prog
Other compilers run it correctly
NVHPC 25.11, NVHPC 26.9, GCC 16.2.0