OffTarget

Observed issues › afar-c-update-iterator-copy-mode

Appears to behave incorrectlyWrong answer · C · OpenMP · Open

amdclang at HSA_XNACK=0: target update with an iterator modifier moves no data

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.0correctbehaves incorrectlybehaves incorrectlybehaves incorrectlybehaves incorrectlyn/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
behaves incorrectlyAFAR 24.3.0, MI300A copy
AFAR 24.3.0, MI250X
AFAR 24.3.0, MI300X
AFAR 24.3.0, MI350X
show
to iterator: bad= 64
fails another wayCCE 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
afar-c-update-iterator-copy-mode.c:8:32: error: call to undeclared function 'iterator'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
    8 |   #pragma omp target update to(iterator(k = 0:1): a[k:n - k])
      |                                ^
afar-c-update-iterator-copy-mode.c:8:46: error: expected ')'
    8 |   #pragma omp target update to(iterator(k = 0:1): a[k:n - k])
      |                                              ^
afar-c-update-iterator-copy-mode.c:8:40: note: to match this '('
    8 |   #pragma omp target update to(iterator(k = 0:1): a[k:n - k])
fails another wayNVHPC 25.11, A100 separate
NVHPC 25.11, A100 managed
NVHPC 26.9, A100 separate
NVHPC 26.9, A100 managed
show
"afar-c-update-iterator-copy-mode.c", line 8: error: identifier "iterator" is undefined
    #pragma omp target update to(iterator(k = 0:1): a[k:n - k])
                                 ^
"afar-c-update-iterator-copy-mode.c", line 8: error: invalid text in pragma
    #pragma omp target update to(iterator(k = 0:1): a[k:n - k])
                                         ^
"afar-c-update-iterator-copy-mode.c", line 4: warning: variable "k" was declared but never referenced [declared_but_not_referenced]
    int a[n], b[n], k, bad = 0;

Reproduce

AFAR 24.3.0, MI300A copy

$AFAR/bin/amdclang -fopenmp --offload-arch=gfx942 -fopenmp-version=52 -fopenmp-version=52 -O2 repro.c -o repro
HSA_XNACK=0 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/gcc -fopenmp -foffload=amdgcn-amdhsa -foffload-options=amdgcn-amdhsa=-march=gfx942 -O2 repro.c -o repro
HSA_XNACK=1 OMP_TARGET_OFFLOAD=mandatory ./repro
Program (40 lines)
// (copy mode for the whole catalog): AFAR amdclang moves no data
// for a target update motion clause with an iterator modifier, at
// HSA_XNACK=0 (separate host and device memory).
// The iterator k = 0:1 has the one value 0 (5.2 §3.2.6 p.67: i0 = begin,
// i0 < end), so to(iterator(k = 0:1): a[k:n - k]) is to(a[0:n]): the
// target update makes the device copy of a consistent with the host
// (5.2 §13.9 p.289). Expected: to iterator: bad= 0 (from_iter: the same
// with from(iterator(k = 0:1): b[k:n - k]) after a device write).
// Observed (tuolumne, MI300A, 2026-10-22, 3 runs each, -O2,
// OMP_TARGET_OFFLOAD=mandatory):
// - AFAR amdclang 24.0.0git at HSA_XNACK=0: to iterator: bad= 64 (and
//   from iterator: bad= 64): nothing is copied; the same update without
//   the iterator, to(a[0:n]), gives bad= 0. Correct at HSA_XNACK=1 (one
//   copy of the data).
// - CCE craycc 19, 20, 21: reject the iterator modifier of to/from (the
//   catalog's to.iterator and from.iterator C programs: "call to
//   undeclared function").
// The catalog's C to.iterator and from.iterator programs (5.2, 6.0) fail
// on AFAR at HSA_XNACK=0 because of it, and so does the C map.iterator
// program: target enter data map(iterator(k = 1:2), to: w[k:n / 2 - k])
// (one value, the section w[1:31]) leaves w[1] not present in copy mode. AFAR amdflang rejects the Fortran
// form ("not yet implemented").
// AFAR: amdclang -fopenmp --offload-arch=gfx942 -fopenmp-version=52 -O2
// Run:  OMP_TARGET_OFFLOAD=mandatory HSA_XNACK=0 ./a.out
#include <stdio.h>
enum { n = 64 };
int main(void) {
  int a[n], b[n], k, bad = 0;
  for (int i = 0; i < n; i++) { a[i] = i; b[i] = 0; }
  #pragma omp target enter data map(to: a) map(alloc: b)
  for (int i = 0; i < n; i++) a[i] += 10;
  #pragma omp target update to(iterator(k = 0:1): a[k:n - k])
  #pragma omp target map(alloc: a, b)
  for (int i = 0; i < n; i++) b[i] = a[i];
  #pragma omp target update from(b)
  #pragma omp target exit data map(release: a, b)
  for (int i = 0; i < n; i++) bad += b[i] != i + 10;
  printf("to iterator: bad= %d\n", bad);
  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

to iterator: bad= 0

Observed where it behaves incorrectly

to iterator: bad= 64

What the specification requires

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

OpenMP 5.2 §3.2.6 p.67

OpenMP 5.2 §13.9 p.289

Evidence

Same compiler, one change

  • to(a[0:n]) instead of to(iterator(k = 0:1): a[k:n - k]): 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>
    enum { n = 64 };
    int main(void) {
      int a[n], b[n], k, bad = 0;
      for (int i = 0; i < n; i++) { a[i] = i; b[i] = 0; }
      #pragma omp target enter data map(to: a) map(alloc: b)
      for (int i = 0; i < n; i++) a[i] += 10;
      #pragma omp target update to(a[0:n])
      #pragma omp target map(alloc: a, b)
      for (int i = 0; i < n; i++) b[i] = a[i];
      #pragma omp target update from(b)
      #pragma omp target exit data map(release: a, b)
      for (int i = 0; i < n; i++) bad += b[i] != i + 10;
      printf("to iterator: bad= %d\n", bad);
      return 0;
    }
    

Other compilers run it correctly

GCC 16.2.0