OffTarget

Observed issues › stress/nvhpc-c-lastprivate-teams-distribute-parallel-for-lost

Appears to behave incorrectlyWrong answer · C · OpenMP · Open

Lastprivate on target teams distribute parallel for accepted silently, value lost

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.0correctcorrectunknown
not run
correctcorrectn/an/a
CCE 19.0.0behaves incorrectlybehaves incorrectlyunknown
not run
unknown
not run
unknown
not run
n/an/a
CCE 20.0.2behaves incorrectlybehaves incorrectlyunknown
not run
unknown
not run
unknown
not run
n/an/a
CCE 21.0.3behaves incorrectlybehaves incorrectlyunknown
not run
unknown
not run
unknown
not run
n/an/a
CCE 21.0.4behaves incorrectlybehaves incorrectlyunknown
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.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 20.0.2, MI300A unified
CCE 20.0.2, MI300A copy
CCE 21.0.3, MI300A unified
CCE 21.0.3, MI300A copy
CCE 21.0.4, MI300A unified
CCE 21.0.4, MI300A copy
NVHPC 25.11, A100 separate
NVHPC 25.11, A100 managed
NVHPC 26.9, A100 separate
NVHPC 26.9, A100 managed
show
l= 0 dev= 1

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

NVHPC 25.11, A100 separate

export LD_LIBRARY_PATH=$NVHPC_25_11/compilers/lib
nvc -mp=gpu -gpu=cc80 -gpu=mem:separate -O2 repro.c -o repro
OMP_TARGET_OFFLOAD=mandatory ./repro

NVHPC 26.9, A100 separate

export LD_LIBRARY_PATH=$NVHPC_26_9/compilers/lib
nvc -mp=gpu -gpu=cc80 -gpu=mem:separate -O2 repro.c -o repro
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 (56 lines)
/* # Finding: NVHPC accepts lastprivate on target teams distribute
   # parallel for, which its guide documents as unsupported, and gives a wrong answer (C)

   - class: an unsupported clause accepted silently with a wrong answer, the R6
     report-candidate class (as nvhpc-depend-inoutset-ignored.f90); a support claim it contradicts
     is partial_support (data/reports/rulings.md, documented limitations), not a compiler bug in a
     documented feature. NVIDIA HPC Compilers User's Guide 25.11 (and 26.9), §7.4 OpenMP Subset:
       2.9.4 Distribute Directives: "The lastprivate clause is not supported"
       2.14 Clauses on Combined and Composite Constructs: "Clauses on combined constructs are
       supported to the extent that the clauses are supported on the component constructs."
     On this construct lastprivate applies to the distribute and for leaves (5.2 §17.2), so it is
     not supported here. nvc gives no diagnostic. The claim is catalog/omp/claims.yaml
     onleaf.distribute.lastprivate (the triage reads it).
   - compilers: NVHPC nvc 25.11 and 26.9, A100 (sm_80), -mp=gpu -gpu=cc80, separate and managed
     memory, -O2
   - expected: l= 2560 dev= 1. lastprivate gives the original l the value of the sequentially last
     iteration (i = 64: 64 * 40) (5.2 §5.4.5; §17.2 p.340 l.21-30 applies it to the distribute and
     for leaves), and map(tofrom: l) on the target leaf brings it back to the host. The explicit
     map is legal: 5.2 §13.8 p.286 l.29-30 restricts only data-sharing clauses applied to the target
     leaf, and the 5.0 §2.19.7.1 restriction (p.321 l.25-26) exempts combined constructs
   - actual: l= 0 dev= 1, both releases, both memory modes
   - same-compiler controls, all l= 2560 on both releases and modes
     (data/reports/fuzz-stress-audit/, runs in results/stress/audit/runs-nvhpc-fix2.jsonl):
       lp-c-tdpf-red.c   the same construct and loop with reduction(max: l) instead of lastprivate
       lp-c-tdpf-copy.c  the same construct, private(l), the last iteration stores l in a mapped array
       lp-c-tdist-map.c  target teams distribute lastprivate(l) map(tofrom: l) (no parallel for)
       lp-c-tpfor-map.c  target parallel for lastprivate(l) map(tofrom: l) (no teams distribute)
       lp-c-tdist-split.c target map(tofrom: l) around teams distribute lastprivate(l)
     The worksharing-loop form (lp-c-tpfor-map.c) uses a documented clause ("The lastprivate clause
     is supported", 2.9.2) and gives 2560. The distribute-only forms (lp-c-tdist-map.c,
     lp-c-tdist-split.c) also give 2560, but that is undocumented behaviour: the guide says
     lastprivate on distribute is not supported. So the composite gives a wrong answer for a clause
     the guide excludes; the controls show that the value can be returned, not that nvc supports it.
   - other families: AFAR amdclang gives 2560 on this program (MI300A HSA_XNACK 1 and 0, MI250X).
     CCE craycc gives 0 here too (see data/reports/fuzz-stress.md, candidate 2b).
   - related, not the same: nvhpc-c-parallel-for-firstprivate-in-target.c is a compile failure
     ("Failed to translate OpenMP region") of a parallel for nested in a target region; this program
     compiles and runs a combined construct. Without the map (r2-lastprivate-combined.c and
     lp-c-tdist.c) nvc also gives 0: the missing implicit map, the C form of
     stress/nvhpc-lastprivate-combined-target-not-mapped.f90.
   - legality: legal by reading: the for loop variable is private; only the lastprivate item l is
     written in the loop; dev is written by the initial thread of the second target region
   - evidence: tools/jobs/run_wingtip_fix2.sh (tools/campaigns/stress_audit.py); the confirmer was not run on it */
#include <stdio.h>
#include <omp.h>
int main(void) {
  long long l = 0;
  int dev = -1;
  #pragma omp target teams distribute parallel for lastprivate(l) map(tofrom: l)
  for (int i = 1; i <= 64; i++)
    l = (long long) i * 40;
  #pragma omp target map(tofrom: dev)
  dev = omp_is_initial_device() ? 0 : 1;
  printf("l= %lld dev= %d\n", l, dev);
  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

l= 2560 dev= 1

Observed where it behaves incorrectly

l= 0 dev= 1

What the specification requires

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

OpenMP 5.2 §17.2

OpenMP 5.2 §5.4.5

OpenMP 5.2 §17.2 p.340 l.21-30

OpenMP 5.2 §13.8 p.286 l.29-30

OpenMP 5.0 §2.19.7.1

Evidence

Same compiler, one change

  • reduction(max: l) instead of lastprivate(l): 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; NVHPC 25.11: correct; NVHPC 26.9: correct
    Control program
    #include <stdio.h>
    #include <omp.h>
    int main(void) {
      long long l = 0;
      int dev = -1;
      #pragma omp target teams distribute parallel for reduction(max: l) map(tofrom: l)
      for (int i = 1; i <= 64; i++)
        l = (long long) i * 40;
      #pragma omp target map(tofrom: dev)
      dev = omp_is_initial_device() ? 0 : 1;
      printf("l= %lld dev= %d\n", l, dev);
      return 0;
    }
    

Other compilers run it correctly

AFAR 24.3.0, GCC 16.2.0