Files
clang-p2996/offload/test/offloading/d2d_memcpy.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

70 lines
1.7 KiB
C

// RUN: %libomptarget-compile-generic && \
// RUN: env OMP_MAX_ACTIVE_LEVELS=2 %libomptarget-run-generic | \
// RUN: %fcheck-generic -allow-empty
// RUN: %libomptarget-compileopt-generic && \
// RUN: env OMP_MAX_ACTIVE_LEVELS=2 %libomptarget-run-generic | \
// RUN: %fcheck-generic -allow-empty
#include <assert.h>
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
const int magic_num = 7;
int main(int argc, char *argv[]) {
const int N = 128;
const int num_devices = omp_get_num_devices();
// No target device, just return
if (num_devices == 0) {
printf("PASS\n");
return 0;
}
const int src_device = 0;
int dst_device = num_devices - 1;
int length = N * sizeof(int);
int *src_ptr = omp_target_alloc(length, src_device);
int *dst_ptr = omp_target_alloc(length, dst_device);
assert(src_ptr && "src_ptr is NULL");
assert(dst_ptr && "dst_ptr is NULL");
#pragma omp target teams distribute parallel for device(src_device) \
is_device_ptr(src_ptr)
for (int i = 0; i < N; ++i) {
src_ptr[i] = magic_num;
}
int rc =
omp_target_memcpy(dst_ptr, src_ptr, length, 0, 0, dst_device, src_device);
assert(rc == 0 && "error in omp_target_memcpy");
int *buffer = malloc(length);
assert(buffer && "failed to allocate host buffer");
#pragma omp target teams distribute parallel for device(dst_device) \
map(from : buffer[0 : N]) is_device_ptr(dst_ptr)
for (int i = 0; i < N; ++i) {
buffer[i] = dst_ptr[i] + magic_num;
}
for (int i = 0; i < N; ++i)
assert(buffer[i] == 2 * magic_num);
printf("PASS\n");
// Free host and device memory
free(buffer);
omp_target_free(src_ptr, src_device);
omp_target_free(dst_ptr, dst_device);
return 0;
}
// CHECK: PASS