OffTarget

Observed issues › cce-c-map-delete-refcount

Appears to behave incorrectlyWrong answer · C · OpenMP · Open

craycc: map(delete:) on target exit data acts as release for an array entered twice (still present)

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/acorrectcorrect
NVHPC 26.9n/an/an/an/an/acorrectcorrect
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
bad= 0 a_present= 1 b_present= 0

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 (43 lines)
// (copy mode for the whole catalog): CCE craycc keeps an array
// present after map(delete: a) on target exit data when its reference
// count is two.
// a is entered twice (reference count 2), b once; target exit data
// map(from: b) map(delete: a) sets a's reference count to zero and
// removes it, and decrements b's to zero (5.2 §5.8.3 p.154: "If the
// map-type is delete and the reference count of the corresponding
// storage block is finite then the reference count is set to zero";
// "If the reference count ... is zero, all storage ... is removed").
// Expected: bad= 0 a_present= 0 b_present= 0
// Observed (tuolumne, MI300A, 2026-10-22, 3 runs each, -O2,
// OMP_TARGET_OFFLOAD=mandatory):
// - CCE craycc 19.0.0, 20.0.2, 21.0.3: bad= 0 a_present= 1 b_present= 0,
//   at HSA_XNACK 0 and 1 (delete acts like release).
// - AFAR amdclang 24.0.0git: expected output in both modes.
// The Fortran form passes on CCE (the catalog's Fortran map.delete
// programs). The catalog's C map.delete programs (5.2, 6.0) check the
// presence only in copy mode (copy_mode_only evidence: under unified
// memory the presence checks are skipped), so CCE reads correct at
// HSA_XNACK=1 and wrong at HSA_XNACK=0; with its presence checks run at
// HSA_XNACK=1 (tools/campaigns/presence_x1.py) it fails there too. Not a copy-mode
// failure: the class is x1_oracle_blind.
// CCE: craycc -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa
//      -Xopenmp-target=amdgcn-amd-amdhsa -march=gfx942 -fopenmp-version=52 -O2
//      (module load cce/<v> craype-accel-amd-gfx942 rocm)
// Run:  OMP_TARGET_OFFLOAD=mandatory HSA_XNACK=0 ./a.out
#include <stdio.h>
#include <omp.h>
enum { n = 64 };
int main(void) {
  int a[n], b[n], d = omp_get_default_device();
  for (int i = 0; i < n; i++) { a[i] = i; b[i] = 0; }
  #pragma omp target enter data map(to: a) map(alloc: b)
  #pragma omp target enter data map(to: a)
  #pragma omp target map(alloc: a, b)
  for (int i = 0; i < n; i++) b[i] = 2 * a[i] + 1;
  #pragma omp target exit data map(from: b) map(delete: a)
  int bad = 0;
  for (int i = 0; i < n; i++) bad += b[i] != 2 * i + 1;
  printf("bad= %d a_present= %d b_present= %d\n", bad,
         omp_target_is_present(a, d), omp_target_is_present(b, d));
  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

bad= 0 a_present= 0 b_present= 0

Observed where it behaves incorrectly

bad= 0 a_present= 1 b_present= 0

What the specification requires

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

OpenMP 5.2 §5.8.3 p.154

If the map-type is delete and the reference count of the corresponding storage block is finite then the reference count is set to zero

Evidence

Same compiler, one change

  • a entered once (reference count 1) instead of twice: 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 <omp.h>
    enum { n = 64 };
    int main(void) {
      int a[n], b[n], d = omp_get_default_device();
      for (int i = 0; i < n; i++) { a[i] = i; b[i] = 0; }
      #pragma omp target enter data map(to: a) map(alloc: b)
      #pragma omp target map(alloc: a, b)
      for (int i = 0; i < n; i++) b[i] = 2 * a[i] + 1;
      #pragma omp target exit data map(from: b) map(delete: a)
      int bad = 0;
      for (int i = 0; i < n; i++) bad += b[i] != 2 * i + 1;
      printf("bad= %d a_present= %d b_present= %d\n", bad,
             omp_target_is_present(a, d), omp_target_is_present(b, d));
      return 0;
    }
    

Other compilers run it correctly

AFAR 24.3.0, NVHPC 25.11, NVHPC 26.9, GCC 16.2.0