Observed issues › fuzz/b2-68-afar
Appears to behave incorrectlyWrong answer · Fortran · OpenMP · Open
amdflang: loop reduction inside parallel if(.false.) in a target region counts the contribution more than once
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 | behaves incorrectly | behaves incorrectly | unknown not run | behaves incorrectly | correct | n/a | n/a |
| CCE 19.0.0 | correct | correct | unknown not run | unknown not run | unknown not run | n/a | n/a |
| CCE 20.0.2 | correct | correct | unknown not run | unknown not run | unknown not run | n/a | n/a |
| CCE 21.0.3 | correct | correct | unknown not run | unknown not run | unknown not run | n/a | n/a |
| CCE 21.0.4 | correct | correct | unknown not run | unknown not run | unknown not run | n/a | n/a |
| NVHPC 25.11 | n/a | n/a | n/a | n/a | n/a | fails another way | fails another way |
| NVHPC 26.9 | n/a | n/a | n/a | n/a | n/a | fails another way | fails another way |
| 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 | AFAR 24.3.0, MI300A unified AFAR 24.3.0, MI300A copy | showRESULT checksum=70431 ran_on_host=0 |
| behaves incorrectly | AFAR 24.3.0, MI300X | showRESULT checksum=52831 ran_on_host=0 |
| fails another way | NVHPC 25.11, A100 separate NVHPC 25.11, A100 managed | showNVFORTRAN-F-1243-GPU target doesn't support 'if' clauses for managing parallel region. (fuzz-b2-68-afar.f90: 13) NVFORTRAN/x86-64 Linux 25.11-0: compilation aborted |
| fails another way | NVHPC 26.9, A100 separate NVHPC 26.9, A100 managed | showNVFORTRAN-F-1243-GPU target doesn't support 'if' clauses for managing parallel region. (fuzz-b2-68-afar.f90: 13) NVFORTRAN/x86-64 Linux 26.9-0: compilation aborted |
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 (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 (50 lines)
! Minimized by compliance.fuzz_min from fuzz seed 68 (fuzz-3).
! toolchain: afar (-O2, HSA_XNACK=1, OMP_TARGET_OFFLOAD=mandatory)
! failure: wrong_code
! expected: the host reference checksum (host reference (cce19) checksum=17631)
! observed: device checksum=70431 ran_on_host=0
! Legal OpenMP 5.2: offload.engine.rules accepts it (offload.engine.prerun.check, rerun: with the
! race rule and the restriction checks); NVHPC is no witness: it rejects it (NVFORTRAN-F-1243-GPU
! target doesn't support 'if' clauses for managing
! parallel region.); the check's other witness, the AFAR flang front end, is the compiler under
! test and is not counted; no gfortran or gcc is a legality witness.
program fuzz_prog
use omp_lib, only: omp_get_default_device, omp_is_initial_device
implicit none
integer, parameter :: n = 200, m = 8
type :: rec_t
end type rec_t
type(rec_t) :: dr
integer :: i, j, r3a, hf3
logical :: lpar
integer(8) :: cs
r3a = 31
hf3 = 0
lpar = .false.
! fuzz: kernels
!$omp target map(tofrom: hf3) map(tofrom: r3a)
hf3 = merge(1, 0, omp_is_initial_device())
!$omp parallel if(parallel: lpar)
!$omp loop reduction(+: r3a)
do i = 1, n
do j = m, 1, -1
r3a = r3a + 11
end do
end do
!$omp end loop
!$omp end parallel
!$omp end target
! fuzz: checksum
cs = 0
cs = modulo(cs * 31_8 + int(r3a, 8), 2147483629_8)
print '(a,i0,a,i0)', 'RESULT checksum=', cs, ' ran_on_host=', max(hf3, 0)
end program fuzz_prog
! spec (requirement): a parallel region whose if clause evaluates to false is executed by a team of one thread, and a reduction
! on the loop construct bound to it combines the threads' private copies with the original value once.
! "if (IfClauseValue = false) then number of threads = 1;" (5.2 §10.1.1 p.226 l.27-28)
! "At the end of a region that corresponds to a construct for which the reduction clause was specified, the original list item
! is updated by combining its original value with the final value of each of the private copies, using the combiner of the
! specified reduction-identifier." (5.2 §5.5.8 p.135 l.7-10)
! spec (this program): parallel if(parallel: lpar) with lpar false (one thread) around loop reduction(+: r3a) in a target region
! adds each of the 1600 contributions once (r3a = 31 + 1600 * 11); AFAR counts the contributions four times (checksum 70431
! instead of 17631), and is correct with lpar true.
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=70431 ran_on_host=0
What the specification requires
The specification text this program relies on and the compiler is expected to support.
OpenMP 5.2 §10.1.1 p.226 l.27-28
if (IfClauseValue = false) then number of threads = 1;
OpenMP 5.2 §5.5.8 p.135 l.7-10
At the end of a region that corresponds to a construct for which the reduction clause was specified, the original list item is updated by combining its original value with the final value of each of the private copies, using the combiner of the specified reduction-identifier.
Evidence
Same compiler, one change
- lpar = .true. (the parallel region is active): 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 fuzz_prog use omp_lib, only: omp_is_initial_device implicit none integer, parameter :: n = 200, m = 8 integer :: i, j, r3a, hf3 logical :: lpar integer(8) :: cs r3a = 31 hf3 = 0 lpar = .true. !$omp target map(tofrom: hf3) map(tofrom: r3a) hf3 = merge(1, 0, omp_is_initial_device()) !$omp parallel if(parallel: lpar) !$omp loop reduction(+: r3a) do i = 1, n do j = m, 1, -1 r3a = r3a + 11 end do end do !$omp end loop !$omp end parallel !$omp end target cs = 0 cs = modulo(cs * 31_8 + int(r3a, 8), 2147483629_8) print '(a,i0,a,i0)', 'RESULT checksum=', cs, ' ran_on_host=', max(hf3, 0) end program fuzz_prog
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