1// RUN: %libomptarget-compilexx-run-and-check-generic
2
3#include <assert.h>
4#include <iostream>
5#include <omp.h>
6
7struct view {
8 const int size = 10;
9 int *data_host;
10 int *data_device;
11 void foo() {
12 std::size_t bytes = size * sizeof(int);
13 const int host_id = omp_get_initial_device();
14 const int device_id = omp_get_default_device();
15 data_host = (int *)malloc(size: bytes);
16 data_device = (int *)omp_target_alloc(bytes, device_id);
17#pragma omp target teams distribute parallel for is_device_ptr(data_device)
18 for (int i = 0; i < size; ++i)
19 data_device[i] = i;
20 omp_target_memcpy(data_host, data_device, bytes, 0, 0, host_id, device_id);
21 for (int i = 0; i < size; ++i)
22 assert(data_host[i] == i);
23 }
24};
25
26int main() {
27 view a;
28 a.foo();
29 // CHECK: PASSED
30 printf(format: "PASSED\n");
31}
32

source code of offload/test/mapping/is_device_ptr.cpp