Files
clang-p2996/offload/test/mapping/prelock.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

70 lines
1.8 KiB
C++

// RUN: %libomptarget-compilexx-generic
// RUN: %libomptarget-run-generic %fcheck-generic
// UNSUPPORTED: aarch64-unknown-linux-gnu
// UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
// UNSUPPORTED: nvptx64-nvidia-cuda
// UNSUPPORTED: nvptx64-nvidia-cuda-LTO
// UNSUPPORTED: x86_64-pc-linux-gnu
// UNSUPPORTED: x86_64-pc-linux-gnu-LTO
// UNSUPPORTED: amdgcn-amd-amdhsa
#include <cstdio>
#include <omp.h>
extern "C" {
void *llvm_omp_target_lock_mem(void *ptr, size_t size, int device_num);
void llvm_omp_target_unlock_mem(void *ptr, int device_num);
}
int main() {
int n = 100;
int *unlocked = new int[n];
for (int i = 0; i < n; i++)
unlocked[i] = i;
int *locked = (int *)llvm_omp_target_lock_mem(unlocked, n * sizeof(int),
omp_get_default_device());
if (!locked)
return 0;
#pragma omp target teams distribute parallel for map(tofrom : unlocked[ : n])
for (int i = 0; i < n; i++)
unlocked[i] += 1;
#pragma omp target teams distribute parallel for map(tofrom : unlocked[10 : 10])
for (int i = 10; i < 20; i++)
unlocked[i] += 1;
#pragma omp target teams distribute parallel for map(tofrom : locked[ : n])
for (int i = 0; i < n; i++)
locked[i] += 1;
#pragma omp target teams distribute parallel for map(tofrom : locked[10 : 10])
for (int i = 10; i < 20; i++)
locked[i] += 1;
llvm_omp_target_unlock_mem(unlocked, omp_get_default_device());
int err = 0;
for (int i = 0; i < n; i++) {
if (i < 10 || i > 19) {
if (unlocked[i] != i + 2) {
printf("Err at %d, got %d, expected %d\n", i, unlocked[i], i + 1);
err++;
}
} else if (unlocked[i] != i + 4) {
printf("Err at %d, got %d, expected %d\n", i, unlocked[i], i + 2);
err++;
}
}
// CHECK: PASS
if (err == 0)
printf("PASS\n");
return err;
}