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

69 lines
2.1 KiB
C

// omp_target_disassociate_ptr should always fail if the hold reference count is
// non-zero, regardless of the dynamic reference count. When the latter is
// finite, the implementation happens to choose to report the hold diagnostic.
// RUN: %libomptarget-compile-generic -fopenmp-extensions
// RUN: %not %libomptarget-run-generic 0 2>&1 | %fcheck-generic
// RUN: %not %libomptarget-run-generic 1 2>&1 | %fcheck-generic
// RUN: %not %libomptarget-run-generic inf 2>&1 | %fcheck-generic
// RUN: %libomptarget-compile-generic -fopenmp-extensions -DHOLD_MORE
// RUN: %not %libomptarget-run-generic 0 2>&1 | %fcheck-generic
// RUN: %not %libomptarget-run-generic 1 2>&1 | %fcheck-generic
// RUN: %not %libomptarget-run-generic inf 2>&1 | %fcheck-generic
#include <limits.h>
#include <omp.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]) {
// Parse command line.
int DynRef;
if (argc != 2) {
fprintf(stderr, "bad arguments\n");
return 1;
}
if (0 == strcmp(argv[1], "inf"))
DynRef = INT_MAX;
else
DynRef = atoi(argv[1]);
// Allocate and set dynamic reference count as specified.
int DevNum = omp_get_default_device();
int X;
void *XDev = omp_target_alloc(sizeof X, DevNum);
if (!XDev) {
fprintf(stderr, "omp_target_alloc failed\n");
return 1;
}
if (DynRef == INT_MAX) {
if (omp_target_associate_ptr(&X, &XDev, sizeof X, 0, DevNum)) {
fprintf(stderr, "omp_target_associate_ptr failed\n");
return 1;
}
} else {
for (int I = 0; I < DynRef; ++I) {
#pragma omp target enter data map(alloc : X)
}
}
// Disassociate while hold reference count > 0.
int Status = 0;
#pragma omp target data map(ompx_hold, alloc : X)
#if HOLD_MORE
#pragma omp target data map(ompx_hold, alloc : X)
#pragma omp target data map(ompx_hold, alloc : X)
#endif
{
// CHECK: omptarget error: Trying to disassociate a pointer with a
// CHECK-SAME: non-zero hold reference count
// CHECK-NEXT: omp_target_disassociate_ptr failed
if (omp_target_disassociate_ptr(&X, DevNum)) {
fprintf(stderr, "omp_target_disassociate_ptr failed\n");
Status = 1;
}
}
return Status;
}