Files
clang-p2996/offload/test/mapping/declare_mapper_target_update.cpp
Johannes Doerfert 330d8983d2 [Offload] Move /openmp/libomptarget to /offload (#75125)
In a nutshell, this moves our libomptarget code to populate the offload
subproject.

With this commit, users need to enable the new LLVM/Offload subproject
as a runtime in their cmake configuration.
No further changes are expected for downstream code.

Tests and other components still depend on OpenMP and have also not been
renamed. The results below are for a build in which OpenMP and Offload
are enabled runtimes. In addition to the pure `git mv`, we needed to
adjust some CMake files. Nothing is intended to change semantics.

```
ninja check-offload
```
Works with the X86 and AMDGPU offload tests

```
ninja check-openmp
```
Still works but doesn't build offload tests anymore.

```
ls install/lib
```
Shows all expected libraries, incl.
- `libomptarget.devicertl.a`
- `libomptarget-nvptx-sm_90.bc`
- `libomptarget.rtl.amdgpu.so` -> `libomptarget.rtl.amdgpu.so.18git`
- `libomptarget.so` -> `libomptarget.so.18git`

Fixes: https://github.com/llvm/llvm-project/issues/75124

---------

Co-authored-by: Saiyedul Islam <Saiyedul.Islam@amd.com>
2024-04-22 09:51:33 -07:00

57 lines
1.3 KiB
C++

// RUN: %libomptarget-compile-run-and-check-generic
#include <cstdio>
#include <cstdlib>
#define NUM 1024
class C {
public:
int *a;
};
#pragma omp declare mapper(id : C s) map(s.a[0 : NUM])
int main() {
C c;
int sum = 0;
c.a = (int *)malloc(sizeof(int) * NUM);
for (int i = 0; i < NUM; i++) {
c.a[i] = 1;
}
#pragma omp target enter data map(mapper(id), alloc : c)
#pragma omp target teams distribute parallel for
for (int i = 0; i < NUM; i++) {
c.a[i] = 0;
}
#pragma omp target update from(mapper(id) : c)
for (int i = 0; i < NUM; i++) {
sum += c.a[i];
}
// CHECK: Sum (after first update from) = 0
printf("Sum (after first update from) = %d\n", sum);
for (int i = 0; i < NUM; i++) {
c.a[i] = 1;
}
#pragma omp target update to(mapper(id) : c)
#pragma omp target teams distribute parallel for
for (int i = 0; i < NUM; i++) {
++c.a[i];
}
sum = 0;
for (int i = 0; i < NUM; i++) {
sum += c.a[i];
}
// CHECK: Sum (after update to) = 1024
printf("Sum (after update to) = %d\n", sum);
#pragma omp target update from(mapper(id) : c)
sum = 0;
for (int i = 0; i < NUM; i++) {
sum += c.a[i];
}
// CHECK: Sum (after second update from) = 2048
printf("Sum (after second update from) = %d\n", sum);
#pragma omp target exit data map(mapper(id), delete : c)
return 0;
}