OffTarget

Observed issues › catalog/afar-c-critical-hint-link

Appears not to supportRefused at link time · C · 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: not independently confirmed. no independent review yet How this is checked

Same issue as catalog/afar-flang-named-critical-link; this program is another reproducer of it.

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.0correctcorrectcorrectunknown
not run
unknown
not run
n/an/a
CCE 20.0.2correctcorrectcorrectunknown
not run
unknown
not run
n/an/a
CCE 21.0.3correctcorrectcorrectunknown
not run
unknown
not run
n/an/a
CCE 21.0.4correctcorrectcorrectunknown
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-cd347b.img.lto.o:(__omp_offloading_14_1c7a89cd_main_l16)
>>> referenced by <dir>/repro.amdgpu9.42.gfx942-cd347b.img.lto.o:(__omp_offloading_14_1c7a89cd_main_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
clang: 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-6c3829.img.lto.o:(__omp_offloading_14_378d4d1d_main_l16)
>>> referenced by <dir>/repro.amdgpu9.0a.gfx90a-6c3829.img.lto.o:(__omp_offloading_14_378d4d1d_main_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
clang: 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_20002da_main_l16)
>>> referenced by <dir>:(__omp_offloading_fc10_20002da_main_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
clang: 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_4bc0_main_l16)
>>> referenced by <dir>:(__omp_offloading_fc10_4bc0_main_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
clang: error: linker command failed with exit code 1 (use -v to see invocation)
fails another wayNVHPC 25.11, A100 separate
NVHPC 25.11, A100 managed
show
NVC++-F-1196-OpenMP - omp critical is not supported in GPU region (afar-c-critical-hint-link.c: 18)
NVC++/x86-64 Linux 25.11-0: compilation aborted
fails another wayNVHPC 26.9, A100 separate
NVHPC 26.9, A100 managed
show
NVC++-F-1196-OpenMP - omp critical is not supported in GPU region (afar-c-critical-hint-link.c: 18)
NVC++/x86-64 Linux 26.9-0: compilation aborted

Reproduce

AFAR 24.3.0, MI300A unified

$AFAR/bin/amdclang -fopenmp --offload-arch=gfx942 -fopenmp-version=52 -fopenmp-version=52 -O2 repro.c -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
craycc -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -Xopenmp-target=amdgcn-amd-amdhsa -march=gfx942 -fopenmp-version=52 -O2 repro.c -o repro
HSA_XNACK=1 OMP_TARGET_OFFLOAD=mandatory ./repro
Program (61 lines)
// # Draft finding: omp52-c-w-critical-hint on afar
//
// - compiler: afar
// - toolchain: afar; arch: gfx942; machine: tuolumne; memory mode: unified; opt: -O2
// - program: catalog omp52-c-w-critical-hint (c, version 52, sha256 27f075f0e726545a)
// - 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 (NVC++-F-1196-OpenMP - omp critical is not supported in GPU region);
//   the check's other witness, the AFAR clang 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, C11; catalog widening). Do not edit.
// id: omp52-c-w-critical-hint
// primary atom: omp.clause.hint
// atoms: omp.clause.hint
// legal: yes
// observable: yes
// ran_on_host: inside the target region of interest
// evidence: construct
// needs: none
// std: c11
// feature: a named critical construct with a hint clause 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; §15.1 (hint clause)
#include <stdio.h>
#include <stdbool.h>
#include <omp.h>

enum { n = 64 };

int main(void) {
  int a[n], b[n], ref[n];
  int host_flag = 1;
  int s = 0;
  for (int i = 0; i < n; i++) {
    a[i] = i + 1;
    b[i] = 0;
    ref[i] = 0;
  }
  #pragma omp target parallel for map(to: a) map(tofrom: s, host_flag)
  for (int i = 0; i < n; i++) {
    #pragma omp critical(wsum) hint(omp_sync_hint_contended)
    {
      int t = s;
      s = t + a[i];
    }
    if (i == 0) host_flag = omp_is_initial_device();
  }
  bool ok = true;
  for (int i = 0; i < n; i++)
    ok = ok && (b[i] == ref[i]);
  ok = ok && (s == n * (n + 1) / 2);
  printf("RESULT ran_on_host=%d check=%s\n", host_flag, ok ? "pass" : "fail");
  return 0;
}

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-cd347b.img.lto.o:(__omp_offloading_14_1c7a89cd_main_l16)
>>> referenced by <dir>/repro.amdgpu9.42.gfx942-cd347b.img.lto.o:(__omp_offloading_14_1c7a89cd_main_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
clang: 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

OpenMP 5.2 §15.1

Evidence

Same compiler, one change

  • the hint clause removed (a named critical without hint): 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
    #include <stdio.h>
    #include <stdbool.h>
    #include <omp.h>
    
    enum { n = 64 };
    
    int main(void) {
      int a[n], b[n], ref[n];
      int host_flag = 1;
      int s = 0;
      for (int i = 0; i < n; i++) {
        a[i] = i + 1;
        b[i] = 0;
        ref[i] = 0;
      }
      #pragma omp target parallel for map(to: a) map(tofrom: s, host_flag)
      for (int i = 0; i < n; i++) {
        #pragma omp critical(wsum)
        {
          int t = s;
          s = t + a[i];
        }
        if (i == 0) host_flag = omp_is_initial_device();
      }
      bool ok = true;
      for (int i = 0; i < n; i++)
        ok = ok && (b[i] == ref[i]);
      ok = ok && (s == n * (n + 1) / 2);
      printf("RESULT ran_on_host=%d check=%s\n", host_flag, ok ? "pass" : "fail");
      return 0;
    }
    

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