OffTarget

Observed issues › harvest/gcc-teams-simd-matmul-allocatable-ice

Appears to behave incorrectlyCompiler crash · Fortran · OpenMP · Open

matmul of allocatable array sections in target teams distribute parallel do simd: internal compiler error

Legality: independently confirmed. 2 independent readings find the program legal and the result required. How this is checked

A target teams distribute parallel do simd loop whose body assigns matmul of sections of allocatable arrays stops GCC 16.2's Fortran front end with an internal compiler error (gfc_omp_clause_default_ctor), for both offload targets. The same loop with the product written as loops compiles and runs correctly. AFAR and NVHPC run the harvested program correctly.

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.0correctcorrectunknown
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/acorrectcorrect
NVHPC 26.9n/an/an/an/an/acorrectcorrect
GCC 16.2.0behaves incorrectlybehaves incorrectlybehaves incorrectlybehaves incorrectlybehaves incorrectlybehaves incorrectlyn/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 incorrectlyGCC 16.2.0, MI300A unified
GCC 16.2.0, MI300A copy
show
during GIMPLE pass: omplower
site-harvest--gcc-teams-simd-matmul-allocatable-ice.f90:38:80:
   38 |   !$omp target teams distribute parallel do simd map(tofrom: a, b, c, host_flag)
      |                                                                                ^
internal compiler error: in gfc_omp_clause_default_ctor, at fortran/trans-openmp.cc:840
0x2072e2d internal_error(char const*, ...)
	<dir>:787
0x7d943f fancy_abort(char const*, int, char const*)
behaves incorrectlyGCC 16.2.0, MI250X
show
during GIMPLE pass: omplower
site-harvest--gcc-teams-simd-matmul-allocatable-ice.f90:33:80:
   33 |   !$omp target teams distribute parallel do simd map(tofrom: a, b, c, host_flag)
      |                                                                                ^
internal compiler error: in gfc_omp_clause_default_ctor, at fortran/trans-openmp.cc:840
0x2072e2d internal_error(char const*, ...)
	<dir><host>-gcc-src/gcc-16.2.0/gcc/diagnostic-global-context.cc:787
0x7d943f fancy_abort(char const*, int, char const*)
behaves incorrectlyGCC 16.2.0, MI300X
GCC 16.2.0, MI350X
show
during GIMPLE pass: omplower
site-harvest--gcc-teams-simd-matmul-allocatable-ice.f90:38:80:
   38 |   !$omp target teams distribute parallel do simd map(tofrom: a, b, c, host_flag)
      |                                                                                ^
internal compiler error: in gfc_omp_clause_default_ctor, at fortran/trans-openmp.cc:840
0x2083fcd internal_error(char const*, ...)
	<home>/<user>/gcc-work/gcc-16.2.0/gcc/diagnostic-global-context.cc:787
0x7cebc6 fancy_abort(char const*, int, char const*)
behaves incorrectlyGCC 16.2.0, A100 separate
show
during GIMPLE pass: omplower
site-harvest--gcc-teams-simd-matmul-allocatable-ice.f90:33:80:
   33 |   !$omp target teams distribute parallel do simd map(tofrom: a, b, c, host_flag)
      |                                                                                ^
internal compiler error: in gfc_omp_clause_default_ctor, at fortran/trans-openmp.cc:840
0x214aceb internal_error(char const*, ...)
	<home>/gcc-build/gcc-16.2.0/gcc/diagnostic-global-context.cc:787
0x7db5a3 fancy_abort(char const*, int, char const*)

Reproduce

GCC 16.2.0, MI300A unified

export LD_LIBRARY_PATH=$GCC_16_2/lib64:/opt/rocm-7.2.1/lib
$GCC_16_2/bin/gfortran -fopenmp -foffload=amdgcn-amdhsa -foffload-options=amdgcn-amdhsa=-march=gfx942 -O2 repro.f90 -o repro
HSA_XNACK=1 OMP_TARGET_OFFLOAD=mandatory ./repro

GCC 16.2.0, A100 separate

export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=$GCC_16_2/lib64
$GCC_16_2/bin/gfortran -fopenmp -foffload=nvptx-none -foffload-options=nvptx-none=-march=sm_80 -foffload-options=nvptx-none=-latomic -O2 repro.f90 -o repro
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 (46 lines)
! # Finding (GCC 16.2, LLVM/AOMP harvest): matmul of allocatable array sections in target teams distribute parallel do simd:
!   internal compiler error in gfc_omp_clause_default_ctor
!
! - toolchains: gcc_g90 (GCC 16.2.0, AMD Instinct MI250X gfx90a, Tioga) and gcc_sm80 (GCC 16.2.0, NVIDIA A100 sm_80, wingtip);
!   separate memory only; -O2
! - build: gfortran -fopenmp -foffload=amdgcn-amdhsa -foffload-options=amdgcn-amdhsa=-march=gfx90a -O2 (gcc_g90);
!   -foffload=nvptx-none -foffload-options=nvptx-none=-march=sm_80 -foffload-options=nvptx-none=-latomic -O2 (gcc_sm80)
! - failure: ice: internal compiler error: in gfc_omp_clause_default_ctor
! - observed: `internal compiler error: in gfc_omp_clause_default_ctor, at fortran/trans-openmp.cc:840` at the combined directive,
!   on both targets (the host compiler fails before any offload code is made)
! - expected: compiles; prints `sum=   6720.0` and `RESULT ran_on_host=0 check=pass`
! - rule: a simd construct may contain calls ("The only OpenMP constructs that can be encountered during execution of a simd region
!   are ..." restricts OpenMP constructs, not procedure references: 5.2 §17.1 p.338 l.25-27); matmul is an intrinsic function of the
!   base language (Fortran 2018 16.9.124).
! - same-compiler control (compiles; correct, gcc_sm80: mandatory pass 5 of 5; unset pass 5 of 5; gcc_g90: mandatory pass 5 of 5;
!   unset pass 5 of 5 (results/parity/<machine>/<tc>/probes.jsonl)): the product as explicit loops in the same construct
!   (controls/gcc-teams-simd-matmul-allocatable-control.f90). With explicit-shape arrays the matmul form compiles and runs correctly
!   on both GPUs (mandatory pass 5 of 5; unset pass 5 of 5; results/parity/probes-r2/matmul_explicit.f90). Without simd it compiles;
!   it runs correctly on the MI250X (5 of 5), and on the A100 the offload image fails to load (`libgomp: Link error log error :
!   Prototype doesn't match for '_gfortran_matmul_r4'`, exit 1, 5 of 5; results/parity/probes-r2/matmul_nosimd.f90): a lead, not
!   part of this finding.
! - other families: AFAR and NVHPC 25.11/26.9 run the harvested program correctly (results/harvest/main); CCE fails it another way.
!   The site's finding matrix runs this file on every compiler.
! - harvested programs (2 cells (1 gcc_g90, 1 gcc_sm80); gate: confirmed 2; confirmer: compiler_bug (R10-compile-ice) 2):
!   hv-aomp-smoke-fails-flang-324387
! - legality: the pre-run check (offload.engine.prerun.check: the rules and AFAR's front end, two witnesses) accepts the harvested
!   program; GCC is a compiler under test only and never a legality witness.
program matmul_teams_simd
  use omp_lib, only: omp_is_initial_device
  implicit none
  integer :: k, host_flag
  real, allocatable :: a(:,:,:), b(:,:,:), c(:,:,:)
  allocate(a(5,7,16), b(7,6,16), c(5,6,16))
  a = 1.0
  b = 2.0
  c = 0.0
  host_flag = 1
  !$omp target teams distribute parallel do simd map(tofrom: a, b, c, host_flag)
  do k = 1, 16
    if (k == 1) host_flag = merge(1, 0, omp_is_initial_device())
    c(:,:,k) = c(:,:,k) + matmul(a(:,:,k), b(:,:,k))
  end do
  ! every element is 7 * (1.0 * 2.0)
  print '(a,f8.1)', 'sum= ', sum(c)
  print '(a,i0,a,a)', 'RESULT ran_on_host=', host_flag, ' check=', merge('pass', 'fail', sum(c) == 5*6*16*14.0)
end program matmul_teams_simd

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

check=pass

Observed where it behaves incorrectly

during GIMPLE pass: omplower
site-harvest--gcc-teams-simd-matmul-allocatable-ice.f90:38:80:
   38 |   !$omp target teams distribute parallel do simd map(tofrom: a, b, c, host_flag)
      |                                                                                ^
internal compiler error: in gfc_omp_clause_default_ctor, at fortran/trans-openmp.cc:840
0x2072e2d internal_error(char const*, ...)
	<dir>:787
0x7d943f fancy_abort(char const*, int, char const*)

What the specification requires

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

OpenMP 5.2 §17.1 p.338 l.25-27

Evidence

Same compiler, one change

  • the product written as explicit loops: not run yet
    Control program
    ! Control of harvest/gcc-teams-simd-matmul-allocatable-ice.f90: the product as explicit loops in the same construct
    ! (compiles; correct on gcc_g90 and gcc_sm80).
    program matmul_teams_simd
      use omp_lib, only: omp_is_initial_device
      implicit none
      integer :: i, j, k, l, host_flag
      real, allocatable :: a(:,:,:), b(:,:,:), c(:,:,:)
      allocate(a(5,7,16), b(7,6,16), c(5,6,16))
      a = 1.0
      b = 2.0
      c = 0.0
      host_flag = 1
      !$omp target teams distribute parallel do simd map(tofrom: a, b, c, host_flag)
      do k = 1, 16
        if (k == 1) host_flag = merge(1, 0, omp_is_initial_device())
        do j = 1, 6
          do i = 1, 5
            do l = 1, 7
              c(i,j,k) = c(i,j,k) + a(i,l,k)*b(l,j,k)
            end do
          end do
        end do
      end do
      ! every element is 7 * (1.0 * 2.0)
      print '(a,f8.1)', 'sum= ', sum(c)
      print '(a,i0,a,a)', 'RESULT ran_on_host=', host_flag, ' check=', merge('pass', 'fail', sum(c) == 5*6*16*14.0)
    end program matmul_teams_simd
    

Other compilers run it correctly

AFAR 24.3.0, CCE 19.0.0, CCE 20.0.2, CCE 21.0.3, CCE 21.0.4, NVHPC 25.11, NVHPC 26.9