OffTarget

Observed issues › cce-c-parallel-for-in-target

Appears to behave incorrectlyWrong answer · C · OpenMP · Open

craycc: parallel for schedule(static) in a target region runs 1 of 64 iterations

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.0correctcorrectcorrectcorrectcorrectn/an/a
CCE 19.0.0behaves incorrectlybehaves incorrectlybehaves incorrectlyunknown
not run
unknown
not run
n/an/a
CCE 20.0.2behaves incorrectlybehaves incorrectlybehaves incorrectlyunknown
not run
unknown
not run
n/an/a
CCE 21.0.3behaves incorrectlybehaves incorrectlybehaves incorrectlyunknown
not run
unknown
not run
n/an/a
CCE 21.0.4behaves incorrectlybehaves incorrectlybehaves incorrectlyunknown
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
behaves incorrectlyCCE 19.0.0, MI300A unified
CCE 19.0.0, MI300A copy
CCE 19.0.0, MI250X
CCE 20.0.2, MI300A unified
CCE 20.0.2, MI300A copy
CCE 20.0.2, MI250X
CCE 21.0.3, MI300A unified
CCE 21.0.3, MI300A copy
CCE 21.0.3, MI250X
CCE 21.0.4, MI300A unified
CCE 21.0.4, MI300A copy
CCE 21.0.4, MI250X
show
static 1 of 64; lastprivate t=-1; linear 64 of 64, x=0
fails another wayNVHPC 25.11, A100 separate
NVHPC 25.11, A100 managed
show
"cce-c-parallel-for-in-target.c", line 10: warning: variable "t" was set but never used [set_but_not_used]
      for (int i = 0; i < 64; i++) { c[i] = i + 1; t = i; }
      ^
Remark: individual warnings can be suppressed with "--diag_suppress <warning-name>"
NVC++-F-0155-Compiler failed to translate OpenMP region  (cce-c-parallel-for-in-target.c: 10)
NVC++/x86-64 Linux 25.11-0: compilation aborted
fails another wayNVHPC 26.9, A100 separate
NVHPC 26.9, A100 managed
show
"cce-c-parallel-for-in-target.c", line 10: warning: variable "t" was set but never used [set_but_not_used]
      for (int i = 0; i < 64; i++) { c[i] = i + 1; t = i; }
      ^
Remark: individual warnings can be suppressed with "--diag_suppress <warning-name>"
NVC++-F-0155-Compiler failed to translate OpenMP region  (cce-c-parallel-for-in-target.c: 10)
NVC++/x86-64 Linux 26.9-0: compilation aborted

Reproduce

CCE 19.0.0, MI300A unified

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

CCE 20.0.2, MI300A unified

module load cce/20.0.2 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

CCE 21.0.3, MI300A unified

module load cce/21.0.3 craype-accel-amd-gfx942 rocm/7.2.0
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

CCE 21.0.4, MI300A unified

module load cce/21.0.4 craype-accel-amd-gfx942 rocm/7.2.0
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

AFAR 24.3.0, MI300A unified (runs correctly)

$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
Program (63 lines)
/* Finding (C): a parallel for nested in a target region loses
   iterations with schedule(static) and drops the final values of
   lastprivate and linear list items on CCE.

   Legal OpenMP 5.2 C. Inside the target region each parallel for must
   run all 64 iterations (5.2 §11.5: every iteration is executed once,
   whatever the schedule); lastprivate(t) gives t the value of the
   sequentially last iteration (5.2 §5.4.5) and linear(x: 1) gives x its
   value after the last iteration (5.2 §5.4.6), and the map(tofrom:)
   returns both to the host.

   Expected: "static 64 of 64; lastprivate t=63; linear 64 of 64, x=64".
   Observed (-O2, HSA_XNACK=1; CCE 19 also at HSA_XNACK=0 and at -O0):
   CCE craycc 19.0.0, 20.0.2 and 21.0.3 print "static 1 of 64; lastprivate t=-1; linear 64 of 64,
   x=0" (the region has one thread; without schedule(static) all 64
   iterations run, with schedule(static, 4) too). AFAR amdclang prints
   the expected line, and CCE ftn runs the Fortran forms correctly
   (omp52-clause-schedule-static, -lastprivate, -linear, -collapse).
   In the matrix this makes the C collapse, lastprivate, linear and
   schedule programs wrong_answer on CCE.

   Probe (data/evidence/triage_probe/pfor_*.c, results/t27b/probes.jsonl,
   tuolumne, both memory modes, 3 runs each): schedule(dynamic) loses
   iterations too on CCE 19, 20 and 21 (b computed wrong, bad > 0), with or
   without default(none) shared(a, b); the same parallel for without a
   schedule clause (with or without default(none)) is correct; AFAR is
   correct in every form. So schedule(static) without a chunk size,
   schedule(dynamic) and the catalog's auto, guided, runtime, monotonic and
   simd forms trigger it, as does lastprivate; schedule(static, 4) (above)
   does not, so not every schedule clause does.

   : three defects in one program (schedule(static)
   loses iterations; lastprivate and linear lose the final value); the
   control above covers only the first. The HPE packet splits them (cases
   cce-c-parallel-for-in-target-static, -lastprivate, -linear, each with its
   own control); a linear item's final value is lost with num_threads(1) too:
   the linear case's former control (num_threads(1) added, now dropped from
   the case) prints x=0 on CCE 19, 20, 21.0.3 and 21.0.4 in both modes
   (data/vendor/checks/results-compact), so it does not isolate the defect
   and is not listed as a control below.

   craycc -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa
          -Xopenmp-target=amdgcn-amd-amdhsa -march=gfx942
          -fopenmp-version=52 -O2 */
#include <stdio.h>
int main(void) {
  int b[64], c[64], d[64], t = -1, x = 0;
  for (int i = 0; i < 64; i++) { b[i] = 0; c[i] = 0; d[i] = -1; }
  #pragma omp target map(from: b, c, d) map(tofrom: t, x)
  {
    #pragma omp parallel for schedule(static)
    for (int i = 0; i < 64; i++) b[i] = i + 1;
    #pragma omp parallel for lastprivate(t)
    for (int i = 0; i < 64; i++) { c[i] = i + 1; t = i; }
    #pragma omp parallel for linear(x: 1)
    for (int i = 0; i < 64; i++) { d[i] = x; x++; }
  }
  int nb = 0, nd = 0;
  for (int i = 0; i < 64; i++) { nb += b[i] == i + 1; nd += d[i] == i; }
  printf("static %d of 64; lastprivate t=%d; linear %d of 64, x=%d\n",
         nb, t, nd, x);
  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

Expected

static 64 of 64; lastprivate t=63; linear 64 of 64, x=64

Observed where it behaves incorrectly

static 1 of 64; lastprivate t=-1; linear 64 of 64, x=0

What the specification requires

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

OpenMP 5.2 §11.5

OpenMP 5.2 §5.4.5

OpenMP 5.2 §5.4.6

Evidence

Same compiler, one change

  • schedule(static) removed from the first parallel for (the first part of the output only): 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>
    int main(void) {
      int b[64], c[64], d[64], t = -1, x = 0;
      for (int i = 0; i < 64; i++) { b[i] = 0; c[i] = 0; d[i] = -1; }
      #pragma omp target map(from: b, c, d) map(tofrom: t, x)
      {
        #pragma omp parallel for
        for (int i = 0; i < 64; i++) b[i] = i + 1;
        #pragma omp parallel for lastprivate(t)
        for (int i = 0; i < 64; i++) { c[i] = i + 1; t = i; }
        #pragma omp parallel for linear(x: 1)
        for (int i = 0; i < 64; i++) { d[i] = x; x++; }
      }
      int nb = 0, nd = 0;
      for (int i = 0; i < 64; i++) { nb += b[i] == i + 1; nd += d[i] == i; }
      printf("static %d of 64; lastprivate t=%d; linear %d of 64, x=%d\n",
             nb, t, nd, x);
      return 0;
    }
    
  • schedule(static) removed: 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>
    int main(void) {
      int b[64];
      for (int i = 0; i < 64; i++) b[i] = 0;
      #pragma omp target map(from: b)
      {
        #pragma omp parallel for
        for (int i = 0; i < 64; i++) b[i] = i + 1;
      }
      int nb = 0;
      for (int i = 0; i < 64; i++) nb += b[i] == i + 1;
      printf("static %d of 64\n", nb);
      return 0;
    }
    
  • reduction(max: t) instead of lastprivate(t): 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>
    int main(void) {
      int c[64], t = -1;
      for (int i = 0; i < 64; i++) c[i] = 0;
      #pragma omp target map(from: c) map(tofrom: t)
      {
        #pragma omp parallel for reduction(max: t)
        for (int i = 0; i < 64; i++) { c[i] = i + 1; t = i; }
      }
      printf("lastprivate t=%d c[63]=%d\n", t, c[63]);
      return 0;
    }
    

Other compilers run it correctly

AFAR 24.3.0, GCC 16.2.0

Reproducers of this issue