llvm-project/offload/test/api/omp_indirect_call.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

48 lines
1.3 KiB
C

// RUN: %libomptarget-compile-run-and-check-generic
#include <assert.h>
#include <stdio.h>
#pragma omp begin declare variant match(device = {kind(gpu)})
// Provided by the runtime.
void *__llvm_omp_indirect_call_lookup(void *host_ptr);
#pragma omp declare target to(__llvm_omp_indirect_call_lookup) \
device_type(nohost)
#pragma omp end declare variant
#pragma omp begin declare variant match(device = {kind(cpu)})
// We assume unified addressing on the CPU target.
void *__llvm_omp_indirect_call_lookup(void *host_ptr) { return host_ptr; }
#pragma omp end declare variant
#pragma omp begin declare target indirect
void foo(int *x) { *x = *x + 1; }
void bar(int *x) { *x = *x + 1; }
void baz(int *x) { *x = *x + 1; }
#pragma omp end declare target
int main() {
void *foo_ptr = foo;
void *bar_ptr = bar;
void *baz_ptr = baz;
int count = 0;
void *foo_res;
void *bar_res;
void *baz_res;
#pragma omp target map(to : foo_ptr, bar_ptr, baz_ptr) map(tofrom : count)
{
foo_res = __llvm_omp_indirect_call_lookup(foo_ptr);
((void (*)(int *))foo_res)(&count);
bar_res = __llvm_omp_indirect_call_lookup(bar_ptr);
((void (*)(int *))bar_res)(&count);
baz_res = __llvm_omp_indirect_call_lookup(baz_ptr);
((void (*)(int *))baz_res)(&count);
}
assert(count == 3 && "Calling failed");
// CHECK: PASS
printf("PASS\n");
}