Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / openmp / libomptarget / test / offloading / memory_manager.cpp
blobac437c53521c6d007bf97018e49c68c5d2972d1e
1 // RUN: %libomptarget-compilexx-run-and-check-generic
3 // UNSUPPORTED: amdgcn-amd-amdhsa
4 // UNSUPPORTED: x86_64-pc-linux-gnu
5 // UNSUPPORTED: x86_64-pc-linux-gnu-LTO
7 #include <omp.h>
9 #include <cassert>
10 #include <iostream>
12 int main(int argc, char *argv[]) {
13 #pragma omp parallel for
14 for (int i = 0; i < 16; ++i) {
15 for (int n = 1; n < (1 << 13); n <<= 1) {
16 void *p = omp_target_alloc(n * sizeof(int), 0);
17 omp_target_free(p, 0);
21 #pragma omp parallel for
22 for (int i = 0; i < 16; ++i) {
23 for (int n = 1; n < (1 << 13); n <<= 1) {
24 int *p = (int *)omp_target_alloc(n * sizeof(int), 0);
25 #pragma omp target teams distribute parallel for is_device_ptr(p)
26 for (int j = 0; j < n; ++j) {
27 p[j] = i;
29 int buffer[n];
30 #pragma omp target teams distribute parallel for is_device_ptr(p) \
31 map(from : buffer)
32 for (int j = 0; j < n; ++j) {
33 buffer[j] = p[j];
35 for (int j = 0; j < n; ++j) {
36 assert(buffer[j] == i);
38 omp_target_free(p, 0);
42 std::cout << "PASS\n";
43 return 0;
46 // CHECK: PASS