1// RUN: %libomptarget-compilexx-run-and-check-generic
2
3// UNSUPPORTED: amdgcn-amd-amdhsa
4// UNSUPPORTED: x86_64-pc-linux-gnu
5// UNSUPPORTED: x86_64-pc-linux-gnu-LTO
6
7#include <omp.h>
8
9#include <cassert>
10#include <iostream>
11
12int 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);
18 }
19 }
20
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;
28 }
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];
34 }
35 for (int j = 0; j < n; ++j) {
36 assert(buffer[j] == i);
37 }
38 omp_target_free(p, 0);
39 }
40 }
41
42 std::cout << "PASS\n";
43 return 0;
44}
45
46// CHECK: PASS
47

source code of offload/test/offloading/memory_manager.cpp