Observed issues › clang-c-shared-declare-target-combined
Appears to behave incorrectlyWrong answer · C · OpenMP · Open
A declare target variable listed in shared on target teams loop is read with its host value
Legality: independently confirmed. 2 independent readings find the program legal and the result required. How this is checked
Affected variants
| Compiler | MI300A 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.0 | behaves incorrectly | behaves incorrectly | behaves incorrectly | behaves incorrectly | behaves incorrectly | n/a | n/a |
| CCE 19.0.0 | behaves incorrectly | behaves incorrectly | behaves incorrectly | unknown not run | unknown not run | n/a | n/a |
| CCE 20.0.2 | behaves incorrectly | behaves incorrectly | behaves incorrectly | unknown not run | unknown not run | n/a | n/a |
| CCE 21.0.3 | behaves incorrectly | behaves incorrectly | behaves incorrectly | unknown not run | unknown not run | n/a | n/a |
| CCE 21.0.4 | behaves incorrectly | behaves incorrectly | behaves incorrectly | unknown not run | unknown not run | n/a | n/a |
| NVHPC 25.11 | n/a | n/a | n/a | n/a | n/a | correct | correct |
| NVHPC 26.9 | n/a | n/a | n/a | n/a | n/a | correct | correct |
| GCC 16.2.0 | correct | correct | correct | correct | correct | correct | n/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
| Result | Compiler and GPU | Message |
|---|---|---|
| behaves incorrectly | AFAR 24.3.0, MI300A unified AFAR 24.3.0, MI300A copy | showwith shared(on_dev): b[1]=2 without: c[1]=3 teams loop in target with shared(on_dev): d[1]=1283789354 (device copy is 1, host copy 0) |
| behaves incorrectly | AFAR 24.3.0, MI250X | showwith shared(on_dev): b[1]=2 without: c[1]=3 teams loop in target with shared(on_dev): d[1]=1283740202 (device copy is 1, host copy 0) |
| behaves incorrectly | AFAR 24.3.0, MI300X | showwith shared(on_dev): b[1]=2 without: c[1]=3 teams loop in target with shared(on_dev): d[1]=-509750742 (device copy is 1, host copy 0) |
| behaves incorrectly | AFAR 24.3.0, MI350X | showwith shared(on_dev): b[1]=2 without: c[1]=3 teams loop in target with shared(on_dev): d[1]=-1098132950 (device copy is 1, host copy 0) |
| behaves incorrectly | CCE 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 | showwith shared(on_dev): b[1]=2 without: c[1]=3 teams loop in target with shared(on_dev): d[1]=3 (device copy is 1, host copy 0) |
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
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 -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 -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 -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 -O2 repro.c -o repro HSA_XNACK=1 OMP_TARGET_OFFLOAD=mandatory ./repro
NVHPC 25.11, A100 separate (runs correctly)
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
Program (51 lines)
/* Finding (C): a declare target variable listed in shared on a
combined target construct is read with its host value.
Legal OpenMP 5.2 / 6.0 C. on_dev is a declare target variable (5.2
§7.8.1); the first target region sets its device copy to 1 (the host
copy stays 0). In the second region the shared clause applies only to
the teams leaf (5.2 §17.2: shared applies to the leaves that permit it,
target does not), so on_dev there is the target region's on_dev: the
device copy, which is present (implicitly map(tofrom), 5.2 §5.8.1: no
transfer for a present variable). Expected b[1] = 2*1 + 1 = 3, the same
as the third region (no shared clause).
Observed (HSA_XNACK 0 and 1, -O2): AFAR amdclang 24.0.0git, CCE craycc
19.0.0, 20.0.2 and 21.0.3 all print b[1]=2 (the host value 0) and
c[1]=3. The fourth region (teams loop nested in a target region, the
shared clause on teams; expected d[1]=3): CCE 19 and 21 print d[1]=3,
AFAR prints an indeterminate value (d[1]=1276187178 here), which makes
omp52/60-c-directive-teams_loop wrong_answer on AFAR. AFAR amdflang
and CCE ftn run the Fortran form of the same program
(omp52-directive-target_teams_loop: shared(a, b, on_dev) under
default(none)) correctly; the C ports of the five probe-region programs
(target parallel for simd, target parallel loop, target teams
distribute parallel for simd, target teams loop, 6.0 target teams
distribute simd) fail on every toolchain because of this.
amdclang -fopenmp --offload-arch=gfx942 -fopenmp-version=52 -O2
craycc -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa
-Xopenmp-target=amdgcn-amd-amdhsa -march=gfx942 -O2 */
#include <stdio.h>
#include <omp.h>
int on_dev = 0;
#pragma omp declare target(on_dev)
int main(void) {
int a[64], b[64], c[64], d[64];
for (int i = 0; i < 64; i++) { a[i] = i; b[i] = 0; c[i] = 0; d[i] = 0; }
#pragma omp target
{ on_dev = 1; }
#pragma omp target teams loop map(to: a) map(from: b) shared(a, b, on_dev)
for (int i = 0; i < 64; i++) b[i] = 2 * a[i] + on_dev;
#pragma omp target teams loop map(to: a) map(from: c)
for (int i = 0; i < 64; i++) c[i] = 2 * a[i] + on_dev;
#pragma omp target map(to: a) map(from: d)
{
#pragma omp teams loop shared(a, d, on_dev)
for (int i = 0; i < 64; i++) d[i] = 2 * a[i] + on_dev;
}
printf("with shared(on_dev): b[1]=%d without: c[1]=%d teams loop in "
"target with shared(on_dev): d[1]=%d (device copy is 1, host copy "
"%d)\n", b[1], c[1], d[1], on_dev);
return 0;
}
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
with shared(on_dev): b[1]=2 without: c[1]=3 teams loop in target with shared(on_dev): d[1]=1283789354 (device copy is 1, host copy 0)
What the specification requires
The specification text this program relies on and the compiler is expected to support.
OpenMP 5.2 §7.8.1
OpenMP 5.2 §17.2
OpenMP 5.2 §5.8.1
Evidence
Same compiler, one change
- shared(a, b, on_dev) removed from the first target teams loop: 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> int on_dev = 0; #pragma omp declare target(on_dev) int main(void) { int a[64], b[64], c[64], d[64]; for (int i = 0; i < 64; i++) { a[i] = i; b[i] = 0; c[i] = 0; d[i] = 0; } #pragma omp target { on_dev = 1; } #pragma omp target teams loop map(to: a) map(from: b) for (int i = 0; i < 64; i++) b[i] = 2 * a[i] + on_dev; #pragma omp target teams loop map(to: a) map(from: c) for (int i = 0; i < 64; i++) c[i] = 2 * a[i] + on_dev; #pragma omp target map(to: a) map(from: d) { #pragma omp teams loop shared(a, d, on_dev) for (int i = 0; i < 64; i++) d[i] = 2 * a[i] + on_dev; } printf("with shared(on_dev): b[1]=%d without: c[1]=%d teams loop in " "target with shared(on_dev): d[1]=%d (device copy is 1, host copy " "%d)\n", b[1], c[1], d[1], on_dev); return 0; }
Other compilers run it correctly
NVHPC 25.11, NVHPC 26.9, GCC 16.2.0