OffTarget

Observed issues › catalog/afar-flang-named-critical-link

Appears not to supportRefused at link time · Fortran · OpenMP · Open

amdflang/amdclang: a named critical (Fortran) or a critical with hint (C) in a target region fails at the device link (__kmpc_critical_with_hint undefined)

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.0not supportednot supportednot supportednot supportednot supportedn/an/a
CCE 19.0.0fails another wayfails another wayfails another wayunknown
not run
unknown
not run
n/an/a
CCE 20.0.2fails another wayfails another wayfails another wayunknown
not run
unknown
not run
n/an/a
CCE 21.0.3fails another wayfails another wayfails another wayunknown
not run
unknown
not run
n/an/a
CCE 21.0.4fails another wayfails another wayfails another wayunknown
not run
unknown
not run
n/an/a
NVHPC 25.11n/an/an/an/an/afails another wayfails another way
NVHPC 26.9n/an/an/an/an/afails another wayfails another way
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
not supportedAFAR 24.3.0, MI300A unified
AFAR 24.3.0, MI300A copy
show
ld.lld: error: undefined symbol: __kmpc_critical_with_hint
>>> referenced by <dir>/repro.amdgpu9.42.gfx942-b56733.img.lto.o:(__omp_offloading_14_1c74fb48__QQmain_l16)
>>> referenced by <dir>/repro.amdgpu9.42.gfx942-b56733.img.lto.o:(__omp_offloading_14_1c74fb48__QQmain_l16)
clang: error: ld.lld command failed with exit code 1 (use -v to see invocation)
$AFAR/lib/llvm/bin/clang-linker-wrapper: error: 'clang' failed
flang-24: error: linker command failed with exit code 1 (use -v to see invocation)
not supportedAFAR 24.3.0, MI250X
show
ld.lld: error: undefined symbol: __kmpc_critical_with_hint
>>> referenced by <dir>/repro.amdgpu9.0a.gfx90a-bc6276.img.lto.o:(__omp_offloading_14_378a3e69__QQmain_l16)
>>> referenced by <dir>/repro.amdgpu9.0a.gfx90a-bc6276.img.lto.o:(__omp_offloading_14_378a3e69__QQmain_l16)
clang: error: ld.lld command failed with exit code 1 (use -v to see invocation)
$AFAR/lib/llvm/bin/clang-linker-wrapper: error: 'clang' failed
flang-24: error: linker command failed with exit code 1 (use -v to see invocation)
not supportedAFAR 24.3.0, MI300X
show
ld.lld: error: undefined symbol: __kmpc_critical_with_hint
>>> referenced by <dir>:(__omp_offloading_fc10_b5__QQmain_l16)
>>> referenced by <dir>:(__omp_offloading_fc10_b5__QQmain_l16)
clang: error: ld.lld command failed with exit code 1 (use -v to see invocation)
$AFAR/lib/llvm/bin/clang-linker-wrapper: error: 'clang' failed
flang-24: error: linker command failed with exit code 1 (use -v to see invocation)
not supportedAFAR 24.3.0, MI350X
show
ld.lld: error: undefined symbol: __kmpc_critical_with_hint
>>> referenced by <dir>:(__omp_offloading_fc10_6003127__QQmain_l16)
>>> referenced by <dir>:(__omp_offloading_fc10_6003127__QQmain_l16)
clang: error: ld.lld command failed with exit code 1 (use -v to see invocation)
$AFAR/lib/llvm/bin/clang-linker-wrapper: error: 'clang' failed
flang-24: error: linker command failed with exit code 1 (use -v to see invocation)
fails another wayCCE 19.0.0, MI300A unified
CCE 19.0.0, MI300A copy
CCE 19.0.0, MI250X
show
Warning:
 Headers and libraries from cray-libsci/25.03.0 will be ignored because depends on PE_MPICH which is unavailable..
MT_CONTEXT_CRITICAL_SECTION
   Error message      ::  unhandled construct type
   Error detected     ::  File '/workspace/crayftn/pdgcs/v_openmp.c', line 7617
   Initiated from     ::  Line 660 (v_main.c)
   Optimizer built    ::  2025-02-07 (production)
   File               ::  afar-flang-named-critical-link.f90
fails another wayCCE 20.0.2, MI300A unified
CCE 20.0.2, MI300A copy
CCE 20.0.2, MI250X
show
Warning:
 Headers and libraries from cray-libsci/25.09.0 will be ignored because depends on PE_MPICH which is unavailable..
MT_CONTEXT_CRITICAL_SECTION
   Error message      ::  unhandled construct type
   Error detected     ::  File '/workspace/crayftn/pdgcs/v_openmp.c', line 7814
   Initiated from     ::  Line 660 (v_main.c)
   Optimizer built    ::  2025-11-17 (production)
   File               ::  afar-flang-named-critical-link.f90
fails another wayCCE 21.0.3, MI300A unified
CCE 21.0.3, MI300A copy
CCE 21.0.3, MI250X
show
Warning:
 Headers and libraries from cray-libsci/26.03.0 will be ignored because depends on PE_MPICH which is unavailable..
MT_CONTEXT_CRITICAL_SECTION
   Error message      ::  unhandled construct type
   Error detected     ::  File '/workspace/crayftn/pdgcs/v_openmp.c', line 8197
   Initiated from     ::  Line 732 (v_main.c)
   Optimizer built    ::  2026-07-14 (production)
   File               ::  afar-flang-named-critical-link.f90
fails another wayCCE 21.0.4, MI300A unified
CCE 21.0.4, MI300A copy
CCE 21.0.4, MI250X
show
Warning:
 Headers and libraries from cray-libsci/26.03.0 will be ignored because depends on PE_MPICH which is unavailable..
MT_CONTEXT_CRITICAL_SECTION
   Error message      ::  unhandled construct type
   Error detected     ::  File '/workspace/crayftn/pdgcs/v_openmp.c', line 8197
   Initiated from     ::  Line 732 (v_main.c)
   Optimizer built    ::  2026-09-24 (production)
   File               ::  afar-flang-named-critical-link.f90
fails another wayNVHPC 25.11, A100 separate
NVHPC 25.11, A100 managed
show
NVFORTRAN-F-1196-OpenMP - omp critical is not supported in GPU region (afar-flang-named-critical-link.f90: 19)
NVFORTRAN/x86-64 Linux 25.11-0: compilation aborted
fails another wayNVHPC 26.9, A100 separate
NVHPC 26.9, A100 managed
show
NVFORTRAN-F-1196-OpenMP - omp critical is not supported in GPU region (afar-flang-named-critical-link.f90: 19)
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

GCC 16.2.0, MI300A unified (runs correctly)

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
Program (59 lines)
! # Draft finding: omp52-w-critical-named on afar
!
! - compiler: afar
! - toolchain: afar; arch: gfx942; machine: tuolumne; memory mode: unified; opt: -O2
! - program: catalog omp52-w-critical-named (f90, version 52, sha256 dabbabc4b167391a)
! - expected: None (None; )
! - actual: rejected  (link_undefined_symbol: ld.lld: error: undefined symbol: __kmpc_critical_with_hint)
! - verdict: compiler_bug by rule R10b-own-link-or-hang: a link failure on symbols the compiler's own generated code needs, or a
!   compile that does not finish, on a legal program: the compiler's defect (never a rejection)
! - reason: 
! - citations: RUL-COMPILE-TIME (rulings.md)
! - legality: legal: offload.engine.rules accepts it (offload.engine.prerun.check, rerun: with the
!   race rule and the restriction checks); NVHPC is no witness: it does not implement a feature the
!   program uses (NVFORTRAN-F-1196-OpenMP - omp critical is not supported in GPU
!   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
! - witnesses: none
! - withdrawn: none
!
! Generated by compliance.widen (OpenMP 5.2, free-form Fortran; catalog widening). Do not edit.
! id: omp52-w-critical-named
! primary atom: form.omp.critical_named
! atoms: form.omp.critical_named
! legal: yes
! observable: yes
! ran_on_host: inside the target region of interest
! evidence: construct
! needs: none
! std: f2008
! feature: a named critical construct in a target parallel loop
! spec: OpenMP 5.2 §15.2, p.299 (critical construct); its binding thread set is the contention group, so a target parallel region
! (one team) is used
program wide_prog
  use omp_lib, only: omp_is_initial_device
  implicit none
  integer, parameter :: n = 64
  integer :: a(n), b(n), ref(n)
  integer :: s, t
  integer :: i, host_flag
  logical :: ok
  do i = 1, n
    a(i) = i
    b(i) = 0
    ref(i) = 2*i + 1
  end do
  host_flag = 1
  s = 0
  !$omp target parallel do map(to: a) map(tofrom: s, host_flag) private(t)
  do i = 1, n
    !$omp critical (wsum)
    t = s
    s = t + a(i)
    !$omp end critical (wsum)
    if (i == 1) host_flag = merge(1, 0, omp_is_initial_device())
  end do
  !$omp end target parallel do
  ok = s == n*(n + 1)/2
  print '(a,i0,a,a)', 'RESULT ran_on_host=', host_flag, ' check=', merge('pass', 'fail', ok)
end program wide_prog

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

Observed where it behaves incorrectly

ld.lld: error: undefined symbol: __kmpc_critical_with_hint
>>> referenced by <dir>/repro.amdgpu9.42.gfx942-b56733.img.lto.o:(__omp_offloading_14_1c74fb48__QQmain_l16)
>>> referenced by <dir>/repro.amdgpu9.42.gfx942-b56733.img.lto.o:(__omp_offloading_14_1c74fb48__QQmain_l16)
clang: error: ld.lld command failed with exit code 1 (use -v to see invocation)
$AFAR/lib/llvm/bin/clang-linker-wrapper: error: 'clang' failed
flang-24: error: linker command failed with exit code 1 (use -v to see invocation)

What the specification requires

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

OpenMP 5.2 §15.2 p.299

Evidence

Same compiler, one change

  • the same loop on the host (parallel do instead of target parallel do): 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 wide_prog
      use omp_lib, only: omp_is_initial_device
      implicit none
      integer, parameter :: n = 64
      integer :: a(n), b(n), ref(n)
      integer :: s, t
      integer :: i, host_flag
      logical :: ok
      do i = 1, n
        a(i) = i
        b(i) = 0
        ref(i) = 2*i + 1
      end do
      host_flag = 1
      s = 0
      !$omp parallel do private(t)
      do i = 1, n
        !$omp critical (wsum)
        t = s
        s = t + a(i)
        !$omp end critical (wsum)
        if (i == 1) host_flag = merge(1, 0, omp_is_initial_device())
      end do
      !$omp end parallel do
      ok = s == n*(n + 1)/2
      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

GCC 16.2.0

Reproducers of this issue