OffTarget

Observed issues › fresh/nvhpc-acc-gang-worker-collapse-nested-vector-reduction-lost

Appears to behave incorrectlyWrong answer · Fortran · OpenACC · Open

nvfortran -acc: gang worker collapse(2) reduction with a nested vector reduction loses whole inner loops

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.0n/an/an/an/an/an/an/a
CCE 19.0.0correctunknown
varies between runs
unknown
not run
unknown
not run
unknown
not run
n/an/a
CCE 20.0.2correctcorrectunknown
not run
unknown
not run
unknown
not run
n/an/a
CCE 21.0.3correctcorrectunknown
not run
unknown
not run
unknown
not run
n/an/a
CCE 21.0.4correctcorrectunknown
not run
unknown
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.0correctcorrectcorrectfails another wayfails another wayfails another wayn/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 incorrectlyNVHPC 25.11, A100 separate
show
 fail    9988000.000000000       expected    10000000.00000000     
behaves incorrectlyNVHPC 25.11, A100 managed
show
 fail    9979000.000000000       expected    10000000.00000000     
behaves incorrectlyNVHPC 26.9, A100 separate
show
 fail    9989000.000000000       expected    10000000.00000000     
behaves incorrectlyNVHPC 26.9, A100 managed
show
 fail    9994000.000000000       expected    10000000.00000000     
fails another wayGCC 16.2.0, MI300X
GCC 16.2.0, MI350X
GCC 16.2.0, A100 separate
show
timeout: the monitored command dumped core

Reproduce

NVHPC 25.11, A100 separate

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

NVHPC 26.9, A100 separate

export LD_LIBRARY_PATH=$NVHPC_26_9/compilers/lib
nvfortran -acc=gpu -gpu=cc80 -gpu=mem:separate -O2 repro.f90 -o repro
./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 -h acc -O2 repro.f90 -o repro
HSA_XNACK=1 ./repro
Program (60 lines)
! # Finding (from the data/bench/fresh draft fresh-076): NVHPC loses contributions of a gang
!   worker collapse(2) reduction with a nested vector reduction
!
! - source: data/bench/fresh/fresh-076.f90 (NVIDIA developer forum topic 354721, the full program of the
!   2025-12-16 reply). The reporter's program has no data clause for sumA on the parallel
!   construct, which OpenACC 3.4 §2.6.2 p.42 l.1403-1409 forbids for a scalar in a loop reduction
!   whose access is exposed to a parent parallel construct; this reproducer adds copy(sumA) and sets
!   A = 1 so the sum is exact. With the reporter's sizes (1000 x 1000 x 100, 100 calls) the legal
!   form ends in CUDA_ERROR_ILLEGAL_ADDRESS (data/reports/fresh-drafts/d076-copy.f90)
! - compilers: NVHPC nvfortran 25.11 and 26.9, -acc=gpu -gpu=cc80 -O2, -gpu=mem:separate and
!   -gpu=mem:managed; A100
! - expected: pass 10000000.0. Each loop's reduction combines the private copies after the loop
!   with the original var (OpenACC 3.4 §2.9.11 p.71 l.2549-2555); a reduction spanning nested
!   loops carries the clause on each loop directive (l.2560-2562), as here; every A(i,j,k) is 1, so
!   the sum is m*n*o = 10^7 exactly in any order
! - actual: 9987000 to 9997000 (whole inner loops of 1000 lost; the count varies between runs), both
!   releases, both memory modes, 12 of 12 runs
! - control (same compiler): 10000000 with gang collapse(2) instead of gang worker collapse(2)
!   (data/reports/fresh-drafts/d076-c-gang.f90), with the inner loop seq (d076-c-seq.f90), or with
!   worker vector on the inner loop (d076-c-worker-vector.f90); the same nest at 64 x 64 x 4 is
!   correct (d076-exact-small.f90)
! - other families: CCE 19/20/21 print pass 10000000 on this program (MI300A HSA_XNACK 1 and 0;
!   MI250X); AFAR has no Fortran OpenACC
! - legality: legal by reading (copy(sumA) on the parallel construct; the reduction clause on both
!   loop directives of the nest)
! - evidence: results/fresh-drafts/wingtip/nv.jsonl, tuo2-q6.jsonl, tioga/tioga-b.jsonl (review)
module test_mod
contains
subroutine test(A, sumA)
  implicit none
  real(kind=8) :: A(:,:,:), sumA
  integer :: i, j, k
!$acc parallel copy(sumA)
!$acc loop gang worker collapse(2) reduction(+:sumA)
  do k = 1, size(A,3)
    do j = 1, size(A,2)
!$acc loop vector reduction(+:sumA)
      do i = 1, size(A,1)
        sumA = sumA + A(i,j,k)
      end do
    end do
  end do
!$acc end parallel
end subroutine test
end module test_mod

program main
  use test_mod
  implicit none
  integer, parameter :: m = 1000, n = 1000, o = 10
  real(kind=8) :: A(m,n,o), sumA
  A = 1.0d0
  sumA = 0.0d0
  call test(A, sumA)
  if (sumA == real(m, 8)*n*o) then
    print *, 'pass', sumA
  else
    print *, 'fail', sumA, ' expected', real(m, 8)*n*o
  end if
end program main

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

pass 10000000.

Observed where it behaves incorrectly

 fail    9988000.000000000       expected    10000000.00000000     

What the specification requires

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

OpenACC 3.4 §2.6.2 p.42 l.1403-1409

OpenACC 3.4 §2.9.11 p.71 l.2549-2555

Evidence

Same compiler, one change

  • gang collapse(2) instead of gang worker collapse(2): CCE 19.0.0: correct; CCE 20.0.2: correct; CCE 21.0.3: correct; CCE 21.0.4: correct; NVHPC 25.11: correct; NVHPC 26.9: correct
    Control program
    module test_mod
    contains
    subroutine test(A, sumA)
      implicit none
      real(kind=8) :: A(:,:,:), sumA
      integer :: i, j, k
    !$acc parallel copy(sumA)
    !$acc loop gang collapse(2) reduction(+:sumA)
      do k = 1, size(A,3)
        do j = 1, size(A,2)
    !$acc loop vector reduction(+:sumA)
          do i = 1, size(A,1)
            sumA = sumA + A(i,j,k)
          end do
        end do
      end do
    !$acc end parallel
    end subroutine test
    end module test_mod
    
    program main
      use test_mod
      implicit none
      integer, parameter :: m = 1000, n = 1000, o = 10
      real(kind=8) :: A(m,n,o), sumA
      A = 1.0d0
      sumA = 0.0d0
      call test(A, sumA)
      if (sumA == real(m, 8)*n*o) then
        print *, 'pass', sumA
      else
        print *, 'fail', sumA, ' expected', real(m, 8)*n*o
      end if
    end program main
    

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